summaryrefslogtreecommitdiffhomepage
path: root/runsc/cmd/exec.go
diff options
context:
space:
mode:
authorLantao Liu <lantaol@google.com>2018-09-26 17:40:01 -0700
committerShentubot <shentubot@google.com>2018-09-26 17:41:20 -0700
commita003e041c86198122af7e37cc171517f977dde6a (patch)
tree82c74811244ebb10e4d893fffb7cfc4161816e5b /runsc/cmd/exec.go
parent539df2940d4f39191b1b985e6588ca7e9529a8df (diff)
runsc: fix pid file race condition in exec detach mode.
PiperOrigin-RevId: 214700295 Change-Id: I73d8490572eebe5da584af91914650d1953aeb91
Diffstat (limited to 'runsc/cmd/exec.go')
-rw-r--r--runsc/cmd/exec.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/runsc/cmd/exec.go b/runsc/cmd/exec.go
index 957c4f0ff..28229dbcf 100644
--- a/runsc/cmd/exec.go
+++ b/runsc/cmd/exec.go
@@ -247,10 +247,14 @@ func (ex *Exec) execAndWait(waitStatus *syscall.WaitStatus) subcommands.ExitStat
// '--process' file is deleted as soon as this process returns and the child
// may fail to read it.
ready := func() (bool, error) {
- _, err := os.Stat(pidFile)
+ pidb, err := ioutil.ReadFile(pidFile)
if err == nil {
- // File appeared, we're done!
- return true, nil
+ // File appeared, check whether pid is fully written.
+ pid, err := strconv.Atoi(string(pidb))
+ if err != nil {
+ return false, nil
+ }
+ return pid == cmd.Process.Pid, nil
}
if pe, ok := err.(*os.PathError); !ok || pe.Err != syscall.ENOENT {
return false, err