-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properly pass stdio handles to child process #3
Conversation
shim.cpp
Outdated
@@ -124,6 +124,15 @@ std::tuple<std::unique_handle, std::unique_handle> MakeProcess(const std::wstrin | |||
std::unique_handle threadHandle; | |||
std::unique_handle processHandle; | |||
|
|||
si.cb = sizeof(STARTUPINFOW); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably we can just forward all of the start info of shim process to its child?
Using something like https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-getstartupinfow.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're correct, I'll give it a try later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works, but maybe we need more tests to see if it will break other things (GUI apps, etc..)
all si.xxxx assignments will become a single GetStartupInfoW(&si);
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A quick test shows that GUI apps and console apps with complicated behavior (REPLs like powershell (+PSReadLine), python) works well. However, it seems that the check for GUI apps, therefore the console window didn't exit when the GUI is shown, but it's not related to the GetStartupInfoW
change though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, please update your PR once you feel confident about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, the new approach is pushed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution. Merge
See ScoopInstaller/Scoop#4849 and restic/restic#3681
When a process (A) spawns a process (B) with
DETACHED_PROCESS
and communicate with it via stdio redirections, process B isn't attached to a console, but its STD_XXX_HANDLEs are still valid (set by process A). However, with shim in the middle, such communication is broken, because for unknown reason the stdio handles are not properly passed down.This PR fixes such problem by manually passing down handles via
STARTUPINFOW
. However during my test, although restic/rclone succeeded to work, a blank console window still popped up. It may be suppressed viaCREATE_NO_WINDOW
creation flag, but I don't know if it would break other things..Code I used to test:
Code for process A (golang, expecting the child/shim executable name = testtarget):
Code for process B (C++):