git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Alexander Sulfrian <alexander@sulfrian.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] added possibility to supply more than one --listen argument to git-daemon
Date: Mon, 23 Aug 2010 12:56:06 -0700	[thread overview]
Message-ID: <7v4oel14tl.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <1282582475-3545-2-git-send-email-alexander@sulfrian.net> (Alexander Sulfrian's message of "Mon\, 23 Aug 2010 18\:54\:35 +0200")

Alexander Sulfrian <alexander@sulfrian.net> writes:

> --listen arguments are gathered in a string_list
> serve and socksetup get listen_addr as string_list
> socketsetup creates a listen socket for each host in that string_list
>
> Signed-off-by: Alexander Sulfrian <alexander@sulfrian.net>
> ---

Thanks for a resend/reminder.  I've been meaning to look at this patch
after somebody who actually runs the daemon commented on it.

A few administravia:

 - Please begin the subject line with affected-area and a colon;

 - Please place more stress on what problem the patch tries to solve and
   less on how the patch solves it, because the latter can be read from
   the patch text itself, when writing a proposed log message;

 - We tend to write the log message in imperative mood, to order either the
   person who applies the patch or the codebase what new things to do.

 - We need to also update the documentation (e.g. just add "Can be given
   more than one times" before "Incompatible with '--inetd' option." in
   Documentation/git-daemon.txt).

So...

    Subject: [PATCH] daemon: allow more than one host addresses given via --listen

    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.

    Signed-off-by: ...

>  daemon.c |  183 ++++++++++++++++++++++++++++++++++++--------------------------
>  1 files changed, 107 insertions(+), 76 deletions(-)
>
> diff --git a/daemon.c b/daemon.c
> index e22a2b7..f4492fe 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>
>  
> @@ -736,7 +737,7 @@ static int set_reuse_addr(int sockfd)
>  
>  #ifndef NO_IPV6
>  
> -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;
>  	int maxfd = -1;
> @@ -744,6 +745,7 @@ static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
>  	struct addrinfo hints, *ai0, *ai;
>  	int gai;
>  	long flags;
> +	int i;
>  
>  	sprintf(pbuf, "%d", listen_port);
>  	memset(&hints, 0, sizeof(hints));
> @@ -752,57 +754,69 @@ static int socksetup(char *listen_addr, int listen_port, int **socklist_p)
>  	hints.ai_protocol = IPPROTO_TCP;
>  	hints.ai_flags = AI_PASSIVE;
>  
> -	gai = getaddrinfo(listen_addr, pbuf, &hints, &ai0);
> -	if (gai)
> -		die("getaddrinfo() failed: %s", gai_strerror(gai));
> +	i = 0;
> +	do {
> +		if (listen_addr->nr > 0) {
> +			gai = getaddrinfo(listen_addr->items[i].string, pbuf,
> +					  &hints, &ai0);
> +		}
> +		else {
> +			gai = getaddrinfo(NULL, pbuf, &hints, &ai0);
> +		}

Style: neither of these if/else body need braces around it.

But more importantly, wouldn't it make the patch and the result easier to
read if you split the part of the code that now is one iteration of the
loop over listen_addr list into a separate helper function?

Then socksetup would look something like:

        static int socksetup(...)
        {
		...
		if (!listen_addr_list->nr)
		    	setup_named_sock(NULL, listen_port, socklist_p);
		else {
			int i;
			for (i = 0; i < listen_addr_list->nr; i++)
                        	setup_named_sock(listen_addr_list->items[i].string,
                                	listen_port, socklist_p);
                }
		...
    	}

If such a refactoring results in more readable code (I haven't tried doing
the refactoring myself, so I don't know if it is worth it), then I would
suggest making this into a two-patch series, one that creates the helper
function, and then another that adds multiple-listen support on top.

> @@ -946,14 +970,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);

Here we are losing "host" information; does it matter?

Earlier socksetup() died only when getaddrinfo died, as in that case we
know there won't be any socket prepared.  You removed that die (which is
sensible---as you may have one unavailable and another available interface
and dying only when there is no socket listening has been the design of
the program, and you are not changing that with this patch).

Also I have to wonder what would have happened in the original code if
there were no --listen given (presumably we got NULL in the argument in
that case).

My gut feeling is that this change is Ok, as this die() would trigger only
when no interface out of either all interface or the ones specified on the
command line with --listen options, can be listened to at the port, either
given by --listen_port option or the default 9418; and the user does know
which "host" was asked anyway.  But the change needs to be mentioned in
the proposed log message.

It might be an improvement if we reported addresses that cannot be
listened to (you can use listen_addr_list->items[i].util for that--- when
setup_named_sock() helper finds that no new socket was added by the loop
over the list resulting from getaddrinfo, it can mark the item's util
field, and then instead of dying the caller of socksetup() can warn on
such names.  If we were to do so, however, that should be done as a
separate patch on top of this change.

> @@ -966,14 +990,17 @@ 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;
>  	int inetd_mode = 0;
> +	struct string_list listen_addr;
>  	const char *pid_file = NULL, *user_name = NULL, *group_name = NULL;
>  	int detach = 0;
>  	struct passwd *pass = NULL;
>  	struct group *group;
>  	gid_t gid = 0;
>  	int i;
> +	int return_value;
> +
> +	memset(&listen_addr, 0, sizeof(struct string_list));

Don't we have STRING_LIST_INIT macro these days?

I also have to wonder if we eventually want to take --listen=host:port so
that you can listen only to two interfaces out of three avaiable on your
host, but on different ports.  Again, if we were to do so, however, that
should be done as a separate patch on top of this change.

Thanks.

  reply	other threads:[~2010-08-23 19:56 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 [this message]
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       ` [PATCHv3 2/2] daemon: allow more than one host address given via --listen Alexander Sulfrian
2010-08-30  7:28         ` 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=7v4oel14tl.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=alexander@sulfrian.net \
    --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.
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).