git-daemon: Avoid leaking the listening sockets into child processes.

This makes it possible to restart git-daemon even if some children are
still running.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
maint
Alexandre Julliard 2007-02-14 18:10:26 +01:00 committed by Junio C Hamano
parent 958545c5a1
commit 20276889d6
1 changed files with 10 additions and 0 deletions

View File

@ -773,6 +773,7 @@ static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
char pbuf[NI_MAXSERV]; char pbuf[NI_MAXSERV];
struct addrinfo hints, *ai0, *ai; struct addrinfo hints, *ai0, *ai;
int gai; int gai;
long flags;


sprintf(pbuf, "%d", listen_port); sprintf(pbuf, "%d", listen_port);
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
@ -820,6 +821,10 @@ static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
continue; /* not fatal */ continue; /* not fatal */
} }


flags = fcntl(sockfd, F_GETFD, 0);
if (flags >= 0)
fcntl(sockfd, F_SETFD, flags | FD_CLOEXEC);

socklist = xrealloc(socklist, sizeof(int) * (socknum + 1)); socklist = xrealloc(socklist, sizeof(int) * (socknum + 1));
socklist[socknum++] = sockfd; socklist[socknum++] = sockfd;


@ -839,6 +844,7 @@ static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
{ {
struct sockaddr_in sin; struct sockaddr_in sin;
int sockfd; int sockfd;
long flags;


memset(&sin, 0, sizeof sin); memset(&sin, 0, sizeof sin);
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
@ -871,6 +877,10 @@ static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
return 0; return 0;
} }


flags = fcntl(sockfd, F_GETFD, 0);
if (flags >= 0)
fcntl(sockfd, F_SETFD, flags | FD_CLOEXEC);

*socklist_p = xmalloc(sizeof(int)); *socklist_p = xmalloc(sizeof(int));
**socklist_p = sockfd; **socklist_p = sockfd;
return 1; return 1;