aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Julliard <julliard@winehq.org>2007-02-14 18:10:26 +0100
committerJunio C Hamano <junkio@cox.net>2007-02-14 10:25:41 -0800
commit20276889d6610d87c17b058ac0c49601ed950e61 (patch)
tree43f14891fa24f042f0014d3f5f6c0cd868a5cb4e
parent958545c5a11e5d6745e34df28abdd4a03a1f40fa (diff)
downloadgit-20276889d6610d87c17b058ac0c49601ed950e61.tar.gz
git-20276889d6610d87c17b058ac0c49601ed950e61.tar.xz
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>
-rw-r--r--daemon.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/daemon.c b/daemon.c
index 2a20ca55c..66f8d6f03 100644
--- a/daemon.c
+++ b/daemon.c
@@ -773,6 +773,7 @@ static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
char pbuf[NI_MAXSERV];
struct addrinfo hints, *ai0, *ai;
int gai;
+ long flags;
sprintf(pbuf, "%d", listen_port);
memset(&hints, 0, sizeof(hints));
@@ -820,6 +821,10 @@ static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
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[socknum++] = sockfd;
@@ -839,6 +844,7 @@ static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
{
struct sockaddr_in sin;
int sockfd;
+ long flags;
memset(&sin, 0, sizeof sin);
sin.sin_family = AF_INET;
@@ -871,6 +877,10 @@ static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
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 = sockfd;
return 1;