From: Aki Tuomi Date: Thu, 13 Oct 2016 07:11:52 +0000 (+0300) Subject: lib: Add reference counting to child_wait_pid X-Git-Tag: 2.2.26~103 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=338bc725b24c78bf973c219e45a8a47e3a492139;p=thirdparty%2Fdovecot%2Fcore.git lib: Add reference counting to child_wait_pid --- diff --git a/src/lib/child-wait.c b/src/lib/child-wait.c index 589bbae7fd..e1c69db2e9 100644 --- a/src/lib/child-wait.c +++ b/src/lib/child-wait.c @@ -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);