File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,10 +7,16 @@ import (
77 "syscall"
88)
99
10+ // Self returns the path to the current process's binary.
11+ // Returns "/proc/self/exe".
12+ func Self () string {
13+ return "/proc/self/exe"
14+ }
15+
1016// Command returns *exec.Cmd which have Path as current binary. Also it setting
1117// SysProcAttr.Pdeathsig to SIGTERM.
12- // For example if current binary is "docker" at "/usr/bin", then cmd.Path will
13- // be set to "/usr/bin/docker" .
18+ // This will use the in-memory version (/proc/self/exe) of the current binary,
19+ // it is thus safe to delete or replace the on-disk binary (os.Args[0]) .
1420func Command (args ... string ) * exec.Cmd {
1521 return & exec.Cmd {
1622 Path : Self (),
Original file line number Diff line number Diff line change @@ -6,6 +6,12 @@ import (
66 "os/exec"
77)
88
9+ // Self returns the path to the current process's binary.
10+ // Uses os.Args[0].
11+ func Self () string {
12+ return naiveSelf ()
13+ }
14+
915// Command returns *exec.Cmd which have Path as current binary.
1016// For example if current binary is "docker.exe" at "C:\", then cmd.Path will
1117// be set to "C:\docker.exe".
Original file line number Diff line number Diff line change @@ -30,8 +30,7 @@ func Init() bool {
3030 return false
3131}
3232
33- // Self returns the path to the current processes binary
34- func Self () string {
33+ func naiveSelf () string {
3534 name := os .Args [0 ]
3635 if filepath .Base (name ) == name {
3736 if lp , err := exec .LookPath (name ); err == nil {
You can’t perform that action at this time.
0 commit comments