os: on OpenBSD implement Executable using Args[0]

OpenBSD no longer has procfs.

Based on a patch by Matthieu Sarter.

Fixes #19453.

Change-Id: Ia09d16f8a1cbef2f8cc1c5f49e9c61ec7d026a40
Reviewed-on: https://go-review.googlesource.com/46004
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Ian Lance Taylor 2017-06-16 18:13:13 -07:00
parent fddc598370
commit c60d6c0b43
3 changed files with 112 additions and 7 deletions

View file

@ -20,10 +20,6 @@ func TestExecutable(t *testing.T) {
testenv.MustHaveExec(t) // will also execlude nacl, which doesn't support Executable anyway
ep, err := os.Executable()
if err != nil {
switch goos := runtime.GOOS; goos {
case "openbsd": // procfs is not mounted by default
t.Skipf("Executable failed on %s: %v, expected", goos, err)
}
t.Fatalf("Executable failed: %v", err)
}
// we want fn to be of the form "dir/prog"
@ -32,6 +28,13 @@ func TestExecutable(t *testing.T) {
if err != nil {
t.Fatalf("filepath.Rel: %v", err)
}
if runtime.GOOS == "openbsd" {
// The rest of the test doesn't work on OpenBSD,
// which relies on argv[0].
t.Skipf("skipping remainder of test on %s", runtime.GOOS)
}
cmd := &osexec.Cmd{}
// make child start with a relative program path
cmd.Dir = dir