]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: child-wait - Mark the SIGCHLD handler as expected when waiting for child.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Thu, 21 Feb 2019 01:37:41 +0000 (02:37 +0100)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Mon, 25 May 2020 11:43:37 +0000 (11:43 +0000)
This alows waiting for a child to be the only activity on the ioloop.

src/lib/child-wait.c

index bba43a3dece2985bde5f192f012647bd7305bfb8..90f8ec545fae70fd4f1e0c0328b847a8c779f4d9 100644 (file)
@@ -19,6 +19,9 @@ static int child_wait_refcount = 0;
 /* pid_t => wait */
 static HASH_TABLE(void *, struct child_wait *) child_pids;
 
+static void
+sigchld_handler(const siginfo_t *si ATTR_UNUSED, void *context ATTR_UNUSED);
+
 #undef child_wait_new_with_pid
 struct child_wait *
 child_wait_new_with_pid(pid_t pid, child_wait_callback_t *callback,
@@ -64,12 +67,17 @@ void child_wait_add_pid(struct child_wait *wait, pid_t pid)
 {
        wait->pid_count++;
        hash_table_insert(child_pids, POINTER_CAST(pid), wait);
+
+       lib_signals_set_expected(SIGCHLD, TRUE, sigchld_handler, NULL);
 }
 
 void child_wait_remove_pid(struct child_wait *wait, pid_t pid)
 {
        wait->pid_count--;
        hash_table_remove(child_pids, POINTER_CAST(pid));
+
+       if (hash_table_count(child_pids) == 0)
+               lib_signals_set_expected(SIGCHLD, FALSE, sigchld_handler, NULL);
 }
 
 static void