diff options
author | Lantao Liu <lantaol@google.com> | 2018-11-12 11:11:47 -0800 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-11-12 11:12:39 -0800 |
commit | 4cd4b60352bc8a572a0a9482c58564397c49446c (patch) | |
tree | f3dd771e1cf6b58cfa2a0e283fdbbb33cbd0b6e3 /runsc | |
parent | c22da3e7052021f146196fc907dbdb6e3f665877 (diff) |
runsc: generate exec pidfile after everything is ready.
PiperOrigin-RevId: 221123160
Change-Id: Ia7061d60d114d69f49aba853fe6bae3c733522b5
Diffstat (limited to 'runsc')
-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 { |