|
3 | 3 | // Handlers can be registered with a name and the argv 0 of the exec of |
4 | 4 | // the binary will be used to find and execute custom init paths. |
5 | 5 | // |
6 | | -// It is used in dockerd to work around forking limitations when using Go. |
| 6 | +// It is used to work around forking limitations when using Go. |
7 | 7 | package reexec |
8 | 8 |
|
9 | 9 | import ( |
@@ -36,10 +36,29 @@ func Init() bool { |
36 | 36 | return false |
37 | 37 | } |
38 | 38 |
|
39 | | -// Self returns the path to the current process's binary. On Linux, it |
40 | | -// returns "/proc/self/exe", which provides the in-memory version of the |
41 | | -// current binary, whereas on other platforms it attempts to looks up the |
42 | | -// absolute path for os.Args[0], or otherwise returns os.Args[0] as-is. |
| 39 | +// Command returns an [*exec.Cmd] with its Path set to the path of the current |
| 40 | +// binary using the result of [Self]. |
| 41 | +// |
| 42 | +// On Linux, the Pdeathsig of [*exec.Cmd.SysProcAttr] is set to SIGTERM. |
| 43 | +// This signal is sent to the process when the OS thread that created |
| 44 | +// the process dies. |
| 45 | +// |
| 46 | +// It is the caller's responsibility to ensure that the creating thread is |
| 47 | +// not terminated prematurely. See https://go.dev/issue/27505 for more details. |
| 48 | +func Command(args ...string) *exec.Cmd { |
| 49 | + return command(args...) |
| 50 | +} |
| 51 | + |
| 52 | +// Self returns the path to the current process's binary. |
| 53 | +// |
| 54 | +// On Linux, it returns "/proc/self/exe", which provides the in-memory version |
| 55 | +// of the current binary. This makes it safe to delete or replace the on-disk |
| 56 | +// binary (os.Args[0]). |
| 57 | +// |
| 58 | +// On Other platforms, it attempts to look up the absolute path for os.Args[0], |
| 59 | +// or otherwise returns os.Args[0] as-is. For example if current binary is |
| 60 | +// "my-binary" at "/usr/bin/" (or "my-binary.exe" at "C:\" on Windows), |
| 61 | +// then it returns "/usr/bin/my-binary" and "C:\my-binary.exe" respectively. |
43 | 62 | func Self() string { |
44 | 63 | if runtime.GOOS == "linux" { |
45 | 64 | return "/proc/self/exe" |
|
0 commit comments