]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add reference counting to child_wait_pid
authorAki Tuomi <aki.tuomi@dovecot.fi>
Thu, 13 Oct 2016 07:11:52 +0000 (10:11 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 19 Oct 2016 12:43:34 +0000 (15:43 +0300)
src/lib/child-wait.c

index 589bbae7fdf4956a4e1061e1f479ab9934ea50e7..e1c69db2e98a2268c699cfd250046434988bdd92 100644 (file)
@@ -14,6 +14,8 @@ struct child_wait {
        void *context;
 };
 
+static int child_wait_refcount = 0;
+
 /* pid_t => wait */
 static HASH_TABLE(void *, struct child_wait *) child_pids;
 
@@ -90,6 +92,8 @@ sigchld_handler(const siginfo_t *si ATTR_UNUSED, void *context ATTR_UNUSED)
 
 void child_wait_init(void)
 {
+       if (child_wait_refcount++ > 0) return;
+
        hash_table_create_direct(&child_pids, default_pool, 0);
 
        lib_signals_set_handler(SIGCHLD, LIBSIG_FLAGS_SAFE,
@@ -102,6 +106,9 @@ void child_wait_deinit(void)
        void *key;
        struct child_wait *value;
 
+       i_assert(child_wait_refcount > 0);
+       if (--child_wait_refcount > 0) return;
+
        lib_signals_unset_handler(SIGCHLD, sigchld_handler, NULL);
 
        iter = hash_table_iterate_init(child_pids);