Executable returns the path name for the executable that started the current process.
()
| 52 | // Executable returns the path name for the executable that started |
| 53 | // the current process. |
| 54 | func Executable() string { |
| 55 | e, err := func(s string) (string, error) { |
| 56 | // prioritize env var in case this is a nested process |
| 57 | if e := os.Getenv(EnvColimaBinary); e != "" { |
| 58 | return e, nil |
| 59 | } |
| 60 | |
| 61 | if filepath.IsAbs(s) { |
| 62 | return s, nil |
| 63 | } |
| 64 | |
| 65 | e, err := exec.LookPath(s) |
| 66 | if err != nil { |
| 67 | return "", fmt.Errorf("error looking up '%s' in PATH: %w", s, err) |
| 68 | } |
| 69 | |
| 70 | abs, err := filepath.Abs(e) |
| 71 | if err != nil { |
| 72 | return "", fmt.Errorf("error computing absolute path of '%s': %w", e, err) |
| 73 | } |
| 74 | |
| 75 | return abs, nil |
| 76 | }(os.Args[0]) |
| 77 | |
| 78 | if err != nil { |
| 79 | // this should never happen, thereby it is safe to do |
| 80 | logrus.Traceln(fmt.Errorf("cannot detect current running executable: %w", err)) |
| 81 | logrus.Traceln("falling back to first CLI argument") |
| 82 | return os.Args[0] |
| 83 | } |
| 84 | |
| 85 | return e |
| 86 | } |
| 87 | |
| 88 | // Socket is a unix socket |
| 89 | type Socket string |
no outgoing calls
no test coverage detected