snapshot: clean up fork-based error handling
authorBrian Norris <banorris@uci.edu>
Fri, 5 Apr 2013 21:02:58 +0000 (14:02 -0700)
committerBrian Norris <banorris@uci.edu>
Fri, 5 Apr 2013 23:13:49 +0000 (16:13 -0700)
This is an ugly attempt at error handling. Kill the useless variables,
reword the debug prints, and use perror().

snapshot.cc

index 5069a1cf1147cb7afb07035cbf607c69daa2c284..da478075c8b4f8bde0c4fdfb3bc499f44a79ace9 100644 (file)
@@ -347,19 +347,19 @@ static void fork_snapshot_init(unsigned int numbackingpages,
                                setcontext(&savedUserSnapshotContext);
                        }
                } else {
-                       int status;
-                       int retVal;
-
-                       DEBUG("The process id of child is %d and the process id of this process is %d and snapshot id is %d\n",
-                               forkedID, getpid(), snapshotid);
-
-                       do {
-                               retVal = waitpid(forkedID, &status, 0);
-                       } while (-1 == retVal && errno == EINTR);
+                       DEBUG("parent PID: %d, child PID: %d, snapshot ID: %d\n",
+                               getpid(), forkedID, snapshotid);
+
+                       while (waitpid(forkedID, NULL, 0) < 0) {
+                               /* waitpid() may be interrupted */
+                               if (errno != EINTR) {
+                                       perror("waitpid");
+                                       exit(EXIT_FAILURE);
+                               }
+                       }
 
-                       if (fork_snap->mIDToRollback != snapshotid) {
+                       if (fork_snap->mIDToRollback != snapshotid)
                                exit(EXIT_SUCCESS);
-                       }
                        rollback = true;
                }
        }