s3-printing: Add child handler to bq process
authorSimo Sorce <idra@samba.org>
Wed, 10 Aug 2011 12:59:44 +0000 (08:59 -0400)
committerAndreas Schneider <asn@samba.org>
Wed, 10 Aug 2011 16:14:05 +0000 (18:14 +0200)
The cups backend forks a child to do asynchronous work.
We need a sigchld handler in bq to properly wait for the chilod to finish and
reap it, otherwise it hangs the forever as a zombie process.

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

index 1b7b4f85790ac7524db31394791b94db50ecfa9b..20f1a5b06b4969dc43b1f2269e32264327084638 100644 (file)
@@ -142,6 +142,35 @@ static void bq_setup_sig_hup_handler(struct tevent_context *ev,
        }
 }
 
+static void bq_sig_chld_handler(struct tevent_context *ev_ctx,
+                               struct tevent_signal *se,
+                               int signum, int count,
+                               void *siginfo, void *pvt)
+{
+       int status;
+       pid_t pid;
+
+       pid = sys_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));
+       }
+}
+
+static void bq_setup_sig_chld_handler(struct tevent_context *ev_ctx)
+{
+       struct tevent_signal *se;
+
+       se = tevent_add_signal(ev_ctx, ev_ctx, SIGCHLD, 0,
+                               bq_sig_chld_handler, NULL);
+       if (!se) {
+               exit_server("failed to setup SIGCHLD handler");
+       }
+}
+
 static void bq_smb_conf_updated(struct messaging_context *msg_ctx,
                                void *private_data,
                                uint32_t msg_type,
@@ -235,14 +264,11 @@ pid_t start_background_queue(struct tevent_context *ev,
                bq_reopen_logs(logfile);
                bq_setup_sig_term_handler();
                bq_setup_sig_hup_handler(ev, msg_ctx);
+               bq_setup_sig_chld_handler(ev);
 
                BlockSignals(false, SIGTERM);
                BlockSignals(false, SIGHUP);
 
-               if (!pcap_cache_loaded()) {
-                       pcap_cache_reload(ev, msg_ctx, &reload_printers);
-               }
-
                if (!printing_subsystem_queue_tasks(ev, msg_ctx)) {
                        exit(1);
                }
@@ -269,6 +295,8 @@ pid_t start_background_queue(struct tevent_context *ev,
                        smb_panic("tevent_add_fd() failed for pause_pipe");
                }
 
+               pcap_cache_reload(ev, msg_ctx, &reload_pcap_change_notify);
+
                DEBUG(5,("start_background_queue: background LPQ thread waiting for messages\n"));
                ret = tevent_loop_wait(ev);
                /* should not be reached */