git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Alexander Sulfrian <alexander@sulfrian.net>
To: gitster@pobox.com, git@vger.kernel.org
Cc: Alexander Sulfrian <alexander@sulfrian.net>
Subject: [PATCHv3 2/2] daemon: allow more than one host address given via --listen
Date: Sun, 29 Aug 2010 17:13:16 +0200	[thread overview]
Message-ID: <1283094796-27984-3-git-send-email-alexander@sulfrian.net> (raw)
In-Reply-To: <1283094462-5184-1-git-send-email-alexander@sulfrian.net>

When the host has more than one interfaces, daemon can listen to all
of them by not giving any --listen option, or listen to only one.
Teach it to accept more than one --listen options.

Remove the hostname information form the die, if no socket could be
created. It would only trigger when no interface out of either all
interface or the ones specified on the command line with --listen
options, can be listened to and so the user does know which "host" was
asked.

Signed-off-by: Alexander Sulfrian <alexander@sulfrian.net>
---
 Documentation/git-daemon.txt |    1 +
 daemon.c                     |   33 ++++++++++++++++++++++++---------
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/Documentation/git-daemon.txt b/Documentation/git-daemon.txt
index 01c9f8e..4afd0a4 100644
--- a/Documentation/git-daemon.txt
+++ b/Documentation/git-daemon.txt
@@ -85,6 +85,7 @@ OPTIONS
 	be either an IPv4 address or an IPv6 address if supported.  If IPv6
 	is not supported, then --listen=hostname is also not supported and
 	--listen must be given an IPv4 address.
+	Can be given more than one time.
 	Incompatible with '--inetd' option.
 
 --port=n::
diff --git a/daemon.c b/daemon.c
index deda4cf..bd7574e 100644
--- a/daemon.c
+++ b/daemon.c
@@ -3,6 +3,7 @@
 #include "exec_cmd.h"
 #include "run-command.h"
 #include "strbuf.h"
+#include "string-list.h"
 
 #include <syslog.h>
 
@@ -861,11 +862,20 @@ static int setup_named_sock(char *listen_addr, int listen_port, int **socklist_p
 
 #endif
 
-static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
+static int socksetup(struct string_list *listen_addr, int listen_port, int **socklist_p)
 {
 	int socknum = 0, *socklist = NULL;
 
-	socknum = setup_named_sock(listen_addr, listen_port, &socklist, socknum);
+	if (!listen_addr->nr)
+		socknum = setup_named_sock(NULL, listen_port, &socklist,
+					   socknum);
+	else {
+		int i;
+		for (i = 0; i < listen_addr->nr; i++)
+			socknum = setup_named_sock(listen_addr->items[i].string,
+						   listen_port, &socklist,
+						   socknum);
+	}
 
 	*socklist_p = socklist;
 	return socknum;
@@ -959,14 +969,14 @@ static void store_pid(const char *path)
 		die_errno("failed to write pid file '%s'", path);
 }
 
-static int serve(char *listen_addr, int listen_port, struct passwd *pass, gid_t gid)
+static int serve(struct string_list *listen_addr, int listen_port, struct passwd *pass, gid_t gid)
 {
 	int socknum, *socklist;
 
 	socknum = socksetup(listen_addr, listen_port, &socklist);
 	if (socknum == 0)
-		die("unable to allocate any listen sockets on host %s port %u",
-		    listen_addr, listen_port);
+		die("unable to allocate any listen sockets on port %u",
+		    listen_port);
 
 	if (pass && gid &&
 	    (initgroups(pass->pw_name, gid) || setgid (gid) ||
@@ -979,7 +989,7 @@ static int serve(char *listen_addr, int listen_port, struct passwd *pass, gid_t
 int main(int argc, char **argv)
 {
 	int listen_port = 0;
-	char *listen_addr = NULL;
+	struct string_list listen_addr = STRING_LIST_INIT_NODUP;
 	int inetd_mode = 0;
 	const char *pid_file = NULL, *user_name = NULL, *group_name = NULL;
 	int detach = 0;
@@ -987,6 +997,7 @@ int main(int argc, char **argv)
 	struct group *group;
 	gid_t gid = 0;
 	int i;
+	int return_value;
 
 	git_extract_argv0_path(argv[0]);
 
@@ -994,7 +1005,7 @@ int main(int argc, char **argv)
 		char *arg = argv[i];
 
 		if (!prefixcmp(arg, "--listen=")) {
-			listen_addr = xstrdup_tolower(arg + 9);
+			string_list_append(&listen_addr, xstrdup_tolower(arg + 9));
 			continue;
 		}
 		if (!prefixcmp(arg, "--port=")) {
@@ -1119,7 +1130,7 @@ int main(int argc, char **argv)
 	if (inetd_mode && (group_name || user_name))
 		die("--user and --group are incompatible with --inetd");
 
-	if (inetd_mode && (listen_port || listen_addr))
+	if (inetd_mode && (listen_port || (listen_addr.nr > 0)))
 		die("--listen= and --port= are incompatible with --inetd");
 	else if (listen_port == 0)
 		listen_port = DEFAULT_GIT_PORT;
@@ -1174,5 +1185,9 @@ int main(int argc, char **argv)
 	if (pid_file)
 		store_pid(pid_file);
 
-	return serve(listen_addr, listen_port, pass, gid);
+	return_value = serve(&listen_addr, listen_port, pass, gid);
+
+	string_list_clear(&listen_addr, 0);
+
+	return return_value;
 }
-- 
1.7.1

  parent reply	other threads:[~2010-08-29 15:13 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-23 16:54 added possibility to supply more than one --listen argument to git-daemon Alexander Sulfrian
2010-08-23 16:54 ` [PATCH] " Alexander Sulfrian
2010-08-23 19:56   ` Junio C Hamano
2010-08-29 15:07     ` daemon: allow more than one host addresses given via --listen Alexander Sulfrian
2010-08-29 15:13       ` Alexander Sulfrian
2010-08-29 15:13       ` [PATCHv3 1/2] daemon: add helper function named_sock_setup Alexander Sulfrian
2010-08-29 15:13       ` Alexander Sulfrian [this message]
2010-08-30  7:28         ` [PATCHv3 2/2] daemon: allow more than one host address given via --listen Junio C Hamano
2010-08-30 11:30           ` Alexander Sulfrian
2010-08-30 11:30           ` [PATCHv4 1/2] daemon: add helper function named_sock_setup Alexander Sulfrian
2010-08-30 12:12             ` Erik Faye-Lund
2010-08-30 12:46               ` AlexanderS
2010-08-30 12:58                 ` Erik Faye-Lund
2010-08-30 11:30           ` [PATCHv4 2/2] daemon: allow more than one host address given via --listen Alexander Sulfrian
2010-08-29 15:07     ` [PATCHv2 1/2] daemon: add helper function named_sock_setup Alexander Sulfrian
2010-08-29 15:07     ` [PATCHv2 2/2] daemon: allow more than one host address given via --listen Alexander Sulfrian
2010-08-29 15:11       ` Erik Faye-Lund
2010-08-29 15:17         ` AlexanderS

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1283094796-27984-3-git-send-email-alexander@sulfrian.net \
    --to=alexander@sulfrian.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).