static unsigned int reap_dead_kids(void) { unsigned int i; unsigned int alive = 0; unsigned int reaped = 0; for_each_child(i) { struct childdata *child; pid_t pid; int ret; child = shm->children[i]; pid = child->pid; if (pid == EMPTY_PIDSLOT) continue; if (pid_is_valid(pid) == FALSE) { static bool once = FALSE; if (once != FALSE) return 0; output(0, "Sanity check failed! Found pid %u at pidslot %u!\n", pid, i); dump_childnos(); if (shm->exit_reason == STILL_RUNNING) panic(EXIT_PID_OUT_OF_RANGE); dump_childdata(child); once = TRUE; return 0; } ret = kill(pid, 0); /* If it disappeared, reap it. */ if (ret == -1) { if (errno == ESRCH) { output(0, "pid %u has disappeared. Reaping.\n", pid); reap_child(pid); reaped++; } else { output(0, "problem checking on pid %u (%d:%s)\n", pid, errno, strerror(errno)); } } else { alive++; } if (shm->running_childs == 0) return 0; } if (reaped != 0) output(0, "Reaped %d dead children\n", reaped); return alive; }
/* * Make sure various entries in the shm look sensible. * We use this to make sure that random syscalls haven't corrupted it. * * also check the pids for sanity. */ static int shm_is_corrupt(void) { unsigned int i; // FIXME: The '500000' is magic, and should be dynamically calculated. // On startup, we should figure out how many getpid()'s per second we can do, // and use that. if (shm->stats.total_syscalls_done - shm->stats.previous_op_count > 500000) { output(0, "Execcount increased dramatically! (old:%ld new:%ld):\n", shm->stats.previous_op_count, shm->stats.total_syscalls_done); panic(EXIT_SHM_CORRUPTION); return TRUE; } shm->stats.previous_op_count = shm->stats.total_syscalls_done; for_each_child(i) { struct childdata *child; pid_t pid; child = shm->children[i]; pid = child->pid; if (pid == EMPTY_PIDSLOT) continue; if (pid_is_valid(pid) == FALSE) { static bool once = FALSE; if (once != FALSE) return TRUE; output(0, "Sanity check failed! Found pid %u at pidslot %u!\n", pid, i); dump_childnos(); if (shm->exit_reason == STILL_RUNNING) panic(EXIT_PID_OUT_OF_RANGE); dump_childdata(child); once = TRUE; return TRUE; } } return FALSE; }
/* * Make sure various entries in the shm look sensible. * We use this to make sure that random syscalls haven't corrupted it. * * also check the pids for sanity. */ static int shm_is_corrupt(void) { unsigned int i; if (shm->stats.op_count < shm->stats.previous_op_count) { output(0, "Execcount went backwards! (old:%ld new:%ld):\n", shm->stats.previous_op_count, shm->stats.op_count); panic(EXIT_SHM_CORRUPTION); return TRUE; } shm->stats.previous_op_count = shm->stats.op_count; for_each_child(i) { struct childdata *child; pid_t pid; child = shm->children[i]; pid = pids[i]; if (pid == EMPTY_PIDSLOT) continue; if (pid_is_valid(pid) == FALSE) { static bool once = FALSE; if (once != FALSE) return TRUE; output(0, "Sanity check failed! Found pid %u at pidslot %u!\n", pid, i); dump_childnos(); if (shm->exit_reason == STILL_RUNNING) panic(EXIT_PID_OUT_OF_RANGE); dump_childdata(child); once = TRUE; return TRUE; } } return FALSE; }