Patchwork libgo patch committed: Change Dup2 to only return an error

login
register
mail settings
Submitter Ian Taylor
Date Feb. 14, 2012, 7:36 p.m.
Message ID <mcr4nutb41q.fsf@dhcp-172-18-216-180.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/141177/
State New
Headers show

Comments

Ian Taylor - Feb. 14, 2012, 7:36 p.m.
In the master Go library the syscall.Dup2 function was changed to only
return an error, rather than returning both the new file descriptor and
and an error (when there is no error the new file descriptor is always
the second argument anyhow).  This patch makes the same change to
libgo.  Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian

Patch

diff -r eb004a41aa88 libgo/go/syscall/exec_bsd.go
--- a/libgo/go/syscall/exec_bsd.go	Tue Feb 14 10:00:14 2012 -0800
+++ b/libgo/go/syscall/exec_bsd.go	Tue Feb 14 11:34:01 2012 -0800
@@ -136,9 +136,8 @@ 
 	// 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 @@ 
 	}
 	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 @@ 
 		}
 		// 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
 		}
 	}
diff -r eb004a41aa88 libgo/go/syscall/exec_linux.go
--- a/libgo/go/syscall/exec_linux.go	Tue Feb 14 10:00:14 2012 -0800
+++ b/libgo/go/syscall/exec_linux.go	Tue Feb 14 11:34:01 2012 -0800
@@ -161,9 +161,8 @@ 
 	// 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 @@ 
 	}
 	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 @@ 
 		}
 		// 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
 		}
 	}
diff -r eb004a41aa88 libgo/go/syscall/exec_unix.go
--- a/libgo/go/syscall/exec_unix.go	Tue Feb 14 10:00:14 2012 -0800
+++ b/libgo/go/syscall/exec_unix.go	Tue Feb 14 11:34:01 2012 -0800
@@ -47,6 +47,9 @@ 
 //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
diff -r eb004a41aa88 libgo/go/syscall/libcall_posix.go
--- a/libgo/go/syscall/libcall_posix.go	Tue Feb 14 10:00:14 2012 -0800
+++ b/libgo/go/syscall/libcall_posix.go	Tue Feb 14 11:34:01 2012 -0800
@@ -178,7 +178,7 @@ 
 //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)