Skip to content

Commit

Permalink
renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
leongross committed Aug 27, 2024
1 parent 8a4a51b commit 8ab06b9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/os/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type Process struct {
}

func StartProcess(name string, argv []string, attr *ProcAttr) (*Process, error) {
return nil, &PathError{Op: "fork/exec", Path: name, Err: ErrNotImplemented}
return startProcess(name, argv, attr)
}

func (p *Process) Wait() (*ProcessState, error) {
Expand Down
12 changes: 6 additions & 6 deletions src/os/exec_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error)
argvp[0] = argv0p
}

pid = syscall.Fork()
if ret < 0 {
ret = syscall.Fork()
if int(ret) < 0 {
return 0, errors.New("fork failed")
}

if ret != 0 {
if int(ret) != 0 {
// if fd == 0 code runs in parent
return int(ret), nil
} else {
// else code runs in child, which then should exec the new process
ret = syscall.Execve(argv0, argv, envp)
if ret != 0 {
if int(ret) != 0 {
// exec failed
syscall.Exit(1)
return int(ret), errors.New("exec failed")
}
// 3. TODO: use pipes to communicate back child status
return int(ret), nil
Expand All @@ -101,7 +101,7 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error)
// The StartProcess function creates a new process by forking the current process and then calling execve to replace the current process with the new process.
// It thereby replaces the newly created process with the specified command and arguments.
func startProcess(name string, argv []string, attr *ProcAttr) (p *Process, err error) {
pid, err := ForkExec(name, argv, attr)
pid, err := forkExec(name, argv, attr)
if err != nil {
return nil, err
}
Expand Down
File renamed without changes.

0 comments on commit 8ab06b9

Please sign in to comment.