-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: os/exec, syscall: allow child processes to inherit all inheritable handles from the parent process #60942
Comments
I don't really understand what the meaning of the Can we update the documentation for |
The doc comment is outdated.
Yep, will submit a CL improving the doc comments. |
Change https://go.dev/cl/505515 mentions this issue: |
Huh, I've just seen that pipes returned by os.Pipe are marked as inheritable since CL 288299, so applications using I see three options to overcome this issue:
I like the second one, if that's feasible and can mitigate possible breaking changes. |
I am still very confused. On the other hand, if the user explicitly sets ( Perhaps Along those same lines, perhaps It looks like the field was added in the first place in https://go.dev/cl/261917 for #42098, but I don't see any tests associated with that proposal or CL at all. (CC @ianlancetaylor @JohanKnutzen). |
https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessasuserw says (emphasis mine):
That problematic case seems like what essentially always happens in a Go program. In particular, it seems like allowing ...actually, come to think of it: it appears that If we were to add |
Will investigate more next week. I'll have to run some tests to understand this.
In fact, it is no longer necessary to cover the case where |
Change https://go.dev/cl/506136 mentions this issue: |
Got the answer:
That's correct. Setting
Agree with both, |
…andles SysProcAttr.NoInheritHandles doc comment is not clear about which handles are affected by it. This CL clarifies that it not only affects the ones passed in AdditionalInheritedHandles, but also the ones passed in ProcAttr.Files, which are required to be stderr, stdin and stdout when calling syscall.StartProcess. Updates #60942 Change-Id: I5bc5b3604b6db04b83f6764d5c5ffbdafeeb22fb Reviewed-on: https://go-review.googlesource.com/c/go/+/505515 Run-TryBot: Quim Muntal <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
Allowing process to inherit all its handles is looking for trouble in general. Perhaps this should be hard to do. Perhaps reimplementing
Sounds reasonable to me. Alex |
…andles SysProcAttr.NoInheritHandles doc comment is not clear about which handles are affected by it. This CL clarifies that it not only affects the ones passed in AdditionalInheritedHandles, but also the ones passed in ProcAttr.Files, which are required to be stderr, stdin and stdout when calling syscall.StartProcess. Updates golang#60942 Change-Id: I5bc5b3604b6db04b83f6764d5c5ffbdafeeb22fb Reviewed-on: https://go-review.googlesource.com/c/go/+/505515 Run-TryBot: Quim Muntal <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
`syscall.ForkLock` is not used in `syscall.StartProcess` since CL 288297, so using it in `sysSocket` makes no sense. This CL goes a little bit further and removes the `sysSocket` fallback for Windows 7, since it is not supported since go 1.21 (#57003). Updates #60942 Change-Id: If14a0d94742f1b80af994f9f69938701ee41b402 Reviewed-on: https://go-review.googlesource.com/c/go/+/506136 Reviewed-by: Heschi Kreinick <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Quim Muntal <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Alex Brainman <[email protected]>
On Windows, one must explicitly list the handles that will be inherited by a new process when calling syscall.StartProcess and os.StartProcess. This is problematic for applications that don't know which handles they have inherited from their parent process and want to spawn new child processes with the same inherited handles, as in #53652.
Windows does not provide an API to list all inherited handles, but suggest to use some form of process communication (source), so these applications are left behind without a solution other than reimplementing
syscall.StartProcess
.In fact, before go1.17 we did support this use case, all inheritable handles were passed explicitly. #44011 changed
syscall.StartProcess
to use the more robust approach of passing them implicitly. What I'm proposing here is to allow users to opt into the old behavior by adding a new property to syscall.SysProcAttr property, namedInheritAllInheritableHandles
.It would look like this:
If
InheritAllInheritableHandles
is set andNoInheritHandles
is unset, thensyscall.StartProcess
would ignoreAdditionalInheritedHandles
and call the relevant windows APIs as beforeCL 288297
. We could also fail in case bothInheritAllInheritableHandles
andNoInheritHandles
are set, I'm still not sold on this.Notice that handles passed in
AdditionalInheritedHandles
will still be inherited whenInheritAllInheritableHandles
is set, as they must be marked as inheritable to be usable inAdditionalInheritedHandles
.@golang/windows @alexbrainman @zx2c4
The text was updated successfully, but these errors were encountered: