diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-01-31 18:07:43 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-02-26 18:23:47 +0000 |
commit | 3146166baa8c420dfe20619e4aa9978b87927268 (patch) | |
tree | e6fc65697c24b5c8d68d33a062ff235caa3f1dec | |
parent | 2d760816ff30bea82f54682f3049cfb6c6027da7 (diff) | |
download | go-3146166baa8c420dfe20619e4aa9978b87927268.tar.gz go-3146166baa8c420dfe20619e4aa9978b87927268.zip |
syscall: introduce SysProcAttr.AdditionalInheritedHandles on Windows
This allows users to specify handles that they explicitly want to be
inherited by the new process. These handles must already be marked as
inheritable.
Updates #44011.
Updates #21085.
Change-Id: Ib18322e7dc2909e68c4209e80385492804fa15d3
Reviewed-on: https://go-review.googlesource.com/c/go/+/288298
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
-rw-r--r-- | src/syscall/exec_windows.go | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/syscall/exec_windows.go b/src/syscall/exec_windows.go index ff9f7a3913..0ddc240a56 100644 --- a/src/syscall/exec_windows.go +++ b/src/syscall/exec_windows.go @@ -235,13 +235,14 @@ type ProcAttr struct { } type SysProcAttr struct { - HideWindow bool - CmdLine string // used if non-empty, else the windows command line is built by escaping the arguments passed to StartProcess - CreationFlags uint32 - Token Token // if set, runs new process in the security context represented by the token - ProcessAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the new process - ThreadAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the main thread of the new process - NoInheritHandles bool // if set, each inheritable handle in the calling process is not inherited by the new process + HideWindow bool + CmdLine string // used if non-empty, else the windows command line is built by escaping the arguments passed to StartProcess + CreationFlags uint32 + Token Token // if set, runs new process in the security context represented by the token + ProcessAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the new process + ThreadAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the main thread of the new process + NoInheritHandles bool // if set, each inheritable handle in the calling process is not inherited by the new process + AdditionalInheritedHandles []Handle // a list of additional handles, already marked as inheritable, that will be inherited by the new process } var zeroProcAttr ProcAttr @@ -337,6 +338,7 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle si.StdOutput = fd[1] si.StdErr = fd[2] + fd = append(fd, sys.AdditionalInheritedHandles...) // Do not accidentally inherit more than these handles. err = updateProcThreadAttribute(si.ProcThreadAttributeList, 0, _PROC_THREAD_ATTRIBUTE_HANDLE_LIST, uintptr(unsafe.Pointer(&fd[0])), uintptr(len(fd))*unsafe.Sizeof(fd[0]), 0, nil) if err != nil { |