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 <carenas@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Carlo Marcelo Arenas Belón committed
Jul 10, 2025 at 19:45 UTC
d83e1eef3bbf8cd85ce5ffc4afff3fbdfb006fd1
1 file changed
+7
-5
daemon.c
+7
-5
@@ -915,11 +915,9 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
915
static void child_handler(int signo UNUSED)
916
{
917
/*
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.
920
*/
922
- signal(SIGCHLD, child_handler);
921
}
922
923
static int set_reuse_addr(int sockfd)
@@ -1120,6 +1118,7 @@ static void socksetup(struct string_list *listen_addr, int listen_port, struct s
1118
1119
static int service_loop(struct socketlist *socklist)
1120
{
1121
+ struct sigaction sa;
1122
struct pollfd *pfd;
1123
1124
CALLOC_ARRAY(pfd, socklist->nr);
@@ -1129,7 +1128,10 @@ static int service_loop(struct socketlist *socklist)
1128
pfd[i].events = POLLIN;
1129
}
1130
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);
1135
1136
for (;;) {
1137
check_dead_children();