From 3a8642b1e0d523dca0711c8e6e3616a0365e0da1 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Sun, 28 Jul 2024 22:27:26 +0800 Subject: [PATCH] syscall: forkAndExecInChild --- _cmptest/{_osexec => osexec}/exec.go | 0 internal/lib/syscall/exec_libc2.go | 11 +++-------- 2 files changed, 3 insertions(+), 8 deletions(-) rename _cmptest/{_osexec => osexec}/exec.go (100%) diff --git a/_cmptest/_osexec/exec.go b/_cmptest/osexec/exec.go similarity index 100% rename from _cmptest/_osexec/exec.go rename to _cmptest/osexec/exec.go diff --git a/internal/lib/syscall/exec_libc2.go b/internal/lib/syscall/exec_libc2.go index 4c45b80b..02237240 100644 --- a/internal/lib/syscall/exec_libc2.go +++ b/internal/lib/syscall/exec_libc2.go @@ -261,22 +261,17 @@ func forkAndExecInChild(argv0 *c.Char, argv, envv **c.Char, chroot, dir *c.Char, if fd[i] == i { // dup2(i, i) won't clear close-on-exec flag on Linux, // probably not elsewhere either. - ret := os.Fcntl(c.Int(fd[i]), syscall.F_SETFD, 0) - if ret != 0 { + if ret := os.Fcntl(c.Int(fd[i]), syscall.F_SETFD, 0); ret != 0 { err1 = Errno(ret) goto childerror } continue } - /* TODO(xsw): // The new fd is created NOT close-on-exec, - // which is exactly what we want. - _, _, err1 = rawSyscall(abi.FuncPCABI0(libc_dup2_trampoline), uintptr(fd[i]), uintptr(i), 0) - if err1 != 0 { + if ret := os.Dup2(c.Int(fd[i]), c.Int(i)); ret != 0 { + err1 = Errno(ret) goto childerror } - */ - panic("todo: syscall.forkAndExecInChild - dup2") } // By convention, we don't close-on-exec the fds we are