...

Source file src/os/executable_procfs.go

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

View as plain text