]> Cypherpunks repositories - gostls13.git/commitdiff
pkg/syscall: Plan 9, 64-bit: Update error checks from sys calls.
authorAkshat Kumar <seed@mail.nanosouffle.net>
Mon, 1 Oct 2012 00:09:08 +0000 (10:09 +1000)
committerRob Pike <r@golang.org>
Mon, 1 Oct 2012 00:09:08 +0000 (10:09 +1000)
This change updates CL 6576057 for exceptional cases where
return values from Syscall/RawSyscall functions are used.

The system calls return 32-bit integers. With the recent change
in size of `int' in Go for amd64, the type conversion was not
catching `-1' return values. This change makes the conversion
explicitly `int32'.

R=rsc, r
CC=golang-dev
https://golang.org/cl/6590047

src/pkg/syscall/exec_plan9.go
src/pkg/syscall/syscall_plan9.go

index 75eaad612a769ca3bf7252bf53a4edf1f122ce13..45da9909e60b45385301faed326d9637fa1acf82 100644 (file)
@@ -207,7 +207,7 @@ func forkAndExecInChild(argv0 *byte, argv []*byte, envv []envItem, dir *byte, at
        r1, _, _ = RawSyscall(SYS_RFORK, uintptr(RFPROC|RFFDG|RFREND|clearenv|rflag), 0, 0)
 
        if r1 != 0 {
-               if int(r1) == -1 {
+               if int32(r1) == -1 {
                        return 0, NewError(errstr())
                }
                // parent; return PID
@@ -219,7 +219,7 @@ func forkAndExecInChild(argv0 *byte, argv []*byte, envv []envItem, dir *byte, at
        // Close fds we don't need.
        for i = 0; i < len(fdsToClose); i++ {
                r1, _, _ = RawSyscall(SYS_CLOSE, uintptr(fdsToClose[i]), 0, 0)
-               if int(r1) == -1 {
+               if int32(r1) == -1 {
                        goto childerror
                }
        }
@@ -229,7 +229,7 @@ func forkAndExecInChild(argv0 *byte, argv []*byte, envv []envItem, dir *byte, at
                for i = 0; i < len(envv); i++ {
                        r1, _, _ = RawSyscall(SYS_CREATE, uintptr(unsafe.Pointer(envv[i].name)), uintptr(O_WRONLY), uintptr(0666))
 
-                       if int(r1) == -1 {
+                       if int32(r1) == -1 {
                                goto childerror
                        }
 
@@ -238,13 +238,13 @@ func forkAndExecInChild(argv0 *byte, argv []*byte, envv []envItem, dir *byte, at
                        r1, _, _ = RawSyscall6(SYS_PWRITE, uintptr(envfd), uintptr(unsafe.Pointer(envv[i].value)), uintptr(envv[i].nvalue),
                                ^uintptr(0), ^uintptr(0), 0)
 
-                       if int(r1) == -1 || int(r1) != envv[i].nvalue {
+                       if int32(r1) == -1 || int(r1) != envv[i].nvalue {
                                goto childerror
                        }
 
                        r1, _, _ = RawSyscall(SYS_CLOSE, uintptr(envfd), 0, 0)
 
-                       if int(r1) == -1 {
+                       if int32(r1) == -1 {
                                goto childerror
                        }
                }
@@ -253,7 +253,7 @@ func forkAndExecInChild(argv0 *byte, argv []*byte, envv []envItem, dir *byte, at
        // Chdir
        if dir != nil {
                r1, _, _ = RawSyscall(SYS_CHDIR, uintptr(unsafe.Pointer(dir)), 0, 0)
-               if int(r1) == -1 {
+               if int32(r1) == -1 {
                        goto childerror
                }
        }
@@ -263,7 +263,7 @@ func forkAndExecInChild(argv0 *byte, argv []*byte, envv []envItem, dir *byte, at
        nextfd = int(len(fd))
        if pipe < nextfd {
                r1, _, _ = RawSyscall(SYS_DUP, uintptr(pipe), uintptr(nextfd), 0)
-               if int(r1) == -1 {
+               if int32(r1) == -1 {
                        goto childerror
                }
                pipe = nextfd
@@ -272,7 +272,7 @@ func forkAndExecInChild(argv0 *byte, argv []*byte, envv []envItem, dir *byte, at
        for i = 0; i < len(fd); i++ {
                if fd[i] >= 0 && fd[i] < int(i) {
                        r1, _, _ = RawSyscall(SYS_DUP, uintptr(fd[i]), uintptr(nextfd), 0)
-                       if int(r1) == -1 {
+                       if int32(r1) == -1 {
                                goto childerror
                        }
 
@@ -294,7 +294,7 @@ func forkAndExecInChild(argv0 *byte, argv []*byte, envv []envItem, dir *byte, at
                        continue
                }
                r1, _, _ = RawSyscall(SYS_DUP, uintptr(fd[i]), uintptr(i), 0)
-               if int(r1) == -1 {
+               if int32(r1) == -1 {
                        goto childerror
                }
        }
@@ -519,7 +519,7 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle
 func Exec(argv0 string, argv []string, envv []string) (err error) {
        if envv != nil {
                r1, _, _ := RawSyscall(SYS_RFORK, RFCENVG, 0, 0)
-               if int(r1) == -1 {
+               if int32(r1) == -1 {
                        return NewError(errstr())
                }
 
index 3657f7c15f526a583550e02db0f6260e2cc0fe93..e2da9fe8645fb84ade4749721029a34c26eee5f7 100644 (file)
@@ -255,7 +255,7 @@ func Unmount(name, old string) (err error) {
                r0, _, e = Syscall(SYS_UNMOUNT, uintptr(unsafe.Pointer(namep)), oldptr, 0)
        }
 
-       if int(r0) == -1 {
+       if int32(r0) == -1 {
                err = e
        }
        return