Skip to content

Conversation

@SteveL-MSFT
Copy link
Member

@SteveL-MSFT SteveL-MSFT commented Nov 11, 2018

PR Summary

There a some differences in support of named pipes for Windows and non-Windows. Named pipes on Unix have a 104 character path limit. On macOS, the $env:TMPDIR (on my system) is already 49 characters; corefx adds 12 more. Since AppDomainName isn't really used, changed it from DefaultAppDomain to None to shorten the name. Need to keep it since Windows PowerShell expects it. Changed starttime part of pipe name to 8 hex characters which is to provide uniqueness to the pipe name.

Fix #5110
Possibly also fix 6435, but need verification. #6435

PR Checklist

@SteveL-MSFT SteveL-MSFT changed the title WIP: Support Get-PSHostProcessInfo and Enter-PSHostProcess on non-Windows Support Get-PSHostProcessInfo and Enter-PSHostProcess on non-Windows Nov 12, 2018
@SteveL-MSFT SteveL-MSFT changed the title Support Get-PSHostProcessInfo and Enter-PSHostProcess on non-Windows WIP: Support Get-PSHostProcessInfo and Enter-PSHostProcess on non-Windows Nov 12, 2018
@SteveL-MSFT SteveL-MSFT force-pushed the named-pipes branch 2 times, most recently from 3669b26 to a6649fd Compare November 12, 2018 01:08
@SteveL-MSFT SteveL-MSFT force-pushed the named-pipes branch 2 times, most recently from be57216 to 4a96f68 Compare November 12, 2018 01:38
cleanup existing Windows specific code and update tests
use same model as AMSI uninitialize to cleanup named pipes on exit
when enumerating pshostprocessinfo, check if they are valid, otherwise exclude and try to remove
@SteveL-MSFT SteveL-MSFT changed the title WIP: Support Get-PSHostProcessInfo and Enter-PSHostProcess on non-Windows Support Get-PSHostProcessInfo and Enter-PSHostProcess on non-Windows Nov 12, 2018
@PaulHigin
Copy link
Contributor

@SteveL-MSFT

Regarding the server named pipe dispose, this is done in WindowsPowerShell via the CLR AppDomain unload event, which is not supported on CORECLR. However, you can use the AppDomain.CurrentDomain.ProcessExit event that we use for AMSI un-initializing. Unfortunately, these CLR events are not reliable, but they are better than nothing.

The start time added to the filename is intended to make the named pipe instance unique, to prevent a DOS or man-in-the-middle attack. We will want to keep something like this, even if it means using something shorter.

address Paul's feedback
Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@TylerLeonhardt
Copy link
Member

TylerLeonhardt commented Nov 12, 2018

I love when a PR has more deletions than insertions yet more functionality

@daxian-dbw
Copy link
Member

As for the domain name, do we really need it for the pipe name? Is multiple domain is going to be supported in .NET Core 3.0?

I have no problem keeping it for now until we get an accurate answer for the app domain support.

@SteveL-MSFT
Copy link
Member Author

@daxian-dbw best I can tell, AppDomains are deprecated in .Net Core and not in the roadmap I can see for 3.0. So it may be fine to remove it for non-Windows. We'll have to keep it for Windows so that Windows PowerShell and PowerShell Core interop still works however.

@PaulHigin
Copy link
Contributor

Yes, I have proposed dropping the Domain name. If it gets supported again in dotNet Core then we can add it back.

@SteveL-MSFT
Copy link
Member Author

To retain interoperability between Windows PowerShell and keep the code similar between Windows and non-Windows, I'll shorten the DefaultAppDomainName to 'none' but will keep it in the pipe name.

@TravisEz13 TravisEz13 added the CL-BreakingChange Indicates that a PR should be marked as a breaking change in the Change Log label Nov 14, 2018
address Paul and Dongbo's feedback
@SteveL-MSFT SteveL-MSFT removed Breaking-Change breaking change that may affect users CL-BreakingChange Indicates that a PR should be marked as a breaking change in the Change Log labels Nov 14, 2018
Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll have to keep it for Windows so that Windows PowerShell and PowerShell Core interop still works however.

Then we should keep the AppDomain field on all platforms. none is short enough and it's better to keep the same schema.

@PaulHigin
Copy link
Contributor

@SteveL-MSFT I forgot about maintaining compatibility with Windows PowerShell. We definitely need to ensure we can still list/parse/connect to those hosts.

@SteveL-MSFT
Copy link
Member Author

Ugh, with the changes I've made since, I can't connect to/from Windows PowerShell and PowerShell Core. Debugging.

revert defaultappdomainname and starttime format on Windows as it's needed to interop with Windows PowerShell
@SteveL-MSFT
Copy link
Member Author

Looks like DefaultAppDomain is necessary on Windows as there is a check for that string and the starttime needs to stay as filetime integers on Windows to support interop between Windows PowerShell and PowerShell Core. I believe everything else is addressed. @PaulHigin can you take another look?

@PaulHigin
Copy link
Contributor

@SteveL-MSFT Yeah, for Windows we need to keep the DomainName to be able to connect to WindowsPowerShell host, and that means keeping the default domain name for Windows platform pipe names.

@SteveL-MSFT
Copy link
Member Author

@PaulHigin yes, the recent commit has the same DefaultAppDomainName and starttime format on Windows and I verified manually it works from and to Windows PowerShell

Copy link
Contributor

@PaulHigin PaulHigin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I wonder if we should add a test to ensure WindowsPowerShell is listed by Get-PSHostProcessInfo? WindowsPowerShell is always installed on Windows so it shouldn't be too hard to run powershell.exe and check.

@SteveL-MSFT
Copy link
Member Author

@PaulHigin good suggestion. Let me add a test for Windows PowerShell interop.

added tests to validate interop with Windows PowerShell
@daxian-dbw
Copy link
Member

@SteveL-MSFT, there are tests about Enter-PSHostProcess failing in AppVeyor, can you please take a look?

@SteveL-MSFT
Copy link
Member Author

@daxian-dbw it appears to be a problem with redirected input with PSReadLine and only on AppVeyor. We're moving off AppVeyor (eventually), so I think we can ignore this otherwise we'll have to special case this by perhaps removing PSReadLine for this test

@daxian-dbw
Copy link
Member

Given @SteveL-MSFT's clarification on the AppVeyor test failure, I'm merging this PR.

@daxian-dbw daxian-dbw added the Documentation Needed in this repo Documentation is needed in this repo label Nov 15, 2018
@daxian-dbw daxian-dbw merged commit c5dd3bd into PowerShell:master Nov 15, 2018
iSazonov pushed a commit to iSazonov/PowerShell that referenced this pull request Nov 29, 2018
…tforms (PowerShell#8232)

There a some differences in support of named pipes for Windows and non-Windows.  Named pipes on Unix have a 104 character path limit.  On macOS, the `$env:TMPDIR` (on my system) is already 49 characters; corefx adds 12 more.  Since AppDomainName isn't really used, changed it from `DefaultAppDomain` to `None` to shorten the name.  Need to keep it since Windows PowerShell expects it.  Changed `starttime` part of pipe name to 8 hex characters which is to provide uniqueness to the pipe name.
@adityapatwardhan adityapatwardhan added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Dec 3, 2018
@SteveL-MSFT SteveL-MSFT deleted the named-pipes branch March 10, 2020 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Engine Indicates that a PR should be marked as an engine change in the Change Log Documentation Needed in this repo Documentation is needed in this repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

port Get-PSHostProcessInfo and Enter-PSHostProcess cmdlets to non-Windows

7 participants