Skip to content

Commit

Permalink
sigchld_handler_service: Iterate over all service children
Browse files Browse the repository at this point in the history
If more than one service child is killed,
the SIGCHLD signals can be coalesced, causing service
to miss worker exit and perform clean-up
  • Loading branch information
adrianM27 committed Jul 4, 2024
1 parent b167917 commit e93699f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions memcr.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ static void clear_pid_on_worker_exit_non_blocking(pid_t worker)
{
for (int i=0; i<CHECKPOINTED_PIDS_LIMIT; ++i) {
if (checkpoint_service_data[i].worker == worker) {
fprintf(stdout, "[+] Clearing pid: %d with worker: %d ...\n",
fprintf(stdout, "[+] Clearing pid: %d with worker: %d on worker exit ...\n",
checkpoint_service_data[i].pid, worker);
cleanup_pid(checkpoint_service_data[i].pid);
checkpoint_service_data[i].pid = PID_INVALID;
Expand Down Expand Up @@ -2248,12 +2248,13 @@ static void sigchld_handler_service(int sig, siginfo_t *sip, void *notused)
{
int status;
int _errno;
pid_t pid;

_errno = errno;
if (sip->si_pid == waitpid(sip->si_pid, &status, WNOHANG)) {
fprintf(stdout, "[+] Worker %d exit.\n", sip->si_pid);
clear_pid_on_worker_exit_non_blocking(sip->si_pid);
while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
clear_pid_on_worker_exit_non_blocking(pid);
}

errno = _errno;
}

Expand Down

0 comments on commit e93699f

Please sign in to comment.