Skip to content

Commit

Permalink
git-daemon: Avoid leaking the listening sockets into child processes.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Alexandre Julliard authored and Junio C Hamano committed Feb 14, 2007
1 parent 958545c commit 2027688
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2027688

Please sign in to comment.