git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
AJAlexandre Julliard <julliard@winehq.org>
Date
Feb 14, 2007, 17:10 UTC
Message-ID
<87d54c8y2l.fsf@wine.dyndns.org>

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

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
---
 daemon.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/daemon.c b/daemon.c
index 2a20ca5..66f8d6f 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;
-- 
1.5.0.7.g2fa71

-- 
Alexandre Julliard
julliard@winehq.org
Message 1 of 1 in “git-daemon: Avoid leaking the listening sockets into child processes.”
  1. git-daemon: Avoid leaking the listening sockets into child processes.Alexandre Julliard, Feb 14, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.