diff options
-rw-r--r-- | runsc/cmd/exec.go | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/runsc/cmd/exec.go b/runsc/cmd/exec.go index 9a395e6f1..35aa5499e 100644 --- a/runsc/cmd/exec.go +++ b/runsc/cmd/exec.go @@ -146,12 +146,6 @@ func (ex *Exec) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) return ex.execAndWait(waitStatus) } - if ex.pidFile != "" { - if err := ioutil.WriteFile(ex.pidFile, []byte(strconv.Itoa(os.Getpid())), 0644); err != nil { - Fatalf("error writing pid file: %v", err) - } - } - // Start the new process and get it pid. pid, err := c.Execute(e) if err != nil { @@ -173,6 +167,15 @@ func (ex *Exec) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) } } + // Generate the pid file after the internal pid file is generated, so that users + // can safely assume that the internal pid file is ready after `runsc exec -d` + // returns. + if ex.pidFile != "" { + if err := ioutil.WriteFile(ex.pidFile, []byte(strconv.Itoa(os.Getpid())), 0644); err != nil { + Fatalf("error writing pid file: %v", err) + } + } + // Wait for the process to exit. ws, err := c.WaitPID(pid, ex.clearStatus) if err != nil { |