Skip to content

Commit d83e1ee

Browse files
carenasgitster
authored andcommitted
daemon: use sigaction() to install child_handler()
Replace signal() with an equivalent invocation of sigaction(), but make sure to NOT set SA_RESTART so the original code that expects to be interrupted when children complete still works as designed. This change has the added benefit of using BSD signal semantics reliably and therefore not needing the rearming call in the signal handler. Signed-off-by: Carlo Marcelo Arenas Belón <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ef03aa4 commit d83e1ee

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

daemon.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -915,11 +915,9 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
915915
static void child_handler(int signo UNUSED)
916916
{
917917
/*
918-
* Otherwise empty handler because systemcalls will get interrupted
919-
* upon signal receipt
920-
* SysV needs the handler to be rearmed
918+
* Otherwise empty handler because systemcalls should get interrupted
919+
* upon signal receipt.
921920
*/
922-
signal(SIGCHLD, child_handler);
923921
}
924922

925923
static int set_reuse_addr(int sockfd)
@@ -1120,6 +1118,7 @@ static void socksetup(struct string_list *listen_addr, int listen_port, struct s
11201118

11211119
static int service_loop(struct socketlist *socklist)
11221120
{
1121+
struct sigaction sa;
11231122
struct pollfd *pfd;
11241123

11251124
CALLOC_ARRAY(pfd, socklist->nr);
@@ -1129,7 +1128,10 @@ static int service_loop(struct socketlist *socklist)
11291128
pfd[i].events = POLLIN;
11301129
}
11311130

1132-
signal(SIGCHLD, child_handler);
1131+
sigemptyset(&sa.sa_mask);
1132+
sa.sa_flags = SA_NOCLDSTOP;
1133+
sa.sa_handler = child_handler;
1134+
sigaction(SIGCHLD, &sa, NULL);
11331135

11341136
for (;;) {
11351137
check_dead_children();

0 commit comments

Comments
 (0)