github.com/geraldss/go/src@v0.0.0-20210511222824-ac7d0ebfc235/os/executable_procfs.go (about) 1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build linux netbsd js,wasm 6 7 package os 8 9 import ( 10 "errors" 11 "runtime" 12 ) 13 14 // We query the executable path at init time to avoid the problem of 15 // readlink returns a path appended with " (deleted)" when the original 16 // binary gets deleted. 17 var executablePath, executablePathErr = func() (string, error) { 18 var procfn string 19 switch runtime.GOOS { 20 default: 21 return "", errors.New("Executable not implemented for " + runtime.GOOS) 22 case "linux", "android": 23 procfn = "/proc/self/exe" 24 case "netbsd": 25 procfn = "/proc/curproc/exe" 26 } 27 return Readlink(procfn) 28 }() 29 30 func executable() (string, error) { 31 return executablePath, executablePathErr 32 }