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 openbsd dragonfly nacl 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 case "openbsd": 27 procfn = "/proc/curproc/file" 28 case "dragonfly": 29 procfn = "/proc/curproc/file" 30 } 31 return Readlink(procfn) 32 }() 33 34 func executable() (string, error) { 35 return executablePath, executablePathErr 36 } 37