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

Open
#3,692 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp, linux, powershell

Research direction

Reproduce the failure on Ubuntu by setting a user's shell to pwsh and running sudo su . Start with the DelayedOneTimeInitialize call in the exception stack trace; done means the switched user receives a PowerShell prompt without the PSReadLineHistoryFile exception.

Written by the indexing model from the issue text.

Description

Area-Stability Issue-Bug issue-mutex
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

Dominant language
C#
Stars
4.4k
Forks
341
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PowerShell/PSReadLine

All issues in PowerShell/PSReadLine

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.