Skip to content

Commit

Permalink
os/StartProcess: cleanup
Browse files Browse the repository at this point in the history
remove old comments, replace explicit syscall numbers with named
variants, undo tempfile seed generation, remove old // +build tags,
improve StartProcess documentation.

Signed-off-by: leongross <[email protected]>
  • Loading branch information
leongross committed Sep 11, 2024
1 parent 404661d commit 17d1525
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/os/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ type Process struct {
Pid int
}

// Wrapper for the forkExec function, which is a wrapper around the fork and execve system calls.
// StartProcess starts a new process with the program, arguments and attributes specified by name, argv and attr.
// Arguments to the process (os.Args) are passed via argv.
func StartProcess(name string, argv []string, attr *ProcAttr) (*Process, error) {
return startProcess(name, argv, attr)
}
Expand Down
1 change: 0 additions & 1 deletion src/os/exec_other.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build (!aix && !android && !freebsd && !linux && !netbsd && !openbsd && !plan9 && !solaris) || baremetal || tinygo.wasm
// +build !aix,!android,!freebsd,!linux,!netbsd,!openbsd,!plan9,!solaris baremetal tinygo.wasm

package os

Expand Down
6 changes: 2 additions & 4 deletions src/os/osexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import (
)

func fork() (pid int, err error) {
// ret, _, _ := syscall.Syscall(syscall.SYS_FORK, 0, 0, 0)
ret, _, _ := syscall.Syscall(57, 0, 0, 0)
ret, _, _ := syscall.Syscall(syscall.SYS_FORK, 0, 0, 0)
if ret < 0 {
// TODO: parse the syscall return codes
return 0, errors.New("fork failed")
Expand All @@ -35,8 +34,7 @@ func execve(pathname string, argv []string, envv []string) (err error) {
}
env1[len(envv)] = nil

// fail, _, _ := syscall.Syscall(syscall.SYS_EXECVE, uintptr(unsafe.Pointer(&argv0[0])), uintptr(unsafe.Pointer(&argv1[0])), uintptr(unsafe.Pointer(&env1[0])))
fail, _, _ := syscall.Syscall(59, uintptr(unsafe.Pointer(&argv0[0])), uintptr(unsafe.Pointer(&argv1[0])), uintptr(unsafe.Pointer(&env1[0])))
fail, _, _ := syscall.Syscall(syscall.SYS_EXECVE, uintptr(unsafe.Pointer(&argv0[0])), uintptr(unsafe.Pointer(&argv1[0])), uintptr(unsafe.Pointer(&env1[0])))
if fail < 0 {
// TODO: parse the syscall return codes
return errors.New("execve failed")
Expand Down
3 changes: 1 addition & 2 deletions src/os/tempfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ var minrandMutex sync.Mutex
func init() {
// Avoid getting same results on every run
now := time.Now()
// seed := uint32(Getpid()) ^ uint32(now.Nanosecond()) ^ uint32(now.Unix())
seed := uint32(now.Nanosecond()) ^ uint32(now.Unix())
seed := uint32(Getpid()) ^ uint32(now.Nanosecond()) ^ uint32(now.Unix())
// initial state must be odd
minrandPreviousValue = seed | 1
}
Expand Down
1 change: 0 additions & 1 deletion src/syscall/syscall_unix.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build linux || unix
// +build linux unix

package syscall

Expand Down

0 comments on commit 17d1525

Please sign in to comment.