Просмотр исходного кода

BProcess: call waitpid() for all processes, not just recognized ones. This is needed so that BProcess processes whose BProcess objects have been freed don't remain
zombies. Be quiet if we wait for an unknown process, or if the wait fails. This is because we may catch SIGCHLD signals for processes which were ran synchronously and
were already waited for, e.g. with system().

ambrop7 15 лет назад
Родитель
Сommit
7dd1d83522
1 измененных файлов с 13 добавлено и 13 удалено
  1. 13 13
      system/BProcess.c

+ 13 - 13
system/BProcess.c

@@ -54,6 +54,18 @@ static void signal_handler (BProcessManager *o, struct BUnixSignal_siginfo sigin
     ASSERT(siginfo.signo == SIGCHLD)
     DebugObject_Access(&o->d_obj);
     
+    // read exit status with waitpid()
+    int status;
+    pid_t res = waitpid(siginfo.pid, &status, WNOHANG);
+    if (res < 0) {
+        BLog(BLOG_DEBUG, "waitpid(%"PRIiMAX") failed", (intmax_t)siginfo.pid);
+        return;
+    }
+    if (res == 0) {
+        BLog(BLOG_ERROR, "waitpid(%"PRIiMAX") returned 0", (intmax_t)siginfo.pid);
+        return;
+    }
+    
     // find process
     BProcess *p = NULL;
     LinkedList2Iterator it;
@@ -69,19 +81,7 @@ static void signal_handler (BProcessManager *o, struct BUnixSignal_siginfo sigin
     }
     
     if (!p) {
-        BLog(BLOG_ERROR, "got SIGCHLD for unknown pid");
-        return;
-    }
-    
-    // read exit status with waitpid()
-    int status;
-    pid_t res = waitpid(p->pid, &status, WNOHANG);
-    if (res < 0) {
-        BLog(BLOG_ERROR, "waitpid(%"PRIiMAX") failed", (intmax_t)p->pid);
-        return;
-    }
-    if (res == 0) {
-        BLog(BLOG_ERROR, "waitpid(%"PRIiMAX") returned 0", (intmax_t)p->pid);
+        BLog(BLOG_DEBUG, "got SIGCHLD for unknown pid");
         return;
     }