printing: Avoid zombies in the background daemon
authorVolker Lendecke <vl@samba.org>
Fri, 23 Apr 2021 09:17:33 +0000 (11:17 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Tue, 27 Apr 2021 13:24:35 +0000 (13:24 +0000)
Whatever you read about waitpid() tells you should should run it in a
loop.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/printing/queue_process.c

index 7d7d53c35d03414da62057bc34b9d6ad019c4356..152b5b645ce606b3bc149bfecd956b52f10618c5 100644 (file)
@@ -264,14 +264,20 @@ static void bq_sig_chld_handler(struct tevent_context *ev_ctx,
        int status;
        pid_t pid;
 
-       pid = waitpid(-1, &status, WNOHANG);
-       if (WIFEXITED(status)) {
-               DEBUG(6, ("Bq child process %d terminated with %d\n",
-                         (int)pid, WEXITSTATUS(status)));
-       } else {
-               DEBUG(3, ("Bq child process %d terminated abnormally\n",
-                         (int)pid));
-       }
+       do {
+               do {
+                       pid = waitpid(-1, &status, WNOHANG);
+               } while ((pid == -1) && (errno == EINTR));
+
+               if (WIFEXITED(status)) {
+                       DBG_INFO("Bq child process %d terminated with %d\n",
+                                (int)pid,
+                                WEXITSTATUS(status));
+               } else {
+                       DBG_NOTICE("Bq child process %d terminated abnormally\n",
+                                  (int)pid);
+               }
+       } while (pid > 0);
 }
 
 static void bq_setup_sig_chld_handler(struct tevent_context *ev_ctx)