daemon: Tolerate EINTR in fork_and_wait_for_startup().
authorBen Pfaff <blp@nicira.com>
Thu, 31 Mar 2011 16:36:10 +0000 (09:36 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 29 Apr 2011 21:31:49 +0000 (14:31 -0700)
It seems possible that a signal coming in at the wrong time could confuse
this code.  It's always best to loop on EINTR.

lib/daemon.c
python/ovs/daemon.py

index 64e2f9e..173dabe 100644 (file)
@@ -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;
 
index 4e54e69..4df2371 100644 (file)
@@ -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