Skip to content

Commit 7a644d9

Browse files
committed
add syscall error handling
Signed-off-by: leongross <[email protected]>
1 parent 95fb302 commit 7a644d9

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/os/exec_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build linux && !baremetal && !tinygo.wasm
5+
//go:build linux && !baremetal && !tinygo.wasm && !aarch64
66

77
package os
88

src/os/osexec.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,21 @@
66
package os
77

88
import (
9-
"errors"
109
"syscall"
1110
"unsafe"
1211
)
1312

1413
func fork() (pid int, err error) {
15-
ret, _, _ := syscall.Syscall(syscall.SYS_FORK, 0, 0, 0)
16-
if ret < 0 {
17-
// TODO: parse the syscall return codes
18-
return 0, errors.New("fork failed")
14+
ret, _, err := syscall.Syscall(syscall.SYS_FORK, 0, 0, 0)
15+
if int(ret) != 0 {
16+
errno := err.(syscall.Errno)
17+
return 0, errno
1918
}
2019
return int(ret), nil
2120
}
2221

2322
// the golang standard library does not expose interfaces for execve and fork, so we define them here the same way via the libc wrapper
24-
func execve(pathname string, argv []string, envv []string) (err error) {
23+
func execve(pathname string, argv []string, envv []string) error {
2524
argv0 := cstring(pathname)
2625

2726
// transform argv and envv into the format expected by execve
@@ -37,10 +36,11 @@ func execve(pathname string, argv []string, envv []string) (err error) {
3736
}
3837
env1[len(envv)] = nil
3938

40-
fail, _, _ := syscall.Syscall(syscall.SYS_EXECVE, uintptr(unsafe.Pointer(&argv0[0])), uintptr(unsafe.Pointer(&argv1[0])), uintptr(unsafe.Pointer(&env1[0])))
41-
if fail < 0 {
42-
// TODO: parse the syscall return codes
43-
return errors.New("execve failed")
39+
ret, _, err := syscall.Syscall(syscall.SYS_EXECVE, uintptr(unsafe.Pointer(&argv0[0])), uintptr(unsafe.Pointer(&argv1[0])), uintptr(unsafe.Pointer(&env1[0])))
40+
if int(ret) != 0 {
41+
// errno := err.(syscall.Errno)
42+
// return errno
43+
return err
4444
}
4545

4646
return nil

0 commit comments

Comments
 (0)