Skip to content

Commit

Permalink
lib: Add reference counting to child_wait_pid
Browse files Browse the repository at this point in the history
  • Loading branch information
cmouse committed Oct 19, 2016
1 parent 08d8de8 commit 7725d60
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib/child-wait.c
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down

0 comments on commit 7725d60

Please sign in to comment.