Skip to content

Commit fffffce

Browse files
committed
adjust build tags, un-export fork and execve, add signals for windows and macos
1 parent 8cce6c2 commit fffffce

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

src/os/exec_linux.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +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 posix || aix || linux || dragonfly || freebsd || (js && wasm) || netbsd || openbsd || solaris || wasip1
6-
// +build posix aix linux dragonfly freebsd js,wasm netbsd openbsd solaris wasip1
5+
//go:build linux
76

87
package os
98

@@ -54,12 +53,12 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error)
5453
attr = new(ProcAttr)
5554
}
5655

57-
pid, err = Fork()
56+
pid, err = fork()
5857
if err != nil {
5958
return 0, err
6059
} else {
6160
// else code runs in child, which then should exec the new process
62-
err = Execve(argv0, argv, attr.Env)
61+
err = execve(argv0, argv, attr.Env)
6362
if err != nil {
6463
// exec failed
6564
return 0, err

src/os/exec_other.go

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33

44
package os
55

6+
import "syscall"
7+
8+
var (
9+
Interrupt Signal = syscall.SIGINT
10+
Kill Signal = syscall.SIGKILL
11+
)
12+
613
func findProcess(pid int) (*Process, error) {
714
return &Process{Pid: pid}, nil
815
}

src/os/osexec.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build linux
2-
// +build linux
32

43
package os
54

@@ -9,7 +8,7 @@ import (
98
"unsafe"
109
)
1110

12-
func Fork() (pid int, err error) {
11+
func fork() (pid int, err error) {
1312
// ret := libc_fork()
1413
// ret, _, _ := syscall.Syscall(syscall.SYS_FORK, 0, 0, 0)
1514
ret, _, _ := syscall.Syscall(57, 0, 0, 0)
@@ -21,7 +20,7 @@ func Fork() (pid int, err error) {
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) (err error) {
2524
argv0 := cstring(pathname)
2625

2726
// transform argv and envv into the format expected by execve

src/syscall/syscall_libc.go

+10
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ func (w WaitStatus) Continued() bool { return false }
224224
func (w WaitStatus) StopSignal() Signal { return 0 }
225225
func (w WaitStatus) TrapCause() int { return 0 }
226226

227+
// since rusage is quite a big struct and we stub it out anyway no need to define it here
228+
func Wait4(pid int, wstatus *WaitStatus, options int, rusage uintptr) (wpid int, err error) {
229+
return 0, ENOSYS // TODO
230+
}
231+
227232
func Getenv(key string) (value string, found bool) {
228233
data := cstring(key)
229234
raw := libc_getenv(&data[0])
@@ -451,3 +456,8 @@ func libc_fork() int32
451456
//
452457
//export execve
453458
func libc_execve(filename *byte, argv **byte, envp **byte) int
459+
460+
// pid_t wait4(pid_t pid, int *wstatus, int options, struct rusage *rusage);
461+
//
462+
//export wait4
463+
func libc_wait4(pid int32, wstatus *int, options int, rusage uintptr) int32

0 commit comments

Comments
 (0)