--- /dev/null
+// Copyright 2024 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.
+
+package os
+
+// From NetBSD's <sys/sysctl.h>
+const (
+ _CTL_KERN = 1
+ _KERN_PROC_ARGS = 48
+ _KERN_PROC_PATHNAME = 5
+)
+
+var executableMIB = [4]int32{_CTL_KERN, _KERN_PROC_ARGS, -1, _KERN_PROC_PATHNAME}
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-//go:build linux || netbsd
+//go:build linux
package os
return "", errors.New("Executable not implemented for " + runtime.GOOS)
case "linux", "android":
procfn = "/proc/self/exe"
- case "netbsd":
- procfn = "/proc/curproc/exe"
}
path, err := Readlink(procfn)
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-//go:build freebsd || dragonfly
+//go:build freebsd || dragonfly || netbsd
package os
)
func executable() (string, error) {
- mib := [4]int32{_CTL_KERN, _KERN_PROC, _KERN_PROC_PATHNAME, -1}
-
n := uintptr(0)
// get length
- _, _, err := syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&mib[0])), 4, 0, uintptr(unsafe.Pointer(&n)), 0, 0)
+ _, _, err := syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&executableMIB[0])), 4, 0, uintptr(unsafe.Pointer(&n)), 0, 0)
if err != 0 {
return "", err
}
return "", nil
}
buf := make([]byte, n)
- _, _, err = syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&mib[0])), 4, uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&n)), 0, 0)
+ _, _, err = syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&executableMIB[0])), 4, uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&n)), 0, 0)
if err != 0 {
return "", err
}