diff --git a/doc/go1.16.html b/doc/go1.16.html index 2f2e395729e492..4ba9d6785c8bc2 100644 --- a/doc/go1.16.html +++ b/doc/go1.16.html @@ -331,6 +331,14 @@

Minor changes to the library

+
syscall
+
+

+ SysProcAttr on Windows has a new NoInheritHandles field that disables inheriting handles when creating a new process. +

+
+
+
strconv

diff --git a/src/syscall/exec_windows.go b/src/syscall/exec_windows.go index 4a1d74ba3f3721..46cbd7567dd560 100644 --- a/src/syscall/exec_windows.go +++ b/src/syscall/exec_windows.go @@ -241,6 +241,7 @@ type SysProcAttr struct { 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 } var zeroProcAttr ProcAttr @@ -341,9 +342,9 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle flags := sys.CreationFlags | CREATE_UNICODE_ENVIRONMENT if sys.Token != 0 { - err = CreateProcessAsUser(sys.Token, argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, true, flags, createEnvBlock(attr.Env), dirp, si, pi) + err = CreateProcessAsUser(sys.Token, argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, !sys.NoInheritHandles, flags, createEnvBlock(attr.Env), dirp, si, pi) } else { - err = CreateProcess(argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, true, flags, createEnvBlock(attr.Env), dirp, si, pi) + err = CreateProcess(argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, !sys.NoInheritHandles, flags, createEnvBlock(attr.Env), dirp, si, pi) } if err != nil { return 0, 0, err