Mercurial > dovecot > core-2.2
changeset 20898:f7e0b7de0540
lib: Add reference counting to child_wait_pid
author | Aki Tuomi <aki.tuomi@dovecot.fi> |
---|---|
date | Thu, 13 Oct 2016 10:11:52 +0300 |
parents | d589f2e1e20a |
children | 29777b0615b9 |
files | src/lib/child-wait.c |
diffstat | 1 files changed, 7 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/child-wait.c Mon Oct 17 12:34:36 2016 +0300 +++ b/src/lib/child-wait.c Thu Oct 13 10:11:52 2016 +0300 @@ -14,6 +14,8 @@ void *context; }; +static int child_wait_refcount = 0; + /* pid_t => wait */ static HASH_TABLE(void *, struct child_wait *) child_pids; @@ -90,6 +92,8 @@ 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 *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);