diff options
Diffstat (limited to 'libgo/go/syscall/exec_bsd.go')
-rw-r--r-- | libgo/go/syscall/exec_bsd.go | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/libgo/go/syscall/exec_bsd.go b/libgo/go/syscall/exec_bsd.go index ad65f63..c05ae13 100644 --- a/libgo/go/syscall/exec_bsd.go +++ b/libgo/go/syscall/exec_bsd.go @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build aix || darwin || dragonfly || freebsd || hurd || netbsd || openbsd || solaris -// +build aix darwin dragonfly freebsd hurd netbsd openbsd solaris +//go:build aix || darwin || dragonfly || hurd || netbsd || openbsd || solaris package syscall import ( + "runtime" "unsafe" ) @@ -152,12 +152,7 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr groups = &gids[0] } if !cred.NoSetGroups { - err2 := setgroups(ngroups, groups) - if err2 == nil { - err1 = 0 - } else { - err1 = err2.(Errno) - } + err1 = raw_setgroups(ngroups, groups) if err1 != 0 { goto childerror } @@ -185,11 +180,19 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr // Pass 1: look for fd[i] < i and move those up above len(fd) // so that pass 2 won't stomp on an fd it needs later. if pipe < nextfd { - err1 = raw_dup2(pipe, nextfd) - if err1 != 0 { - goto childerror + switch runtime.GOOS { + case "netbsd": + err1 = raw_dup3(pipe, nextfd, O_CLOEXEC) + if err1 != 0 { + goto childerror + } + default: + err1 = raw_dup2(pipe, nextfd) + if err1 != 0 { + goto childerror + } + raw_fcntl(nextfd, F_SETFD, FD_CLOEXEC) } - raw_fcntl(nextfd, F_SETFD, FD_CLOEXEC) pipe = nextfd nextfd++ } @@ -198,11 +201,19 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr if nextfd == pipe { // don't stomp on pipe nextfd++ } - err1 = raw_dup2(fd[i], nextfd) - if err1 != 0 { - goto childerror + switch runtime.GOOS { + case "netbsd": + err1 = raw_dup3(fd[i], nextfd, O_CLOEXEC) + if err1 != 0 { + goto childerror + } + default: + err1 = raw_dup2(fd[i], nextfd) + if err1 != 0 { + goto childerror + } + raw_fcntl(nextfd, F_SETFD, FD_CLOEXEC) } - raw_fcntl(nextfd, F_SETFD, FD_CLOEXEC) fd[i] = nextfd nextfd++ } |