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>
Alexandre Julliard committed
Feb 14, 2007 at 18:10 UTC
20276889d6610d87c17b058ac0c49601ed950e61
1 file changed
+10
daemon.c
+10
@@ -773,6 +773,7 @@ static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
773
char pbuf[NI_MAXSERV];
774
struct addrinfo hints, *ai0, *ai;
775
int gai;
776
+ long flags;
777
778
sprintf(pbuf, "%d", listen_port);
779
memset(&hints, 0, sizeof(hints));
@@ -820,6 +821,10 @@ static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
821
continue; /* not fatal */
822
}
823
824
+ flags = fcntl(sockfd, F_GETFD, 0);
825
+ if (flags >= 0)
826
+ fcntl(sockfd, F_SETFD, flags | FD_CLOEXEC);
827
+
828
socklist = xrealloc(socklist, sizeof(int) * (socknum + 1));
829
socklist[socknum++] = sockfd;
830
@@ -839,6 +844,7 @@ static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
844
{
845
struct sockaddr_in sin;
846
int sockfd;
847
+ long flags;
848
849
memset(&sin, 0, sizeof sin);
850
sin.sin_family = AF_INET;
@@ -871,6 +877,10 @@ static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
877
return 0;
878
}
879
880
+ flags = fcntl(sockfd, F_GETFD, 0);
881
+ if (flags >= 0)
882
+ fcntl(sockfd, F_SETFD, flags | FD_CLOEXEC);
883
+
884
*socklist_p = xmalloc(sizeof(int));
885
**socklist_p = sockfd;
886
return 1;