]> git.ipfire.org Git - thirdparty/git.git/commitdiff
daemon: use sigaction() to install child_handler()
authorCarlo Marcelo Arenas Belón <carenas@gmail.com>
Thu, 10 Jul 2025 19:45:43 +0000 (19:45 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 10 Jul 2025 21:19:57 +0000 (14:19 -0700)
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>
daemon.c

index d1be61fd578949385c94e590ca3b7ba7c09048d2..28fc19479038608a9d7c1b21b15549a3ce814452 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -915,11 +915,9 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen)
 static void child_handler(int signo UNUSED)
 {
        /*
-        * Otherwise empty handler because systemcalls will get interrupted
-        * upon signal receipt
-        * SysV needs the handler to be rearmed
+        * Otherwise empty handler because systemcalls should get interrupted
+        * upon signal receipt.
         */
-       signal(SIGCHLD, child_handler);
 }
 
 static int set_reuse_addr(int sockfd)
@@ -1120,6 +1118,7 @@ static void socksetup(struct string_list *listen_addr, int listen_port, struct s
 
 static int service_loop(struct socketlist *socklist)
 {
+       struct sigaction sa;
        struct pollfd *pfd;
 
        CALLOC_ARRAY(pfd, socklist->nr);
@@ -1129,7 +1128,10 @@ static int service_loop(struct socketlist *socklist)
                pfd[i].events = POLLIN;
        }
 
-       signal(SIGCHLD, child_handler);
+       sigemptyset(&sa.sa_mask);
+       sa.sa_flags = SA_NOCLDSTOP;
+       sa.sa_handler = child_handler;
+       sigaction(SIGCHLD, &sa, NULL);
 
        for (;;) {
                check_dead_children();