From 8d2eb62a1070dc2ee5be99338d4fa66981002c12 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 23 Apr 2021 11:17:33 +0200 Subject: [PATCH] printing: Avoid zombies in the background daemon Whatever you read about waitpid() tells you should should run it in a loop. Signed-off-by: Volker Lendecke Reviewed-by: Andreas Schneider --- source3/printing/queue_process.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/source3/printing/queue_process.c b/source3/printing/queue_process.c index 7d7d53c35d0..152b5b645ce 100644 --- a/source3/printing/queue_process.c +++ b/source3/printing/queue_process.c @@ -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)