From: Brian Norris Date: Fri, 5 Apr 2013 21:02:58 +0000 (-0700) Subject: snapshot: clean up fork-based error handling X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=103b2cae595a3744095dd8432b62b138f24ec9eb;p=cdsspec-compiler.git snapshot: clean up fork-based error handling This is an ugly attempt at error handling. Kill the useless variables, reword the debug prints, and use perror(). --- diff --git a/snapshot.cc b/snapshot.cc index 5069a1c..da47807 100644 --- a/snapshot.cc +++ b/snapshot.cc @@ -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; } }