r170: Use waitpid() rather than wait() to avoid it hanging while waiting for a
authoryoe <yoe>
Fri, 4 Aug 2006 18:34:12 +0000 (18:34 +0000)
committeryoe <yoe>
Fri, 4 Aug 2006 18:34:12 +0000 (18:34 +0000)
child if we receive a spurious SIGCHLD.

nbd-server.c

index c21e3c6..e2463ae 100644 (file)
@@ -536,12 +536,12 @@ GArray* parse_cfile(gchar* f, GError** e) {
  * is severely wrong)
  **/
 void sigchld_handler(int s) {
-        int* status=NULL;
+        int status;
        int* i;
        pid_t pid;
 
-       while((pid=wait(status)) > 0) {
-               if(WIFEXITED(status)) {
+       while((pid=waitpid(-1, &status, WNOHANG)) > 0) {
+               if(WIFEXITED(&status)) {
                        msg3(LOG_INFO, "Child exited with %d", WEXITSTATUS(status));
                }
                i=g_hash_table_lookup(children, &pid);