MCPcopy Index your code
hub / github.com/smallstep/cli / RunWithPid

Function RunWithPid

exec/exec.go:72–100  ·  view source on GitHub ↗

RunWithPid calls Run and writes the process ID in pidFile.

(pidFile, name string, arg ...string)

Source from the content-addressed store, hash-verified

70
71// RunWithPid calls Run and writes the process ID in pidFile.
72func 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
103func OpenInBrowser(url, browser string) error {

Callers

nothing calls this directly

Calls 5

errorAndExitFunction · 0.85
errorfFunction · 0.85
getExitStatusFunction · 0.85
runFunction · 0.70
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…