Skip to content

Commit 2d1bd1f

Browse files
binarycrusaderbradfitz
authored andcommitted
syscall: fix Exec on solaris
The test added for issue #18146 exposed a long-existing bug in the Solaris port; notably, that syscall.Exec uses RawSyscall -- which is not actually functional for the Solaris port (intentionally) and only exists as a placebo to satisfy build requirements. Call syscall.execve instead for Solaris. Fixes #20832 Change-Id: I327d863f4bbbbbb6e5ecf66b82152c4030825d09 Reviewed-on: https://go-review.googlesource.com/47032 Run-TryBot: Shawn Walker-Salas <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent cfb8404 commit 2d1bd1f

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/syscall/exec_solaris.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ func setuid(uid uintptr) (err Errno)
4141
func setpgid(pid uintptr, pgid uintptr) (err Errno)
4242
func write1(fd uintptr, buf uintptr, nbyte uintptr) (n uintptr, err Errno)
4343

44+
// syscall defines this global on our behalf to avoid a build dependency on other platforms
45+
func init() {
46+
execveSolaris = execve
47+
}
48+
4449
// Fork, dup fd onto 0..len(fd), and exec(argv0, argvv, envv) in child.
4550
// If a dup or exec fails, write the errno error to pipe.
4651
// (Pipe is close-on-exec so if exec succeeds, it will be closed.)

src/syscall/exec_unix.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle
246246
func runtime_BeforeExec()
247247
func runtime_AfterExec()
248248

249+
// execveSolaris is non-nil on Solaris, set to execve in exec_solaris.go; this
250+
// avoids a build dependency for other platforms.
251+
var execveSolaris func(path uintptr, argv uintptr, envp uintptr) (err Errno)
252+
249253
// Exec invokes the execve(2) system call.
250254
func Exec(argv0 string, argv []string, envv []string) (err error) {
251255
argv0p, err := BytePtrFromString(argv0)
@@ -261,10 +265,20 @@ func Exec(argv0 string, argv []string, envv []string) (err error) {
261265
return err
262266
}
263267
runtime_BeforeExec()
264-
_, _, err1 := RawSyscall(SYS_EXECVE,
265-
uintptr(unsafe.Pointer(argv0p)),
266-
uintptr(unsafe.Pointer(&argvp[0])),
267-
uintptr(unsafe.Pointer(&envvp[0])))
268+
269+
var err1 Errno
270+
if runtime.GOOS == "solaris" {
271+
// RawSyscall should never be used on Solaris.
272+
err1 = execveSolaris(
273+
uintptr(unsafe.Pointer(argv0p)),
274+
uintptr(unsafe.Pointer(&argvp[0])),
275+
uintptr(unsafe.Pointer(&envvp[0])))
276+
} else {
277+
_, _, err1 = RawSyscall(SYS_EXECVE,
278+
uintptr(unsafe.Pointer(argv0p)),
279+
uintptr(unsafe.Pointer(&argvp[0])),
280+
uintptr(unsafe.Pointer(&envvp[0])))
281+
}
268282
runtime_AfterExec()
269-
return Errno(err1)
283+
return err1
270284
}

0 commit comments

Comments
 (0)