Skip to content

Commit

Permalink
fixup 51602f5
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonVrouwe committed Nov 15, 2021
1 parent 17c36f2 commit e634855
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lightningd/lightningd.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,12 +782,22 @@ static struct io_plan *sigchld_rfd_in(struct io_conn *conn,
static u8 ignorebuf;
static size_t len;
pid_t pid;

/* Reap any terminated child we can; for the rest we ignore these */
while ((pid = waitpid(-1, 0, WNOHANG)) != 0)
/* No child processes: this causes a hang sometimes, so break that */
if (pid == -1 && errno == ECHILD)
int status;

/* Reap any terminated child we can; for the rest we ignore these.
* This elaborate while loop appears to solve a rare hang issue in the
* case all children are gone (somehow ?). */
while (true) {
pid = waitpid(-1, &status, WNOHANG);
if (pid == 0)
break;
if (pid == -1){
log_debug(ld->log, "waitpid returned -1: errno %s",
strerror(errno));
break;
} else
log_unusual(ld->log, "reaped child pid %i", pid);
}

return io_read_partial(conn, &ignorebuf, 1, &len, sigchld_rfd_in, ld);
}
Expand Down

0 comments on commit e634855

Please sign in to comment.