child-wait.c revision 1c7fa51b35231f375998f66d5756f214519218f8
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny/* Copyright (c) 2007-2009 Dovecot authors, see the included COPYING file */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny unsigned int pid_count;
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenychild_wait_new_with_pid(pid_t pid, child_wait_callback_t *callback,
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny /* this should be rare, so iterating hash is fast enough */
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenyvoid child_wait_add_pid(struct child_wait *wait, pid_t pid)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny hash_table_insert(child_pids, POINTER_CAST(pid), wait);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenyvoid child_wait_remove_pid(struct child_wait *wait, pid_t pid)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny hash_table_remove(child_pids, POINTER_CAST(pid));
f26c954658dfd7461f290f0b5d924951a6db219aJan Zelenysigchld_handler(const siginfo_t *si ATTR_UNUSED, void *context ATTR_UNUSED)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny while ((status.pid = waitpid(-1, &status.status, WNOHANG)) > 0) {
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny status.wait->callback(&status, status.wait->context);
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny if (status.pid == -1 && errno != EINTR && errno != ECHILD)
f26c954658dfd7461f290f0b5d924951a6db219aJan Zeleny child_pids = hash_table_create(default_pool, default_pool, 0,
684d1b48b5582a1bf7812b8c3c663592dc6dfed9Pavel Březina lib_signals_set_handler(SIGCHLD, TRUE, sigchld_handler, NULL);