Skip to content

sudo su <user> to a user with pwsh as their default shell leads to an exception around PSReadLineHistoryFile #3692

Open
@stoic-tcramer

Description

@stoic-tcramer

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.

Exception report

Oops, something went wrong.
Please report this bug with ALL the details below, including both the 'Environment' and 'Exception' sections.
Please report on GitHub: https://github.com/PowerShell/PSReadLine/issues/new?template=Bug_Report.yaml
Thank you!

### Environment
PSReadLine: 2.2.6
PowerShell: 7.3.4
OS: Linux 5.15.0-1019-azure #24~20.04.1-Ubuntu SMP Tue Aug 23 15:52:52 UTC 2022
BufferWidth: 299
BufferHeight: 68

Last 0 Keys:



### Exception

System.IO.IOException: The system cannot open the device or file specified. : 'PSReadLineHistoryFile_3434894495'
   at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew)
   at Microsoft.PowerShell.PSConsoleReadLine.DelayedOneTimeInitialize()
   at Microsoft.PowerShell.PSConsoleReadLine.Initialize(Runspace runspace, EngineIntrinsics engineIntrinsics)
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken, Nullable`1 lastRunStatus)

Screenshot

PS /p4/tcramer/root> whoami
tcramer
PS /p4/tcramer/root> sudo su user2
PowerShell 7.3.4
PS /p4/user2/root>
Oops, something went wrong.

Environment data

PS Version: 7.3.4
PS HostName: ConsoleHost
PSReadLine Version: 2.2.6
PSReadLine EditMode: Emacs
OS: Linux bf-p4scratch 5.15.0-1019-azure #24~20.04.1-Ubuntu SMP Tue Aug 23 15:52:52 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
BufferWidth: 299
BufferHeight: 68

Steps to reproduce

Install Powershell on Ubuntu
Set a user's shell to pwsh (in the above it's set to /snap/powershell/current/opt/powershell/pwsh)
sudo su from another user with sudo access

Expected behavior

A powershell prompt running under the provided to the sudo su command with no exceptions

Actual behavior

The above exception is thrown

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-StabilityLabel for tracking stability IssuesIssue-BugIt either shouldn't be doing this or needs an investigation.issue-mutexThe mutex creation issue on macOS

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions