Merge branch 'cb/daemon-reap-children'

Futz with SIGCHLD handling in "git daemon".

* cb/daemon-reap-children:
  daemon: use sigaction() to install child_handler()
  compat/mingw: allow sigaction(SIGCHLD)
This commit is contained in:
Junio C Hamano
2025-07-21 09:14:28 -07:00
3 changed files with 11 additions and 6 deletions

View File

@@ -96,6 +96,7 @@ struct sigaction {
unsigned sa_flags;
};
#define SA_RESTART 0
#define SA_NOCLDSTOP 1
struct itimerval {
struct timeval it_value, it_interval;

View File

@@ -2561,7 +2561,9 @@ int setitimer(int type UNUSED, struct itimerval *in, struct itimerval *out)
int sigaction(int sig, struct sigaction *in, struct sigaction *out)
{
if (sig != SIGALRM)
if (sig == SIGCHLD)
return -1;
else if (sig != SIGALRM)
return errno = EINVAL,
error("sigaction only implemented for SIGALRM");
if (out)

View File

@@ -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)
@@ -1115,6 +1113,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);
@@ -1124,7 +1123,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();