Skip to content

Commit bc91b4b

Browse files
carenasgitster
authored andcommitted
daemon: explicitly allow EINTR during poll()
If the setup for the SIGCHLD signal handler sets SA_RESTART, poll() might not return with -1 and set errno to EINTR when a signal is received. Since the logic to reap zombie childs relies on those interruptions make sure to explicitly disable SA_RESTART around this function. Signed-off-by: Carlo Marcelo Arenas Belón <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 298caa6 commit bc91b4b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

daemon.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,13 +1133,28 @@ static void set_signal_handler(struct sigaction *psa)
11331133
sigaction(SIGCHLD, psa, NULL);
11341134
}
11351135

1136+
static void set_sa_restart(struct sigaction *psa, int enable)
1137+
{
1138+
if (enable)
1139+
psa->sa_flags |= SA_RESTART;
1140+
else
1141+
psa->sa_flags &= ~SA_RESTART;
1142+
sigaction(SIGCHLD, psa, NULL);
1143+
}
1144+
11361145
#else
11371146

11381147
static void set_signal_handler(struct sigaction *psa UNUSED)
11391148
{
11401149
signal(SIGCHLD, child_handler);
11411150
}
11421151

1152+
static void set_sa_restart(struct sigaction *psa UNUSED, int enable UNUSED)
1153+
{
1154+
}
1155+
1156+
#endif
1157+
11431158
static int service_loop(struct socketlist *socklist)
11441159
{
11451160
struct sigaction sa;
@@ -1157,6 +1172,7 @@ static int service_loop(struct socketlist *socklist)
11571172
for (;;) {
11581173
check_dead_children();
11591174

1175+
set_sa_restart(&sa, 0);
11601176
if (poll(pfd, socklist->nr, -1) < 0) {
11611177
if (errno != EINTR) {
11621178
logerror("Poll failed, resuming: %s",
@@ -1165,6 +1181,7 @@ static int service_loop(struct socketlist *socklist)
11651181
}
11661182
continue;
11671183
}
1184+
set_sa_restart(&sa, 1);
11681185

11691186
for (size_t i = 0; i < socklist->nr; i++) {
11701187
if (pfd[i].revents & POLLIN) {

0 commit comments

Comments
 (0)