From: Mark Wooding <mdw@distorted.org.uk>
To: git@vger.kernel.org
Subject: [PATCH 2/3] daemon: Set SO_REUSEADDR on listening sockets.
Date: Fri, 03 Feb 2006 20:27:04 +0000 [thread overview]
Message-ID: <20060203202704.1895.18383.stgit@metalzone.distorted.org.uk> (raw)
In-Reply-To: <20060203202330.1895.60474.stgit@metalzone.distorted.org.uk>
From: Mark Wooding <mdw@distorted.org.uk>
Without this, you can silently lose the ability to receive IPv4
connections if you stop and restart the daemon.
Signed-off-by: Mark Wooding <mdw@distorted.org.uk>
---
daemon.c | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/daemon.c b/daemon.c
index 532bb0c..6b88c0c 100644
--- a/daemon.c
+++ b/daemon.c
@@ -454,6 +454,7 @@ static int socksetup(int port, int **soc
int socknum = 0, *socklist = NULL;
int maxfd = -1;
char pbuf[NI_MAXSERV];
+ int yes = 1;
struct addrinfo hints, *ai0, *ai;
int gai;
@@ -491,6 +492,12 @@ static int socksetup(int port, int **soc
}
#endif
+ if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
+ &yes, sizeof(yes))) {
+ close(sockfd);
+ return 0; /* not fatal */
+ }
+
if (bind(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) {
close(sockfd);
continue; /* not fatal */
@@ -523,6 +530,7 @@ static int socksetup(int port, int **soc
{
struct sockaddr_in sin;
int sockfd;
+ int yes = 1;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
@@ -533,6 +541,12 @@ static int socksetup(int port, int **soc
sin.sin_addr.s_addr = htonl(INADDR_ANY);
sin.sin_port = htons(port);
+ if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
+ &yes, sizeof(yes))) {
+ close(sockfd);
+ return 0;
+ }
+
if ( bind(sockfd, (struct sockaddr *)&sin, sizeof sin) < 0 ) {
close(sockfd);
return 0;
next prev parent reply other threads:[~2006-02-03 20:27 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-03 20:23 [PATCH 0/3] git-daemon hacking Mark Wooding
2006-02-03 20:27 ` [PATCH 1/3] daemon: Provide missing argument for logerror() call Mark Wooding
2006-02-03 20:27 ` Mark Wooding [this message]
2006-02-03 20:57 ` [PATCH 2/3] daemon: Set SO_REUSEADDR on listening sockets Junio C Hamano
2006-02-04 8:49 ` Junio C Hamano
2006-02-04 10:16 ` Mark Wooding
2006-02-03 20:27 ` [PATCH 3/3] daemon: Support a --user-path option Mark Wooding
2006-02-03 20:52 ` Junio C Hamano
2006-02-04 8:50 ` Junio C Hamano
2006-02-04 10:02 ` Mark Wooding
2006-02-04 12:40 ` Junio C Hamano
2006-02-04 19:13 ` Mark Wooding
2006-02-04 22:02 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060203202704.1895.18383.stgit@metalzone.distorted.org.uk \
--to=mdw@distorted.org.uk \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).