Debian Codegraph @

src/os/executable_procfs.go

raw
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 //go:build linux
6
7 package os
8
9 import (
10 "errors"
11 "internal/stringslite"
12 "runtime"
13 )
14
15 func executable() (string, error) {
16 var procfn string
17 switch runtime.GOOS {
18 default:
19 return "", errors.New("Executable not implemented for " + runtime.GOOS)
20 case "linux", "android":
21 procfn = "/proc/self/exe"
22 }
23 path, err := Readlink(procfn)
24
25 // When the executable has been deleted then Readlink returns a
26 // path appended with " (deleted)".
27 return stringslite.TrimSuffix(path, " (deleted)"), err
28 }