syscall.forkAndExecInChild fix: os.Fcntl/Dup2 retval
This commit is contained in:
@@ -263,15 +263,15 @@ func forkAndExecInChild(argv0 *c.Char, argv, envv **c.Char, chroot, dir *c.Char,
|
|||||||
if fd[i] == i {
|
if fd[i] == i {
|
||||||
// dup2(i, i) won't clear close-on-exec flag on Linux,
|
// dup2(i, i) won't clear close-on-exec flag on Linux,
|
||||||
// probably not elsewhere either.
|
// probably not elsewhere either.
|
||||||
if ret := os.Fcntl(c.Int(fd[i]), syscall.F_SETFD, 0); ret != 0 {
|
if ret := os.Fcntl(c.Int(fd[i]), syscall.F_SETFD, 0); ret < 0 {
|
||||||
err1 = Errno(ret)
|
err1 = Errno(os.Errno)
|
||||||
goto childerror
|
goto childerror
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// The new fd is created NOT close-on-exec,
|
// The new fd is created NOT close-on-exec,
|
||||||
if ret := os.Dup2(c.Int(fd[i]), c.Int(i)); ret != 0 {
|
if ret := os.Dup2(c.Int(fd[i]), c.Int(i)); ret < 0 {
|
||||||
err1 = Errno(ret)
|
err1 = Errno(os.Errno)
|
||||||
goto childerror
|
goto childerror
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -281,10 +281,7 @@ func forkAndExecInChild(argv0 *c.Char, argv, envv **c.Char, chroot, dir *c.Char,
|
|||||||
// Programs that know they inherit fds >= 3 will need
|
// Programs that know they inherit fds >= 3 will need
|
||||||
// to set them close-on-exec.
|
// to set them close-on-exec.
|
||||||
for i = len(fd); i < 3; i++ {
|
for i = len(fd); i < 3; i++ {
|
||||||
/* TODO(xsw):
|
os.Close(c.Int(i))
|
||||||
rawSyscall(abi.FuncPCABI0(libc_close_trampoline), uintptr(i), 0, 0)
|
|
||||||
*/
|
|
||||||
panic("todo: syscall.forkAndExecInChild - for i")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detach fd 0 from tty
|
// Detach fd 0 from tty
|
||||||
|
|||||||
Reference in New Issue
Block a user