diff options
author | Ben Pfaff <blp@nicira.com> | 2011-03-31 09:36:10 -0700 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2011-04-29 14:31:49 -0700 |
commit | 8fb32694154c620dce9ff0379a744178f73c1c89 (patch) | |
tree | 2a1c7f1960e5fd6bc0b95382f1c1018b4602db6d | |
parent | a328a943f173391cd9a9a54e257c8dabcd463402 (diff) | |
download | openvswitch-8fb32694154c620dce9ff0379a744178f73c1c89.tar.gz |
daemon: Tolerate EINTR in fork_and_wait_for_startup().
It seems possible that a signal coming in at the wrong time could confuse
this code. It's always best to loop on EINTR.
-rw-r--r-- | lib/daemon.c | 3 | ||||
-rw-r--r-- | python/ovs/daemon.py | 13 |
2 files changed, 11 insertions, 5 deletions
diff --git a/lib/daemon.c b/lib/daemon.c index 64e2f9e9a..173dabe6f 100644 --- a/lib/daemon.c +++ b/lib/daemon.c @@ -244,11 +244,12 @@ fork_and_wait_for_startup(int *fdp) pid = fork(); if (pid > 0) { /* Running in parent process. */ + size_t bytes_read; char c; close(fds[1]); fatal_signal_fork(); - if (read(fds[0], &c, 1) != 1) { + if (read_fully(fds[0], &c, 1, &bytes_read) != 0) { int retval; int status; diff --git a/python/ovs/daemon.py b/python/ovs/daemon.py index 4e54e697f..4df237159 100644 --- a/python/ovs/daemon.py +++ b/python/ovs/daemon.py @@ -213,10 +213,15 @@ def _fork_and_wait_for_startup(): # Running in parent process. os.close(wfd) ovs.fatal_signal.fork() - try: - s = os.read(rfd, 1) - except OSError, e: - s = "" + while True: + try: + s = os.read(rfd, 1) + error = 0 + except OSError, e: + s = "" + error = e.errno + if error != errno.EINTR: + break if len(s) != 1: retval, status = _waitpid(pid, 0) if (retval == pid and |