21 #ifdef HAVE_SYS_WAIT_H
39 void (*userfn)(int,
void *userdata);
45 static inline unsigned int
48 return (
unsigned) ent->pid;
51 static inline unsigned int
55 return a->pid == b->pid;
61 process_map_entries_eq_);
74 set_waitpid_callback(pid_t pid,
void (*fn)(
int,
void *),
void *arg)
83 old_ent = HT_REPLACE(process_map, &process_map, ent);
85 log_warn(
LD_BUG,
"Replaced a waitpid monitor on pid %u. That should be "
86 "impossible.", (
unsigned) pid);
105 old_ent = HT_REMOVE(process_map, &process_map, ent);
106 if (old_ent != ent) {
107 log_warn(
LD_BUG,
"Couldn't remove waitpid monitor for pid %u.",
108 (
unsigned) ent->pid);
124 ent = HT_REMOVE(process_map, &process_map, &search);
125 if (!ent || !ent->running) {
126 log_info(
LD_GENERAL,
"Child process %u has exited; no callback was "
127 "registered", (
unsigned)pid);
131 log_info(
LD_GENERAL,
"Child process %u has exited; running callback.",
135 ent->userfn(status, ent->userdata);
148 while ((child = waitpid(-1, &status, WNOHANG)) > 0) {