diff --git a/src/os/exec.go b/src/os/exec.go index 4ed76f18ca..28406f916b 100644 --- a/src/os/exec.go +++ b/src/os/exec.go @@ -5,6 +5,12 @@ import ( "syscall" ) +var ( + ErrNotImplementedDir = errors.New("directory setting not implemented") + ErrNotImplementedSys = errors.New("sys setting not implemented") + ErrNotImplementedFiles = errors.New("files setting not implemented") +) + type Signal interface { String() string Signal() // to distinguish from other Stringers diff --git a/src/os/exec_linux.go b/src/os/exec_linux.go index a2b9bb8d7e..9cf2fdce8d 100644 --- a/src/os/exec_linux.go +++ b/src/os/exec_linux.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build linux && !baremetal && !tinygo.wasm && !arm64 +//go:build linux && !baremetal && !tinygo.wasm package os @@ -22,12 +22,6 @@ var ( Kill Signal = syscall.SIGKILL ) -var ( - ErrNotImplementedDir = errors.New("directory setting not implemented") - ErrNotImplementedSys = errors.New("sys setting not implemented") - ErrNotImplementedFiles = errors.New("files setting not implemented") -) - // Keep compatible with golang and always succeed and return new proc with pid on Linux. func findProcess(pid int) (*Process, error) { return &Process{Pid: pid}, nil diff --git a/src/os/exec_linux_arm64.go b/src/os/exec_linux_arm64.go deleted file mode 100644 index 765433eb2c..0000000000 --- a/src/os/exec_linux_arm64.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build linux && !baremetal && !tinygo.wasm && arm64 - -package os - -import ( - "errors" - "runtime" - "syscall" -) - -var ( - Interrupt Signal = syscall.SIGINT - Kill Signal = syscall.SIGKILL -) - -// Keep compatible with golang and always succeed and return new proc with pid on Linux. -func findProcess(pid int) (*Process, error) { - return &Process{Pid: pid}, nil -} - -func (p *Process) release() error { - // NOOP for unix. - p.Pid = -1 - // no need for a finalizer anymore - runtime.SetFinalizer(p, nil) - return nil -} - -// On the aarch64 architecture, the fork system call is not available. -// Therefore, the fork function is implemented to return an error. -func startProcess(name string, argv []string, attr *ProcAttr) (p *Process, err error) { - return nil, errors.New("fork not yet supported on aarch64") -} diff --git a/src/os/exec_linux_test.go b/src/os/exec_linux_test.go index 4b56b88d2d..34f1fef983 100644 --- a/src/os/exec_linux_test.go +++ b/src/os/exec_linux_test.go @@ -1,4 +1,4 @@ -//go: build linux && !baremetal && !tinygo.wasm +//go:build linux && !baremetal && !tinygo.wasm package os_test @@ -24,10 +24,13 @@ func TestForkExec(t *testing.T) { t.Fatalf("forkExec failed: %v", err) } + if proc == nil { + t.Fatalf("proc is nil") + } + if proc.Pid == 0 { t.Fatalf("forkExec failed: new process has pid 0") } - t.Logf("forkExec succeeded: new process has pid %d", proc) } func TestForkExecErrNotExist(t *testing.T) { diff --git a/src/os/osexec.go b/src/os/osexec.go index d557222c9b..944a0e62fd 100644 --- a/src/os/osexec.go +++ b/src/os/osexec.go @@ -1,4 +1,4 @@ -//go:build linux && !baremetal && !tinygo.wasm && !arm64 +//go:build linux && !baremetal && !tinygo.wasm // arm64 does not have a fork syscall, so ignore it for now // TODO: add support for arm64 with clone or use musl implementation @@ -13,7 +13,9 @@ import ( func fork() (pid int32, err error) { pid = libc_fork() if pid != 0 { - err = syscall.Errno(*libc_errno()) + if errno := *libc_errno(); errno != 0 { + err = syscall.Errno(*libc_errno()) + } } return }