RunWithPid calls Run and writes the process ID in pidFile.
(pidFile, name string, arg ...string)
| 70 | |
| 71 | // RunWithPid calls Run and writes the process ID in pidFile. |
| 72 | func RunWithPid(pidFile, name string, arg ...string) { |
| 73 | f, err := os.OpenFile(pidFile, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600) |
| 74 | if err != nil { |
| 75 | errorAndExit(name, err) |
| 76 | } |
| 77 | |
| 78 | // Run process |
| 79 | cmd, exitCh, err := run(name, arg...) |
| 80 | if err != nil { |
| 81 | f.Close() |
| 82 | _ = os.Remove(f.Name()) // #nosec G703 -- file does not depend on user configuration |
| 83 | errorAndExit(name, err) |
| 84 | } |
| 85 | |
| 86 | // Write pid |
| 87 | f.WriteString(strconv.Itoa(cmd.Process.Pid)) |
| 88 | |
| 89 | f.Close() |
| 90 | |
| 91 | // Wait until it finishes |
| 92 | if err = cmd.Wait(); err != nil { |
| 93 | errorf(name, err) |
| 94 | } |
| 95 | |
| 96 | // clean, exit and wait until os.Exit |
| 97 | _ = os.Remove(f.Name()) // #nosec G703 -- file does not depend on user configuration |
| 98 | exitCh <- getExitStatus(cmd) |
| 99 | exitCh <- 0 |
| 100 | } |
| 101 | |
| 102 | // OpenInBrowser opens the given url on a web browser |
| 103 | func OpenInBrowser(url, browser string) error { |
nothing calls this directly
no test coverage detected
searching dependent graphs…