Skip to content

Commit d80b764

Browse files
committed
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)
2 parents fe02fe7 + d83e1ee commit d80b764

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

compat/mingw-posix.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ struct sigaction {
9696
unsigned sa_flags;
9797
};
9898
#define SA_RESTART 0
99+
#define SA_NOCLDSTOP 1
99100

100101
struct itimerval {
101102
struct timeval it_value, it_interval;

compat/mingw.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2561,7 +2561,9 @@ int setitimer(int type UNUSED, struct itimerval *in, struct itimerval *out)
25612561

25622562
int sigaction(int sig, struct sigaction *in, struct sigaction *out)
25632563
{
2564-
if (sig != SIGALRM)
2564+
if (sig == SIGCHLD)
2565+
return -1;
2566+
else if (sig != SIGALRM)
25652567
return errno = EINVAL,
25662568
error("sigaction only implemented for SIGALRM");
25672569
if (out)

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)
@@ -1115,6 +1113,7 @@ static void socksetup(struct string_list *listen_addr, int listen_port, struct s
11151113

11161114
static int service_loop(struct socketlist *socklist)
11171115
{
1116+
struct sigaction sa;
11181117
struct pollfd *pfd;
11191118

11201119
CALLOC_ARRAY(pfd, socklist->nr);
@@ -1124,7 +1123,10 @@ static int service_loop(struct socketlist *socklist)
11241123
pfd[i].events = POLLIN;
11251124
}
11261125

1127-
signal(SIGCHLD, child_handler);
1126+
sigemptyset(&sa.sa_mask);
1127+
sa.sa_flags = SA_NOCLDSTOP;
1128+
sa.sa_handler = child_handler;
1129+
sigaction(SIGCHLD, &sa, NULL);
11281130

11291131
for (;;) {
11301132
check_dead_children();

0 commit comments

Comments
 (0)