Skip to content

Commit

Permalink
util: fix race condition in WaitForFile
Browse files Browse the repository at this point in the history
when using inotify, check for the file existence once the watcher is
configured.  It solves a race condition where the file is created the
watcher configuration and we'd not have any inotify event.

Closes: containers#2942

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed May 20, 2019
1 parent a83edf2 commit 7e9f2b8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libpod/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ func WaitForFile(path string, chWait chan error, timeout time.Duration) (bool, e
inotifyEvents = watcher.Events
}
defer watcher.Close()

// Verify that the file wasn't created while we were setting up
// the watcher.
if _, err := os.Stat(path); err == nil {
return true, nil
}
}
if inotifyEvents == nil {
// If for any reason we fail to create the inotify
Expand Down

0 comments on commit 7e9f2b8

Please sign in to comment.