syscall: Change Dup2 to only return an error.

From-SVN: r184222
This commit is contained in:
Ian Lance Taylor 2012-02-14 19:36:31 +00:00
parent 4b386d4d6a
commit 2b120fe98e
4 changed files with 15 additions and 18 deletions

View File

@ -136,9 +136,8 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr
// so that pass 2 won't stomp on an fd it needs later.
nextfd = int(len(fd))
if pipe < nextfd {
_, err2 := Dup2(pipe, nextfd)
if err2 != nil {
err1 = err2.(Errno)
err1 = raw_dup2(pipe, nextfd)
if err1 != 0 {
goto childerror
}
raw_fcntl(nextfd, F_SETFD, FD_CLOEXEC)
@ -147,9 +146,8 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr
}
for i = 0; i < len(fd); i++ {
if fd[i] >= 0 && fd[i] < int(i) {
_, err2 := Dup2(fd[i], nextfd)
if err2 != nil {
err1 = err2.(Errno)
err1 = raw_dup2(fd[i], nextfd)
if err1 != 0 {
goto childerror
}
raw_fcntl(nextfd, F_SETFD, FD_CLOEXEC)
@ -178,9 +176,8 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr
}
// The new fd is created NOT close-on-exec,
// which is exactly what we want.
_, err2 := Dup2(fd[i], i)
err1 = raw_dup2(fd[i], i)
if err1 != 0 {
err1 = err2.(Errno)
goto childerror
}
}

View File

@ -161,9 +161,8 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr
// so that pass 2 won't stomp on an fd it needs later.
nextfd = int(len(fd))
if pipe < nextfd {
_, err2 := Dup2(pipe, nextfd)
if err2 != nil {
err1 = err2.(Errno)
err1 = raw_dup2(pipe, nextfd)
if err1 != 0 {
goto childerror
}
raw_fcntl(nextfd, F_SETFD, FD_CLOEXEC)
@ -172,9 +171,8 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr
}
for i = 0; i < len(fd); i++ {
if fd[i] >= 0 && fd[i] < int(i) {
_, err2 := Dup2(fd[i], nextfd)
if err2 != nil {
err1 = err2.(Errno)
err1 = raw_dup2(fd[i], nextfd)
if err1 != 0 {
goto childerror
}
raw_fcntl(nextfd, F_SETFD, FD_CLOEXEC)
@ -203,9 +201,8 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr
}
// The new fd is created NOT close-on-exec,
// which is exactly what we want.
_, err2 := Dup2(fd[i], i);
if err2 != nil {
err1 = err2.(Errno)
err1 = raw_dup2(fd[i], i)
if err1 != 0 {
goto childerror
}
}

View File

@ -47,6 +47,9 @@ import (
//sysnb raw_exit(status int)
//_exit(status int)
//sysnb raw_dup2(oldfd int, newfd int) (err Errno)
//dup2(oldfd int, newfd int) int
// Note: not raw, returns error rather than Errno.
//sys read(fd int, p *byte, np int) (n int, err error)
//read(fd int, buf *byte, count Size_t) Ssize_t

View File

@ -178,7 +178,7 @@ func FDZero(set *FdSet) {
//sysnb Dup(oldfd int) (fd int, err error)
//dup(oldfd int) int
//sysnb Dup2(oldfd int, newfd int) (fd int, err error)
//sysnb Dup2(oldfd int, newfd int) (err error)
//dup2(oldfd int, newfd int) int
//sys Exit(code int)