Skip to content

Commit

Permalink
adjust build tags, un-export fork and execve, add signals for windows…
Browse files Browse the repository at this point in the history
… and macos

Signed-off-by: leongross <[email protected]>
  • Loading branch information
leongross committed Aug 5, 2024
1 parent 8cce6c2 commit 0844543
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/os/exec_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build posix || aix || linux || dragonfly || freebsd || (js && wasm) || netbsd || openbsd || solaris || wasip1
// +build posix aix linux dragonfly freebsd js,wasm netbsd openbsd solaris wasip1
//go:build linux

package os

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

pid, err = Fork()
pid, err = fork()
if err != nil {
return 0, err
} else {
// else code runs in child, which then should exec the new process
err = Execve(argv0, argv, attr.Env)
err = execve(argv0, argv, attr.Env)
if err != nil {
// exec failed
return 0, err
Expand Down
7 changes: 7 additions & 0 deletions src/os/exec_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

package os

import "syscall"

var (
Interrupt Signal = syscall.SIGINT
Kill Signal = syscall.SIGKILL
)

func findProcess(pid int) (*Process, error) {
return &Process{Pid: pid}, nil
}
Expand Down
5 changes: 2 additions & 3 deletions src/os/osexec.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build linux
// +build linux

package os

Expand All @@ -9,7 +8,7 @@ import (
"unsafe"
)

func Fork() (pid int, err error) {
func fork() (pid int, err error) {
// ret := libc_fork()
// ret, _, _ := syscall.Syscall(syscall.SYS_FORK, 0, 0, 0)
ret, _, _ := syscall.Syscall(57, 0, 0, 0)
Expand All @@ -21,7 +20,7 @@ func Fork() (pid int, err error) {
}

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

// transform argv and envv into the format expected by execve
Expand Down
5 changes: 5 additions & 0 deletions src/syscall/syscall_libc.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ func (w WaitStatus) Continued() bool { return false }
func (w WaitStatus) StopSignal() Signal { return 0 }
func (w WaitStatus) TrapCause() int { return 0 }

// since rusage is quite a big struct and we stub it out anyway no need to define it here
func Wait4(pid int, wstatus *WaitStatus, options int, rusage uintptr) (wpid int, err error) {
return 0, ENOSYS // TODO
}

func Getenv(key string) (value string, found bool) {
data := cstring(key)
raw := libc_getenv(&data[0])
Expand Down

0 comments on commit 0844543

Please sign in to comment.