git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] daemon: add --no-syslog to undo implicit --syslog
@ 2018-01-22 23:23 Lucas Werkmeister
  2018-01-23  0:00 ` Ævar Arnfjörð Bjarmason
  0 siblings, 1 reply; 21+ messages in thread
From: Lucas Werkmeister @ 2018-01-22 23:23 UTC (permalink / raw)
  To: git; +Cc: Lucas Werkmeister

Several options imply --syslog, without there being a way to disable it
again. This commit adds that option.

This is useful, for instance, when running `git daemon` as a systemd
service with --inetd. systemd connects stderr to the journal by default,
so logging to stderr is useful. On the other hand, log messages sent via
syslog also reach the journal eventually, but run the risk of being
processed at a time when the `git daemon` process has already exited
(especially if the process was very short-lived, e.g. due to client
error), so that the journal can no longer read its cgroup and attach the
message to the correct systemd unit. See systemd/systemd#2913 [1].

[1]: https://github.com/systemd/systemd/issues/2913

Signed-off-by: Lucas Werkmeister <mail@lucaswerkmeister.de>
---

Notes:
    I decided not to add the option to git-daemon's --help output, since
    the similar --no-informative-errors option is also not listed there.
    Let me know if it should be added.
    
    Feel free to remove the part about systemd from the commit message
    if you feel it doesn't need to be included.

 Documentation/git-daemon.txt | 6 ++++--
 daemon.c                     | 4 ++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-daemon.txt b/Documentation/git-daemon.txt
index 3c91db7be..dfd6ce03c 100644
--- a/Documentation/git-daemon.txt
+++ b/Documentation/git-daemon.txt
@@ -8,7 +8,7 @@ git-daemon - A really simple server for Git repositories
 SYNOPSIS
 --------
 [verse]
-'git daemon' [--verbose] [--syslog] [--export-all]
+'git daemon' [--verbose] [--[no-]syslog] [--export-all]
 	     [--timeout=<n>] [--init-timeout=<n>] [--max-connections=<n>]
 	     [--strict-paths] [--base-path=<path>] [--base-path-relaxed]
 	     [--user-path | --user-path=<path>]
@@ -109,9 +109,11 @@ OPTIONS
 	Maximum number of concurrent clients, defaults to 32.  Set it to
 	zero for no limit.
 
---syslog::
+--[no-]syslog::
 	Log to syslog instead of stderr. Note that this option does not imply
 	--verbose, thus by default only error conditions will be logged.
+	`--no-syslog` is the default, but may be given explicitly to override
+	the implicit `--syslog` of an earlier `--inetd` or `--detach` option.
 
 --user-path::
 --user-path=<path>::
diff --git a/daemon.c b/daemon.c
index e37e343d0..d59fef6d6 100644
--- a/daemon.c
+++ b/daemon.c
@@ -1300,6 +1300,10 @@ int cmd_main(int argc, const char **argv)
 			log_syslog = 1;
 			continue;
 		}
+		if (!strcmp(arg, "--no-syslog")) {
+			log_syslog = 0;
+			continue;
+		}
 		if (!strcmp(arg, "--export-all")) {
 			export_all_trees = 1;
 			continue;
-- 
2.16.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH] daemon: add --no-syslog to undo implicit --syslog
  2018-01-22 23:23 [PATCH] daemon: add --no-syslog to undo implicit --syslog Lucas Werkmeister
@ 2018-01-23  0:00 ` Ævar Arnfjörð Bjarmason
  2018-01-23 18:30   ` Junio C Hamano
  0 siblings, 1 reply; 21+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-01-23  0:00 UTC (permalink / raw)
  To: Lucas Werkmeister; +Cc: git


On Mon, Jan 22 2018, Lucas Werkmeister jotted:

> Several options imply --syslog, without there being a way to disable it
> again. This commit adds that option.

Just two options imply --syslog, --detach & --inetd, unless I've missed
something, anyway 2 != several, so maybe just say "The --detach and
--inetd options imply --syslog ...".

> This is useful, for instance, when running `git daemon` as a systemd
> service with --inetd. systemd connects stderr to the journal by default,
> so logging to stderr is useful. On the other hand, log messages sent via
> syslog also reach the journal eventually, but run the risk of being
> processed at a time when the `git daemon` process has already exited
> (especially if the process was very short-lived, e.g. due to client
> error), so that the journal can no longer read its cgroup and attach the
> message to the correct systemd unit. See systemd/systemd#2913 [1].
>
> [1]: https://github.com/systemd/systemd/issues/2913

This patch looks good, but I wonder if with the rise of systemd there's
a good reason to flip the default around to not having other stuff imply
--syslog, and have users specify this implictly, then we won't need a
--no-syslog option.

But maybe that'll break too much stuff.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH] daemon: add --no-syslog to undo implicit --syslog
  2018-01-23  0:00 ` Ævar Arnfjörð Bjarmason
@ 2018-01-23 18:30   ` Junio C Hamano
  2018-01-23 22:06     ` Lucas Werkmeister
  0 siblings, 1 reply; 21+ messages in thread
From: Junio C Hamano @ 2018-01-23 18:30 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: Lucas Werkmeister, git

Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> On Mon, Jan 22 2018, Lucas Werkmeister jotted:
>
>> Several options imply --syslog, without there being a way to disable it
>> again. This commit adds that option.
>
> Just two options imply --syslog, --detach & --inetd, unless I've missed
> something, anyway 2 != several, so maybe just say "The --detach and
> --inetd options imply --syslog ...".

Correct. Moreover, --detach completely dissociates the process from
the original set of standard file descriptors by first closing them
and then connecting it to "/dev/null", so it will be nonsense to use
this new option with it.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH] daemon: add --no-syslog to undo implicit --syslog
  2018-01-23 18:30   ` Junio C Hamano
@ 2018-01-23 22:06     ` Lucas Werkmeister
  2018-01-24 10:05       ` Lucas Werkmeister
  2018-01-24 18:33       ` Junio C Hamano
  0 siblings, 2 replies; 21+ messages in thread
From: Lucas Werkmeister @ 2018-01-23 22:06 UTC (permalink / raw)
  To: Junio C Hamano, Ævar Arnfjörð Bjarmason; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 1956 bytes --]

Thanks for your responses!

On 23.01.2018 01:00, Ævar Arnfjörð Bjarmason wrote:
> This patch looks good, but I wonder if with the rise of systemd
> there's a good reason to flip the default around to not having other
> stuff imply --syslog, and have users specify this implictly, then we
> won't need a --no-syslog option.
> 
> But maybe that'll break too much stuff.
> 

That seems risky to me – even with systemd, the StandardError directive
by default inherits StandardOutput, so if you set StandardOutput=socket
without StandardError=journal, log output in stderr clobbers regular
output. (Also, stderr is apparently closed with --detach, see below.)

On 23.01.2018 19:30, Junio C Hamano wrote:
> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> 
>> On Mon, Jan 22 2018, Lucas Werkmeister jotted:
>> 
>>> Several options imply --syslog, without there being a way to
>>> disable it again. This commit adds that option.
>> 
>> Just two options imply --syslog, --detach & --inetd, unless I've
>> missed something, anyway 2 != several, so maybe just say "The
>> --detach and --inetd options imply --syslog ...".
> 
> Correct.

I respectfully disagree on “2 != several”, but sure, I can repeat the
two options in the message instead :)

> Moreover, --detach completely dissociates the process from the
> original set of standard file descriptors by first closing them and
> then connecting it to "/dev/null", so it will be nonsense to use this
> new option with it.
> 

Ah, I wasn’t aware of that – so with --detach, --no-syslog would be
better described as “disables all logging” rather than “log to stderr
instead”. IMHO it would still make sense to have the --no-syslog option
(then mainly for use with --inetd) as long as its interaction with
--inetd is properly documented… do you agree? If yes, I’ll be glad to
submit another version of the patch.

Best regards,
Lucas


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4165 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH] daemon: add --no-syslog to undo implicit --syslog
  2018-01-23 22:06     ` Lucas Werkmeister
@ 2018-01-24 10:05       ` Lucas Werkmeister
  2018-01-24 18:33       ` Junio C Hamano
  1 sibling, 0 replies; 21+ messages in thread
From: Lucas Werkmeister @ 2018-01-24 10:05 UTC (permalink / raw)
  To: Junio C Hamano, Ævar Arnfjörð Bjarmason; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 932 bytes --]

On 23.01.2018 23:06, Lucas Werkmeister wrote:
> Ah, I wasn’t aware of that – so with --detach, --no-syslog would be
> better described as “disables all logging” rather than “log to stderr
> instead”. IMHO it would still make sense to have the --no-syslog option
> (then mainly for use with --inetd) as long as its interaction with
> --inetd is properly documented… do you agree? If yes, I’ll be glad to
> submit another version of the patch.

One alternative idea would be to instead make syslog and stderr logging
orthogonal by adding not just --no-syslog, but also --[no-]stderr. For
backwards compatibility, --syslog would imply --no-stderr, but you could
also enable logging to both channels with --syslog --stderr, or disable
all logging with --no-syslog --no-stderr. But that doesn’t really solve
the interaction with --detach – --detach --stderr would still be a
nonsensical combination.


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4165 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH] daemon: add --no-syslog to undo implicit --syslog
  2018-01-23 22:06     ` Lucas Werkmeister
  2018-01-24 10:05       ` Lucas Werkmeister
@ 2018-01-24 18:33       ` Junio C Hamano
  2018-01-24 19:48         ` Lucas Werkmeister
  2018-01-27 18:31         ` [PATCH v2] daemon: add --send-log-to=(stderr|syslog|none) Lucas Werkmeister
  1 sibling, 2 replies; 21+ messages in thread
From: Junio C Hamano @ 2018-01-24 18:33 UTC (permalink / raw)
  To: Lucas Werkmeister; +Cc: Ævar Arnfjörð Bjarmason, git

Lucas Werkmeister <mail@lucaswerkmeister.de> writes:

>> Moreover, --detach completely dissociates the process from the
>> original set of standard file descriptors by first closing them and
>> then connecting it to "/dev/null", so it will be nonsense to use this
>> new option with it.
>
> Ah, I wasn’t aware of that – so with --detach, --no-syslog would be
> better described as “disables all logging” rather than “log to stderr
> instead”. IMHO it would still make sense to have the --no-syslog option
> (then mainly for use with --inetd) as long as its interaction with
> --inetd is properly documented.

Because "--detach --no-syslog" is a roundabout way to ask for
sending the log to _nowhere_, I actually would say that "nonsense"
is a bit too strong a word for the combination of your thing with
"--detach".

It might make more sense to introduce a new "--send-log-to=<dest>"
option, where the destination can be one of: syslog, stderr, none.

The you can make the current "--syslog" option a synonym to
"--send-log-to=syslog".  The internal variable log_syslog would
probably become

	enum log_destination { 
		LOG_TO_NONE = -1,
		LOG_TO_STDERR = 0,
		LOG_TO_SYSLOG = 1,
	} log_destination;

and wherever the current code assigns 1 to log_syslog, you would be
setting it LOG_TO_SYSLOG.

Then those who want no log can express that wish in a more direct
way, i.e. "daemon --send-log-to=none", perhaps.

Such an approach leaves open room for future enhancement.  It is not
too far-fetched to imagine something like:

	git daemon --send-log-to=/var/log/git-daemon.log

by introducing the fourth value to "enum log_destination"; perhaps
the file is opened and connected to stderr to accept the logs,
combined with a new feature that tells the daemon to close and
reopen the log file when it receives a HUP or something like that.







^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH] daemon: add --no-syslog to undo implicit --syslog
  2018-01-24 18:33       ` Junio C Hamano
@ 2018-01-24 19:48         ` Lucas Werkmeister
  2018-01-27 18:31         ` [PATCH v2] daemon: add --send-log-to=(stderr|syslog|none) Lucas Werkmeister
  1 sibling, 0 replies; 21+ messages in thread
From: Lucas Werkmeister @ 2018-01-24 19:48 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Ævar Arnfjörð Bjarmason, git

On 24.01.2018 19:33, Junio C Hamano wrote:
> Lucas Werkmeister <mail@lucaswerkmeister.de> writes:
> 
>>> Moreover, --detach completely dissociates the process from the
>>> original set of standard file descriptors by first closing them and
>>> then connecting it to "/dev/null", so it will be nonsense to use this
>>> new option with it.
>>
>> Ah, I wasn’t aware of that – so with --detach, --no-syslog would be
>> better described as “disables all logging” rather than “log to stderr
>> instead”. IMHO it would still make sense to have the --no-syslog option
>> (then mainly for use with --inetd) as long as its interaction with
>> --inetd is properly documented.
> 
> Because "--detach --no-syslog" is a roundabout way to ask for
> sending the log to _nowhere_, I actually would say that "nonsense"
> is a bit too strong a word for the combination of your thing with
> "--detach".
> 
> It might make more sense to introduce a new "--send-log-to=<dest>"
> option, where the destination can be one of: syslog, stderr, none.
> 
> The you can make the current "--syslog" option a synonym to
> "--send-log-to=syslog".  The internal variable log_syslog would
> probably become
> 
> 	enum log_destination { 
> 		LOG_TO_NONE = -1,
> 		LOG_TO_STDERR = 0,
> 		LOG_TO_SYSLOG = 1,
> 	} log_destination;
> 
> and wherever the current code assigns 1 to log_syslog, you would be
> setting it LOG_TO_SYSLOG.
> 
> Then those who want no log can express that wish in a more direct
> way, i.e. "daemon --send-log-to=none", perhaps.
> 
> Such an approach leaves open room for future enhancement.  It is not
> too far-fetched to imagine something like:
> 
> 	git daemon --send-log-to=/var/log/git-daemon.log
> 
> by introducing the fourth value to "enum log_destination"; perhaps
> the file is opened and connected to stderr to accept the logs,
> combined with a new feature that tells the daemon to close and
> reopen the log file when it receives a HUP or something like that.

Sounds interesting… do you think it would be worth it supporting
multiple destinations? Right now this could be implemented fairly easily
by making log_destination a bit field (and --syslog would then imply
--send-log-to=syslog --no-send-log-to=stderr or something like that). On
the other hand, that doesn’t allow for this nice trick of reusing the
stderr fd for a log file in case of future enhancement.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v2] daemon: add --send-log-to=(stderr|syslog|none)
  2018-01-24 18:33       ` Junio C Hamano
  2018-01-24 19:48         ` Lucas Werkmeister
@ 2018-01-27 18:31         ` Lucas Werkmeister
  2018-01-28  6:40           ` Eric Sunshine
  1 sibling, 1 reply; 21+ messages in thread
From: Lucas Werkmeister @ 2018-01-27 18:31 UTC (permalink / raw)
  To: Junio C Hamano, git; +Cc: Lucas Werkmeister

This makes it possible to use --inetd while still logging to standard
error. --syslog is retained as an alias for --send-log-to=syslog. A mode
to disable logging explicitly is also provided.

The combination of --inetd with --send-log-to=stderr is useful, for
instance, when running `git daemon` as an instanced systemd service
(with associated socket unit). In this case, log messages sent via
syslog are received by the journal daemon, but run the risk of being
processed at a time when the `git daemon` process has already exited
(especially if the process was very short-lived, e.g. due to client
error), so that the journal daemon can no longer read its cgroup and
attach the message to the correct systemd unit (see systemd/systemd#2913
[1]). Logging to stderr instead can solve this problem, because systemd
can connect stderr directly to the journal daemon, which then already
knows which unit is associated with this stream.

[1]: https://github.com/systemd/systemd/issues/2913

Signed-off-by: Lucas Werkmeister <mail@lucaswerkmeister.de>
Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
---

Notes:
    This was originally “daemon: add --no-syslog to undo implicit
    --syslog”, but Junio pointed out that combining --no-syslog with
    --detach isn’t especially useful and suggested --send-log-to=
    instead. Is Helped-by: the right credit for this or should it be
    something else?
    
    I’m also not quite sure if the systemd part of the commit message is
    accurate – see my comment on the linked issue [2]. TL;DR: this might
    no longer be necessary on systemd v235. (I’m experiencing the
    problem on Debian Stretch, systemd v232.) As in the last patch, feel
    free to remove that part of the commit message.
    
    [2]: https://github.com/systemd/systemd/issues/2913#issuecomment-361002589

 Documentation/git-daemon.txt | 23 +++++++++++++++++++++--
 daemon.c                     | 43 ++++++++++++++++++++++++++++++++++++-------
 2 files changed, 57 insertions(+), 9 deletions(-)

diff --git a/Documentation/git-daemon.txt b/Documentation/git-daemon.txt
index 3c91db7be..e973f4390 100644
--- a/Documentation/git-daemon.txt
+++ b/Documentation/git-daemon.txt
@@ -20,6 +20,7 @@ SYNOPSIS
 	     [--inetd |
 	      [--listen=<host_or_ipaddr>] [--port=<n>]
 	      [--user=<user> [--group=<group>]]]
+	     [--send-log-to=(stderr|syslog|none)]
 	     [<directory>...]
 
 DESCRIPTION
@@ -110,8 +111,26 @@ OPTIONS
 	zero for no limit.
 
 --syslog::
-	Log to syslog instead of stderr. Note that this option does not imply
-	--verbose, thus by default only error conditions will be logged.
+	Short for `--send-log-to=syslog`.
+
+--send-log-to=<destination>::
+	Send log messages to the specified destination.
+	Note that this option does not imply --verbose,
+	thus by default only error conditions will be logged.
+	The <destination> defaults to `stderr`, and must be one of:
++
+--
+stderr::
+	Write to standard error.
+	Note that if `--detach` is specified,
+	the process disconnects from the real standard error,
+	making this destination effectively equivalent to `none`.
+syslog::
+	Write to syslog, using the `git-daemon` identifier.
+none::
+	Disable all logging.
+--
++
 
 --user-path::
 --user-path=<path>::
diff --git a/daemon.c b/daemon.c
index e37e343d0..3d8e16ede 100644
--- a/daemon.c
+++ b/daemon.c
@@ -9,7 +9,11 @@
 #define initgroups(x, y) (0) /* nothing */
 #endif
 
-static int log_syslog;
+static enum log_destination {
+	LOG_TO_NONE = -1,
+	LOG_TO_STDERR = 0,
+	LOG_TO_SYSLOG = 1,
+} log_destination;
 static int verbose;
 static int reuseaddr;
 static int informative_errors;
@@ -25,6 +29,7 @@ static const char daemon_usage[] =
 "           [--access-hook=<path>]\n"
 "           [--inetd | [--listen=<host_or_ipaddr>] [--port=<n>]\n"
 "                      [--detach] [--user=<user> [--group=<group>]]\n"
+"           [--send-log-to=(stderr|syslog|none)]\n"
 "           [<directory>...]";
 
 /* List of acceptable pathname prefixes */
@@ -74,11 +79,14 @@ static const char *get_ip_address(struct hostinfo *hi)
 
 static void logreport(int priority, const char *err, va_list params)
 {
-	if (log_syslog) {
+	switch (log_destination) {
+	case LOG_TO_SYSLOG: {
 		char buf[1024];
 		vsnprintf(buf, sizeof(buf), err, params);
 		syslog(priority, "%s", buf);
-	} else {
+		break;
+	}
+	case LOG_TO_STDERR: {
 		/*
 		 * Since stderr is set to buffered mode, the
 		 * logging of different processes will not overlap
@@ -88,6 +96,11 @@ static void logreport(int priority, const char *err, va_list params)
 		vfprintf(stderr, err, params);
 		fputc('\n', stderr);
 		fflush(stderr);
+		break;
+	}
+	case LOG_TO_NONE: {
+		break;
+	}
 	}
 }
 
@@ -1289,7 +1302,7 @@ int cmd_main(int argc, const char **argv)
 		}
 		if (!strcmp(arg, "--inetd")) {
 			inetd_mode = 1;
-			log_syslog = 1;
+			log_destination = LOG_TO_SYSLOG;
 			continue;
 		}
 		if (!strcmp(arg, "--verbose")) {
@@ -1297,9 +1310,25 @@ int cmd_main(int argc, const char **argv)
 			continue;
 		}
 		if (!strcmp(arg, "--syslog")) {
-			log_syslog = 1;
+			log_destination = LOG_TO_SYSLOG;
 			continue;
 		}
+		if (skip_prefix(arg, "--send-log-to=", &v)) {
+			if (!strcmp(v, "syslog")) {
+				log_destination = LOG_TO_SYSLOG;
+				continue;
+			}
+			else if (!strcmp(v, "stderr")) {
+				log_destination = LOG_TO_STDERR;
+				continue;
+			}
+			else if (!strcmp(v, "none")) {
+				log_destination = LOG_TO_NONE;
+				continue;
+			}
+			else
+				die("Unknown log destination %s", v);
+		}
 		if (!strcmp(arg, "--export-all")) {
 			export_all_trees = 1;
 			continue;
@@ -1356,7 +1385,7 @@ int cmd_main(int argc, const char **argv)
 		}
 		if (!strcmp(arg, "--detach")) {
 			detach = 1;
-			log_syslog = 1;
+			log_destination = LOG_TO_SYSLOG;
 			continue;
 		}
 		if (skip_prefix(arg, "--user=", &v)) {
@@ -1402,7 +1431,7 @@ int cmd_main(int argc, const char **argv)
 		usage(daemon_usage);
 	}
 
-	if (log_syslog) {
+	if (log_destination == LOG_TO_SYSLOG) {
 		openlog("git-daemon", LOG_PID, LOG_DAEMON);
 		set_die_routine(daemon_die);
 	} else
-- 
2.16.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH v2] daemon: add --send-log-to=(stderr|syslog|none)
  2018-01-27 18:31         ` [PATCH v2] daemon: add --send-log-to=(stderr|syslog|none) Lucas Werkmeister
@ 2018-01-28  6:40           ` Eric Sunshine
  2018-01-28 22:58             ` Lucas Werkmeister
  0 siblings, 1 reply; 21+ messages in thread
From: Eric Sunshine @ 2018-01-28  6:40 UTC (permalink / raw)
  To: Lucas Werkmeister; +Cc: Junio C Hamano, Git List

On Sat, Jan 27, 2018 at 1:31 PM, Lucas Werkmeister
<mail@lucaswerkmeister.de> wrote:
> This makes it possible to use --inetd while still logging to standard
> error. --syslog is retained as an alias for --send-log-to=syslog. A mode
> to disable logging explicitly is also provided.
>
> The combination of --inetd with --send-log-to=stderr is useful, for
> instance, when running `git daemon` as an instanced systemd service
> (with associated socket unit). In this case, log messages sent via
> syslog are received by the journal daemon, but run the risk of being
> processed at a time when the `git daemon` process has already exited
> (especially if the process was very short-lived, e.g. due to client
> error), so that the journal daemon can no longer read its cgroup and
> attach the message to the correct systemd unit (see systemd/systemd#2913
> [1]). Logging to stderr instead can solve this problem, because systemd
> can connect stderr directly to the journal daemon, which then already
> knows which unit is associated with this stream.

The purpose of this patch would be easier to fathom if the problem was
presented first (systemd race condition), followed by the solution
(ability to log to stderr even when using --inetd), followed finally
by incidental notes ("--syslog is retained as an alias..." and ability
to disable logging).

Not sure, though, if it's worth a re-roll.

> Signed-off-by: Lucas Werkmeister <mail@lucaswerkmeister.de>
> Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> Helped-by: Junio C Hamano <gitster@pobox.com>
> ---
>
> Notes:
>     This was originally “daemon: add --no-syslog to undo implicit
>     --syslog”, but Junio pointed out that combining --no-syslog with
>     --detach isn’t especially useful and suggested --send-log-to=
>     instead. Is Helped-by: the right credit for this or should it be
>     something else?

Helped-by: is fine, though typically your Signed-off-by: would be last.

I understand that Junio suggested the name --send-log-to=, but I
wonder if the more concise --log= would be an possibility.

More below...

> diff --git a/Documentation/git-daemon.txt b/Documentation/git-daemon.txt
> @@ -110,8 +111,26 @@ OPTIONS
> +--send-log-to=<destination>::
> +       Send log messages to the specified destination.
> +       Note that this option does not imply --verbose,
> +       thus by default only error conditions will be logged.
> +       The <destination> defaults to `stderr`, and must be one of:

Perhaps also update the documentation of --inetd to mention that its
implied --syslog can be overridden by --send-log-to=.

> diff --git a/daemon.c b/daemon.c
> @@ -74,11 +79,14 @@ static const char *get_ip_address(struct hostinfo *hi)
>
>  static void logreport(int priority, const char *err, va_list params)
>  {
> -       if (log_syslog) {
> +       switch (log_destination) {
> +       case LOG_TO_SYSLOG: {
>                 char buf[1024];
>                 vsnprintf(buf, sizeof(buf), err, params);
>                 syslog(priority, "%s", buf);
> -       } else {
> +               break;
> +       }
> +       case LOG_TO_STDERR: {

There aren't many instances of:

    case FOO: {

in the code-base, but those that exist don't use braces around cases
which don't need it, so perhaps drop it from the STDERR and NONE
cases. (Probably not worth a re-roll, though.)

>                 /*
>                  * Since stderr is set to buffered mode, the
>                  * logging of different processes will not overlap
> @@ -88,6 +96,11 @@ static void logreport(int priority, const char *err, va_list params)
>                 vfprintf(stderr, err, params);
>                 fputc('\n', stderr);
>                 fflush(stderr);
> +               break;
> +       }
> +       case LOG_TO_NONE: {
> +               break;
> +       }
>         }

Consecutive lines with braces at the same indentation level is rather
odd (but see previous comment).

>  }
>
> @@ -1289,7 +1302,7 @@ int cmd_main(int argc, const char **argv)
>                 }
>                 if (!strcmp(arg, "--inetd")) {
>                         inetd_mode = 1;
> -                       log_syslog = 1;
> +                       log_destination = LOG_TO_SYSLOG;

Hmm, so an invocation "--inetd --send-log-to=stderr" works as
expected, but "--send-log-to=stderr --inetd" doesn't; output goes to
syslog despite the explicit request for stderr. Counterintuitive. This
should probably distinguish between 'log_destination' being unset and
set explicitly; if unset, then, and only then, have --inetd imply
syslog. Perhaps something like this:

    static enum log_destination {
        LOG_TO_UNSET = -1
        LOG_TO_NONE,
        LOG_TO_STDERR,
        LOG_TO_SYSLOG,
    } log_destination = LOG_TO_UNSET;

    if (!strcmp(arg, "--inetd")) {
        inetd_mode = 1;
        if (log_destination == LOG_TO_UNSET)
            log_destination = LOG_TO_SYSLOG;
        ...
    }
    ...
    if (log_destination == LOG_TO_UNSET)
        log_destination = LOG_TO_STDERR

>                         continue;
>                 }
> @@ -1297,9 +1310,25 @@ int cmd_main(int argc, const char **argv)
> +               if (skip_prefix(arg, "--send-log-to=", &v)) {
> +                       if (!strcmp(v, "syslog")) {
> +                               log_destination = LOG_TO_SYSLOG;
> +                               continue;
> +                       }
> +                       else if (!strcmp(v, "stderr")) {

Style: cuddle 'else' with the braces: } else if (...) {

> +                               log_destination = LOG_TO_STDERR;
> +                               continue;
> +                       }
> +                       else if (!strcmp(v, "none")) {
> +                               log_destination = LOG_TO_NONE;
> +                               continue;
> +                       }
> +                       else
> +                               die("Unknown log destination %s", v);

Even though there is a mix of capitalized and lowercase-only error
messages in daemon.c, newly written code avoids capitalization so
perhaps downcase "unknown".

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2] daemon: add --send-log-to=(stderr|syslog|none)
  2018-01-28  6:40           ` Eric Sunshine
@ 2018-01-28 22:58             ` Lucas Werkmeister
  2018-01-29  0:10               ` Eric Sunshine
  0 siblings, 1 reply; 21+ messages in thread
From: Lucas Werkmeister @ 2018-01-28 22:58 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Junio C Hamano, Git List

On 28.01.2018 07:40, Eric Sunshine wrote:
> On Sat, Jan 27, 2018 at 1:31 PM, Lucas Werkmeister
> <mail@lucaswerkmeister.de> wrote:
>> This makes it possible to use --inetd while still logging to standard
>> error. --syslog is retained as an alias for --send-log-to=syslog. A mode
>> to disable logging explicitly is also provided.
>>
>> The combination of --inetd with --send-log-to=stderr is useful, for
>> instance, when running `git daemon` as an instanced systemd service
>> (with associated socket unit). In this case, log messages sent via
>> syslog are received by the journal daemon, but run the risk of being
>> processed at a time when the `git daemon` process has already exited
>> (especially if the process was very short-lived, e.g. due to client
>> error), so that the journal daemon can no longer read its cgroup and
>> attach the message to the correct systemd unit (see systemd/systemd#2913
>> [1]). Logging to stderr instead can solve this problem, because systemd
>> can connect stderr directly to the journal daemon, which then already
>> knows which unit is associated with this stream.
> 
> The purpose of this patch would be easier to fathom if the problem was
> presented first (systemd race condition), followed by the solution
> (ability to log to stderr even when using --inetd), followed finally
> by incidental notes ("--syslog is retained as an alias..." and ability
> to disable logging).
> 
> Not sure, though, if it's worth a re-roll.

I didn’t want to sound like I was just scratching my own itch ;) I hope
this option is useful for other use-cases as well?

> 
>> Signed-off-by: Lucas Werkmeister <mail@lucaswerkmeister.de>
>> Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
>> Helped-by: Junio C Hamano <gitster@pobox.com>
>> ---
>>
>> Notes:
>>     This was originally “daemon: add --no-syslog to undo implicit
>>     --syslog”, but Junio pointed out that combining --no-syslog with
>>     --detach isn’t especially useful and suggested --send-log-to=
>>     instead. Is Helped-by: the right credit for this or should it be
>>     something else?
> 
> Helped-by: is fine, though typically your Signed-off-by: would be last.
> 
> I understand that Junio suggested the name --send-log-to=, but I
> wonder if the more concise --log= would be an possibility.

--log sounds to me like it could also indicate *what* to log (e. g. “log
verbosely” or “don’t log client IPs”). But perhaps --log-to= ?

> 
> More below...
> 
>> diff --git a/Documentation/git-daemon.txt b/Documentation/git-daemon.txt
>> @@ -110,8 +111,26 @@ OPTIONS
>> +--send-log-to=<destination>::
>> +       Send log messages to the specified destination.
>> +       Note that this option does not imply --verbose,
>> +       thus by default only error conditions will be logged.
>> +       The <destination> defaults to `stderr`, and must be one of:
> 
> Perhaps also update the documentation of --inetd to mention that its
> implied --syslog can be overridden by --send-log-to=.

Very good idea!

> 
>> diff --git a/daemon.c b/daemon.c
>> @@ -74,11 +79,14 @@ static const char *get_ip_address(struct hostinfo *hi)
>>
>>  static void logreport(int priority, const char *err, va_list params)
>>  {
>> -       if (log_syslog) {
>> +       switch (log_destination) {
>> +       case LOG_TO_SYSLOG: {
>>                 char buf[1024];
>>                 vsnprintf(buf, sizeof(buf), err, params);
>>                 syslog(priority, "%s", buf);
>> -       } else {
>> +               break;
>> +       }
>> +       case LOG_TO_STDERR: {
> 
> There aren't many instances of:
> 
>     case FOO: {
> 
> in the code-base, but those that exist don't use braces around cases
> which don't need it, so perhaps drop it from the STDERR and NONE
> cases. (Probably not worth a re-roll, though.)

Good point, forgot that part of the coding guidelines. Only the syslog
case needs it because the buf declaration can’t be labeled directly.

> 
>>                 /*
>>                  * Since stderr is set to buffered mode, the
>>                  * logging of different processes will not overlap
>> @@ -88,6 +96,11 @@ static void logreport(int priority, const char *err, va_list params)
>>                 vfprintf(stderr, err, params);
>>                 fputc('\n', stderr);
>>                 fflush(stderr);
>> +               break;
>> +       }
>> +       case LOG_TO_NONE: {
>> +               break;
>> +       }
>>         }
> 
> Consecutive lines with braces at the same indentation level is rather
> odd (but see previous comment).
> 
>>  }
>>
>> @@ -1289,7 +1302,7 @@ int cmd_main(int argc, const char **argv)
>>                 }
>>                 if (!strcmp(arg, "--inetd")) {
>>                         inetd_mode = 1;
>> -                       log_syslog = 1;
>> +                       log_destination = LOG_TO_SYSLOG;
> 
> Hmm, so an invocation "--inetd --send-log-to=stderr" works as
> expected, but "--send-log-to=stderr --inetd" doesn't; output goes to
> syslog despite the explicit request for stderr. Counterintuitive. This
> should probably distinguish between 'log_destination' being unset and
> set explicitly; if unset, then, and only then, have --inetd imply
> syslog. Perhaps something like this:
> 
>     static enum log_destination {
>         LOG_TO_UNSET = -1
>         LOG_TO_NONE,
>         LOG_TO_STDERR,
>         LOG_TO_SYSLOG,
>     } log_destination = LOG_TO_UNSET;
> 
>     if (!strcmp(arg, "--inetd")) {
>         inetd_mode = 1;
>         if (log_destination == LOG_TO_UNSET)
>             log_destination = LOG_TO_SYSLOG;
>         ...
>     }
>     ...
>     if (log_destination == LOG_TO_UNSET)
>         log_destination = LOG_TO_STDERR
> 

I’m not sure if that’s worth the extra complication… some existing
options behave the same way already, e. g. in `git rebase --stat
--quiet`, the `--stat` is ignored.

>>                         continue;
>>                 }
>> @@ -1297,9 +1310,25 @@ int cmd_main(int argc, const char **argv)
>> +               if (skip_prefix(arg, "--send-log-to=", &v)) {
>> +                       if (!strcmp(v, "syslog")) {
>> +                               log_destination = LOG_TO_SYSLOG;
>> +                               continue;
>> +                       }
>> +                       else if (!strcmp(v, "stderr")) {
> 
> Style: cuddle 'else' with the braces: } else if (...) {
>

Is that a general rule? I couldn’t find anything about it in
CodingGuidelines and daemon.c seemed to use both styles about evenly, so
I wasn’t sure what to use.

>> +                               log_destination = LOG_TO_STDERR;
>> +                               continue;
>> +                       }
>> +                       else if (!strcmp(v, "none")) {
>> +                               log_destination = LOG_TO_NONE;
>> +                               continue;
>> +                       }
>> +                       else
>> +                               die("Unknown log destination %s", v);
> 
> Even though there is a mix of capitalized and lowercase-only error
> messages in daemon.c, newly written code avoids capitalization so
> perhaps downcase "unknown".
> 

Okay, thanks!

I’ll prepare a new version of the patch, but will wait a bit before
sending it in case there’s more feedback. But thanks for your reply :)

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v2] daemon: add --send-log-to=(stderr|syslog|none)
  2018-01-28 22:58             ` Lucas Werkmeister
@ 2018-01-29  0:10               ` Eric Sunshine
  2018-02-03 23:08                 ` [PATCH v3] daemon: add --log-destination=(stderr|syslog|none) Lucas Werkmeister
  0 siblings, 1 reply; 21+ messages in thread
From: Eric Sunshine @ 2018-01-29  0:10 UTC (permalink / raw)
  To: Lucas Werkmeister; +Cc: Junio C Hamano, Git List

On Sun, Jan 28, 2018 at 5:58 PM, Lucas Werkmeister
<mail@lucaswerkmeister.de> wrote:
> On 28.01.2018 07:40, Eric Sunshine wrote:
>> On Sat, Jan 27, 2018 at 1:31 PM, Lucas Werkmeister
>> <mail@lucaswerkmeister.de> wrote:
>>> This makes it possible to use --inetd while still logging to standard
>>> error. --syslog is retained as an alias for --send-log-to=syslog. A mode
>>> to disable logging explicitly is also provided.
>>>
>>> The combination of --inetd with --send-log-to=stderr is useful, for
>>> instance, when running `git daemon` as an instanced systemd service
>>> (with associated socket unit). In this case, log messages sent via
>>> syslog are received by the journal daemon, but run the risk of being
>>> processed at a time when the `git daemon` process has already exited
>>> (especially if the process was very short-lived, e.g. due to client
>>> error), so that the journal daemon can no longer read its cgroup and
>>> attach the message to the correct systemd unit (see systemd/systemd#2913
>>> [1]). Logging to stderr instead can solve this problem, because systemd
>>> can connect stderr directly to the journal daemon, which then already
>>> knows which unit is associated with this stream.
>>
>> The purpose of this patch would be easier to fathom if the problem was
>> presented first (systemd race condition), followed by the solution
>> (ability to log to stderr even when using --inetd), followed finally
>> by incidental notes ("--syslog is retained as an alias..." and ability
>> to disable logging).
>>
>> Not sure, though, if it's worth a re-roll.
>
> I didn’t want to sound like I was just scratching my own itch ;) I hope
> this option is useful for other use-cases as well?

If the reader does not know that --inetd implies --syslog, then

    This makes it possible to use --inetd while still logging to
    standard error.

leads to a "Huh?" moment since it is not self-contained. Had it said

    Add new option --send-log-to=(stderr|syslog|none) which
    allows the implied --syslog by --inetd to be overridden.

it would have provided enough information to understand the purpose of
the patch at a glance. Talking about the systemd race-condition first
would also have explained the patch's purpose, and since the proposed
solution is general (not specific to your use-case), scratching an
itch is not a point against it.

Anyhow, it's not that big of a deal, but it did give me a bit of a
pause when reading the first paragraph since it's customary on this
project to start by explaining the problem.

>> I understand that Junio suggested the name --send-log-to=, but I
>> wonder if the more concise --log= would be an possibility.
>
> --log sounds to me like it could also indicate *what* to log (e. g. “log
> verbosely” or “don’t log client IPs”). But perhaps --log-to= ?

Perhaps we can take into consideration precedent by other (non-Git)
daemon-like commands when naming this option. (None come to my mind
immediately, but I'm sure they're out there.)

>>>                 if (!strcmp(arg, "--inetd")) {
>>>                         inetd_mode = 1;
>>> -                       log_syslog = 1;
>>> +                       log_destination = LOG_TO_SYSLOG;
>>
>> Hmm, so an invocation "--inetd --send-log-to=stderr" works as
>> expected, but "--send-log-to=stderr --inetd" doesn't; output goes to
>> syslog despite the explicit request for stderr. Counterintuitive. This
>> should probably distinguish between 'log_destination' being unset and
>> set explicitly; if unset, then, and only then, have --inetd imply
>> syslog. Perhaps something like this:
>>
>>     static enum log_destination {
>>         LOG_TO_UNSET = -1
>>         LOG_TO_NONE,
>>         LOG_TO_STDERR,
>>         LOG_TO_SYSLOG,
>>     } log_destination = LOG_TO_UNSET;
>>
>>     if (!strcmp(arg, "--inetd")) {
>>         inetd_mode = 1;
>>         if (log_destination == LOG_TO_UNSET)
>>             log_destination = LOG_TO_SYSLOG;
>>         ...
>>     }
>>     ...
>>     if (log_destination == LOG_TO_UNSET)
>>         log_destination = LOG_TO_STDERR
>>
>
> I’m not sure if that’s worth the extra complication… some existing
> options behave the same way already, e. g. in `git rebase --stat
> --quiet`, the `--stat` is ignored.

I took "last one wins" into consideration when writing the above but
was not convinced that it applies to this case since --inetd and
--send-log-to= have no obvious relation to one another (unlike, say,
--verbose and --quiet or other similar combinations). Unless one reads
the documentation very closely, output ending up in syslog despite
"--send-log-to=stderr --inetd" is just way too counterintuitive and
may well lead to bug reports later on. Therefore, doing the additional
work now to stave off such bug reports is likely worthwhile.

>>> +                       }
>>> +                       else if (!strcmp(v, "stderr")) {
>>
>> Style: cuddle 'else' with the braces: } else if (...) {
>>
>
> Is that a general rule? I couldn’t find anything about it in
> CodingGuidelines and daemon.c seemed to use both styles about evenly, so
> I wasn’t sure what to use.

It's not stated explicitly in CodingGuidelines, but there is one
example of cuddling 'else' with braces in the section talking about
braces and 'if' statements.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v3] daemon: add --log-destination=(stderr|syslog|none)
  2018-01-29  0:10               ` Eric Sunshine
@ 2018-02-03 23:08                 ` Lucas Werkmeister
  2018-02-04  6:36                   ` Eric Sunshine
  0 siblings, 1 reply; 21+ messages in thread
From: Lucas Werkmeister @ 2018-02-03 23:08 UTC (permalink / raw)
  To: Eric Sunshine, Junio C Hamano, git; +Cc: Lucas Werkmeister

This new option can be used to override the implicit --syslog of
--inetd, or to disable all logging. (While --detach also implies
--syslog, --log-destination=stderr with --detach is useless since
--detach disassociates the process from the original stderr.) --syslog
is retained as an alias for --log-destination=syslog.

--log-destination always overrides implicit --syslog regardless of
option order. This is different than the “last one wins” logic that
applies to some implicit options elsewhere in Git, but should hopefully
be less confusing. (I also don’t know if *all* implicit options in Git
follow “last one wins”.)

The combination of --inetd with --log-destination=stderr is useful, for
instance, when running `git daemon` as an instanced systemd service
(with associated socket unit). In this case, log messages sent via
syslog are received by the journal daemon, but run the risk of being
processed at a time when the `git daemon` process has already exited
(especially if the process was very short-lived, e.g. due to client
error), so that the journal daemon can no longer read its cgroup and
attach the message to the correct systemd unit (see systemd/systemd#2913
[1]). Logging to stderr instead can solve this problem, because systemd
can connect stderr directly to the journal daemon, which then already
knows which unit is associated with this stream.

[1]: https://github.com/systemd/systemd/issues/2913

Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Lucas Werkmeister <mail@lucaswerkmeister.de>
---

Notes:
    Next version on my quest to make git-daemon logging more reliable :)
    many thanks to Eric Sunshine for review. Main changes this version:
    
    - Rename --send-log-to to --log-destination, following the
      postgresql option. A cursory search didn’t turn up any other
      daemons with a similar option – suggestions welcome!
    - Make explicit --log-destination always override implicit --syslog,
      regardless of option order.

 Documentation/git-daemon.txt | 26 ++++++++++++++++++++++---
 daemon.c                     | 45 +++++++++++++++++++++++++++++++++++++-------
 2 files changed, 61 insertions(+), 10 deletions(-)

diff --git a/Documentation/git-daemon.txt b/Documentation/git-daemon.txt
index 3c91db7be..a0106e6aa 100644
--- a/Documentation/git-daemon.txt
+++ b/Documentation/git-daemon.txt
@@ -20,6 +20,7 @@ SYNOPSIS
 	     [--inetd |
 	      [--listen=<host_or_ipaddr>] [--port=<n>]
 	      [--user=<user> [--group=<group>]]]
+	     [--log-destination=(stderr|syslog|none)]
 	     [<directory>...]
 
 DESCRIPTION
@@ -80,7 +81,8 @@ OPTIONS
 	do not have the 'git-daemon-export-ok' file.
 
 --inetd::
-	Have the server run as an inetd service. Implies --syslog.
+	Have the server run as an inetd service. Implies --syslog (may be
+	overridden with `--log-destination=`).
 	Incompatible with --detach, --port, --listen, --user and --group
 	options.
 
@@ -110,8 +112,26 @@ OPTIONS
 	zero for no limit.
 
 --syslog::
-	Log to syslog instead of stderr. Note that this option does not imply
-	--verbose, thus by default only error conditions will be logged.
+	Short for `--log-destination=syslog`.
+
+--log-destination=<destination>::
+	Send log messages to the specified destination.
+	Note that this option does not imply --verbose,
+	thus by default only error conditions will be logged.
+	The <destination> defaults to `stderr`, and must be one of:
++
+--
+stderr::
+	Write to standard error.
+	Note that if `--detach` is specified,
+	the process disconnects from the real standard error,
+	making this destination effectively equivalent to `none`.
+syslog::
+	Write to syslog, using the `git-daemon` identifier.
+none::
+	Disable all logging.
+--
++
 
 --user-path::
 --user-path=<path>::
diff --git a/daemon.c b/daemon.c
index e37e343d0..f28400e3f 100644
--- a/daemon.c
+++ b/daemon.c
@@ -9,7 +9,12 @@
 #define initgroups(x, y) (0) /* nothing */
 #endif
 
-static int log_syslog;
+static enum log_destination {
+	LOG_DESTINATION_UNSET = -1,
+	LOG_DESTINATION_NONE = 0,
+	LOG_DESTINATION_STDERR = 1,
+	LOG_DESTINATION_SYSLOG = 2,
+} log_destination;
 static int verbose;
 static int reuseaddr;
 static int informative_errors;
@@ -25,6 +30,7 @@ static const char daemon_usage[] =
 "           [--access-hook=<path>]\n"
 "           [--inetd | [--listen=<host_or_ipaddr>] [--port=<n>]\n"
 "                      [--detach] [--user=<user> [--group=<group>]]\n"
+"           [--log-destination=(stderr|syslog|none)]\n"
 "           [<directory>...]";
 
 /* List of acceptable pathname prefixes */
@@ -74,11 +80,14 @@ static const char *get_ip_address(struct hostinfo *hi)
 
 static void logreport(int priority, const char *err, va_list params)
 {
-	if (log_syslog) {
+	switch (log_destination) {
+	case LOG_DESTINATION_SYSLOG: {
 		char buf[1024];
 		vsnprintf(buf, sizeof(buf), err, params);
 		syslog(priority, "%s", buf);
-	} else {
+		break;
+	}
+	case LOG_DESTINATION_STDERR:
 		/*
 		 * Since stderr is set to buffered mode, the
 		 * logging of different processes will not overlap
@@ -88,6 +97,10 @@ static void logreport(int priority, const char *err, va_list params)
 		vfprintf(stderr, err, params);
 		fputc('\n', stderr);
 		fflush(stderr);
+		break;
+	case LOG_DESTINATION_NONE:
+	case LOG_DESTINATION_UNSET:
+		break;
 	}
 }
 
@@ -1289,7 +1302,6 @@ int cmd_main(int argc, const char **argv)
 		}
 		if (!strcmp(arg, "--inetd")) {
 			inetd_mode = 1;
-			log_syslog = 1;
 			continue;
 		}
 		if (!strcmp(arg, "--verbose")) {
@@ -1297,9 +1309,22 @@ int cmd_main(int argc, const char **argv)
 			continue;
 		}
 		if (!strcmp(arg, "--syslog")) {
-			log_syslog = 1;
+			log_destination = LOG_DESTINATION_SYSLOG;
 			continue;
 		}
+		if (skip_prefix(arg, "--log-destination=", &v)) {
+			if (!strcmp(v, "syslog")) {
+				log_destination = LOG_DESTINATION_SYSLOG;
+				continue;
+			} else if (!strcmp(v, "stderr")) {
+				log_destination = LOG_DESTINATION_STDERR;
+				continue;
+			} else if (!strcmp(v, "none")) {
+				log_destination = LOG_DESTINATION_NONE;
+				continue;
+			} else
+				die("Unknown log destination %s", v);
+		}
 		if (!strcmp(arg, "--export-all")) {
 			export_all_trees = 1;
 			continue;
@@ -1356,7 +1381,6 @@ int cmd_main(int argc, const char **argv)
 		}
 		if (!strcmp(arg, "--detach")) {
 			detach = 1;
-			log_syslog = 1;
 			continue;
 		}
 		if (skip_prefix(arg, "--user=", &v)) {
@@ -1402,7 +1426,14 @@ int cmd_main(int argc, const char **argv)
 		usage(daemon_usage);
 	}
 
-	if (log_syslog) {
+	if (log_destination == LOG_DESTINATION_UNSET) {
+		if (inetd_mode || detach)
+			log_destination = LOG_DESTINATION_SYSLOG;
+		else
+			log_destination = LOG_DESTINATION_STDERR;
+	}
+
+	if (log_destination == LOG_DESTINATION_SYSLOG) {
 		openlog("git-daemon", LOG_PID, LOG_DAEMON);
 		set_die_routine(daemon_die);
 	} else
-- 
2.16.1


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH v3] daemon: add --log-destination=(stderr|syslog|none)
  2018-02-03 23:08                 ` [PATCH v3] daemon: add --log-destination=(stderr|syslog|none) Lucas Werkmeister
@ 2018-02-04  6:36                   ` Eric Sunshine
  2018-02-04 18:29                     ` Lucas Werkmeister
  0 siblings, 1 reply; 21+ messages in thread
From: Eric Sunshine @ 2018-02-04  6:36 UTC (permalink / raw)
  To: Lucas Werkmeister; +Cc: Junio C Hamano, Git List

On Sat, Feb 3, 2018 at 6:08 PM, Lucas Werkmeister
<mail@lucaswerkmeister.de> wrote:
> This new option can be used to override the implicit --syslog of
> --inetd, or to disable all logging. (While --detach also implies
> --syslog, --log-destination=stderr with --detach is useless since
> --detach disassociates the process from the original stderr.) --syslog
> is retained as an alias for --log-destination=syslog.
> [...]
> Signed-off-by: Lucas Werkmeister <mail@lucaswerkmeister.de>

Thanks for the re-roll. There are a few comments below. Except for one
apparent bug, I'm not sure the others are worth a re-roll...

> diff --git a/Documentation/git-daemon.txt b/Documentation/git-daemon.txt
> @@ -110,8 +112,26 @@ OPTIONS
> +--log-destination=<destination>::
> +       Send log messages to the specified destination.
> +       Note that this option does not imply --verbose,
> +       thus by default only error conditions will be logged.
> +       The <destination> defaults to `stderr`, and must be one of:

I wonder if this should say instead:

    The default destination is `stderr` unless `syslog`
    is implied by `--inetd` or `--detach`, ...

> diff --git a/daemon.c b/daemon.c
> @@ -9,7 +9,12 @@
> -static int log_syslog;
> +static enum log_destination {
> +       LOG_DESTINATION_UNSET = -1,
> +       LOG_DESTINATION_NONE = 0,
> +       LOG_DESTINATION_STDERR = 1,
> +       LOG_DESTINATION_SYSLOG = 2,
> +} log_destination;

Doesn't log_destination need to be initialized to
LOG_DESTINATION_UNSET (see [1])? As it stands, being static, it's
initialized automatically to 0 (LOG_DESTINATION_NONE), which borks the
logic below.

> @@ -74,11 +80,14 @@ static const char *get_ip_address(struct hostinfo *hi)
>  static void logreport(int priority, const char *err, va_list params)
>  {
> +       switch (log_destination) {
> +       case LOG_DESTINATION_SYSLOG: {
>                 char buf[1024];
>                 vsnprintf(buf, sizeof(buf), err, params);
>                 syslog(priority, "%s", buf);
> +               break;
> +       }
> +       case LOG_DESTINATION_STDERR:
>                 /*
>                  * Since stderr is set to buffered mode, the
>                  * logging of different processes will not overlap
> @@ -88,6 +97,10 @@ static void logreport(int priority, const char *err, va_list params)
>                 vfprintf(stderr, err, params);
>                 fputc('\n', stderr);
>                 fflush(stderr);
> +               break;
> +       case LOG_DESTINATION_NONE:
> +       case LOG_DESTINATION_UNSET:
> +               break;

Since LOG_DESTINATION_UNSET should never occur, perhaps this should be
written as:

    case LOG_DESTINATION_NONE:
        break;
    case LOG_DESTINATION_UNSET:
        BUG("impossible destination: %d", log_destination);

> @@ -1297,9 +1309,22 @@ int cmd_main(int argc, const char **argv)
> +               if (skip_prefix(arg, "--log-destination=", &v)) {
> +                       if (!strcmp(v, "syslog")) {
> +                               log_destination = LOG_DESTINATION_SYSLOG;
> +                               continue;
> +                       } else if (!strcmp(v, "stderr")) {
> +                               log_destination = LOG_DESTINATION_STDERR;
> +                               continue;
> +                       } else if (!strcmp(v, "none")) {
> +                               log_destination = LOG_DESTINATION_NONE;
> +                               continue;
> +                       } else
> +                               die("Unknown log destination %s", v);

Mentioned previously[1], this probably ought to start with lowercase.
It also would be more readable to set off the unknown value with a
colon or quotes:

    die("unknown log destination '%s', v);

> @@ -1402,7 +1426,14 @@ int cmd_main(int argc, const char **argv)
> -       if (log_syslog) {
> +       if (log_destination == LOG_DESTINATION_UNSET) {
> +               if (inetd_mode || detach)
> +                       log_destination = LOG_DESTINATION_SYSLOG;
> +               else
> +                       log_destination = LOG_DESTINATION_STDERR;
> +       }
> +
> +       if (log_destination == LOG_DESTINATION_SYSLOG) {
>                 openlog("git-daemon", LOG_PID, LOG_DAEMON);
>                 set_die_routine(daemon_die);

[1]: https://public-inbox.org/git/CAPig+cTetjQ9LSH68Fe5OTcj9TwQ9GSbGzdrjzHOhTAVFvrPxw@mail.gmail.com/

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v3] daemon: add --log-destination=(stderr|syslog|none)
  2018-02-04  6:36                   ` Eric Sunshine
@ 2018-02-04 18:29                     ` Lucas Werkmeister
  2018-02-04 18:30                       ` [PATCH v4] " Lucas Werkmeister
  0 siblings, 1 reply; 21+ messages in thread
From: Lucas Werkmeister @ 2018-02-04 18:29 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Junio C Hamano, Git List

[-- Attachment #1: Type: text/plain, Size: 5087 bytes --]

On 04.02.2018 07:36, Eric Sunshine wrote:
> On Sat, Feb 3, 2018 at 6:08 PM, Lucas Werkmeister
> <mail@lucaswerkmeister.de> wrote:
>> This new option can be used to override the implicit --syslog of
>> --inetd, or to disable all logging. (While --detach also implies
>> --syslog, --log-destination=stderr with --detach is useless since
>> --detach disassociates the process from the original stderr.) --syslog
>> is retained as an alias for --log-destination=syslog.
>> [...]
>> Signed-off-by: Lucas Werkmeister <mail@lucaswerkmeister.de>
> 
> Thanks for the re-roll. There are a few comments below. Except for one
> apparent bug, I'm not sure the others are worth a re-roll...
> 
>> diff --git a/Documentation/git-daemon.txt b/Documentation/git-daemon.txt
>> @@ -110,8 +112,26 @@ OPTIONS
>> +--log-destination=<destination>::
>> +       Send log messages to the specified destination.
>> +       Note that this option does not imply --verbose,
>> +       thus by default only error conditions will be logged.
>> +       The <destination> defaults to `stderr`, and must be one of:
> 
> I wonder if this should say instead:
> 
>     The default destination is `stderr` unless `syslog`
>     is implied by `--inetd` or `--detach`, ...
> 
>> diff --git a/daemon.c b/daemon.c
>> @@ -9,7 +9,12 @@
>> -static int log_syslog;
>> +static enum log_destination {
>> +       LOG_DESTINATION_UNSET = -1,
>> +       LOG_DESTINATION_NONE = 0,
>> +       LOG_DESTINATION_STDERR = 1,
>> +       LOG_DESTINATION_SYSLOG = 2,
>> +} log_destination;
> 
> Doesn't log_destination need to be initialized to
> LOG_DESTINATION_UNSET (see [1])? As it stands, being static, it's
> initialized automatically to 0 (LOG_DESTINATION_NONE), which borks the
> logic below.

Thanks, I knew I’d forgotten something :)

> 
>> @@ -74,11 +80,14 @@ static const char *get_ip_address(struct hostinfo *hi)
>>  static void logreport(int priority, const char *err, va_list params)
>>  {
>> +       switch (log_destination) {
>> +       case LOG_DESTINATION_SYSLOG: {
>>                 char buf[1024];
>>                 vsnprintf(buf, sizeof(buf), err, params);
>>                 syslog(priority, "%s", buf);
>> +               break;
>> +       }
>> +       case LOG_DESTINATION_STDERR:
>>                 /*
>>                  * Since stderr is set to buffered mode, the
>>                  * logging of different processes will not overlap
>> @@ -88,6 +97,10 @@ static void logreport(int priority, const char *err, va_list params)
>>                 vfprintf(stderr, err, params);
>>                 fputc('\n', stderr);
>>                 fflush(stderr);
>> +               break;
>> +       case LOG_DESTINATION_NONE:
>> +       case LOG_DESTINATION_UNSET:
>> +               break;
> 
> Since LOG_DESTINATION_UNSET should never occur, perhaps this should be
> written as:
> 
>     case LOG_DESTINATION_NONE:
>         break;
>     case LOG_DESTINATION_UNSET:
>         BUG("impossible destination: %d", log_destination);

Good point, I didn’t know about the BUG() macro. But putting the
destination in the message seems unnecessary if it can only be a single
value – or would you make this a default: case?

> 
>> @@ -1297,9 +1309,22 @@ int cmd_main(int argc, const char **argv)
>> +               if (skip_prefix(arg, "--log-destination=", &v)) {
>> +                       if (!strcmp(v, "syslog")) {
>> +                               log_destination = LOG_DESTINATION_SYSLOG;
>> +                               continue;
>> +                       } else if (!strcmp(v, "stderr")) {
>> +                               log_destination = LOG_DESTINATION_STDERR;
>> +                               continue;
>> +                       } else if (!strcmp(v, "none")) {
>> +                               log_destination = LOG_DESTINATION_NONE;
>> +                               continue;
>> +                       } else
>> +                               die("Unknown log destination %s", v);
> 
> Mentioned previously[1], this probably ought to start with lowercase.
> It also would be more readable to set off the unknown value with a
> colon or quotes:
> 
>     die("unknown log destination '%s', v);
> 
>> @@ -1402,7 +1426,14 @@ int cmd_main(int argc, const char **argv)
>> -       if (log_syslog) {
>> +       if (log_destination == LOG_DESTINATION_UNSET) {
>> +               if (inetd_mode || detach)
>> +                       log_destination = LOG_DESTINATION_SYSLOG;
>> +               else
>> +                       log_destination = LOG_DESTINATION_STDERR;
>> +       }
>> +
>> +       if (log_destination == LOG_DESTINATION_SYSLOG) {
>>                 openlog("git-daemon", LOG_PID, LOG_DAEMON);
>>                 set_die_routine(daemon_die);
> 
> [1]: https://public-inbox.org/git/CAPig+cTetjQ9LSH68Fe5OTcj9TwQ9GSbGzdrjzHOhTAVFvrPxw@mail.gmail.com/
> 

I’ll send a new version shortly, also addressing your other comments
which I didn’t reply to here.

Cheers,
Lucas


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4165 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH v4] daemon: add --log-destination=(stderr|syslog|none)
  2018-02-04 18:29                     ` Lucas Werkmeister
@ 2018-02-04 18:30                       ` Lucas Werkmeister
  2018-02-04 18:55                         ` Ævar Arnfjörð Bjarmason
  2018-02-04 19:36                         ` Eric Sunshine
  0 siblings, 2 replies; 21+ messages in thread
From: Lucas Werkmeister @ 2018-02-04 18:30 UTC (permalink / raw)
  To: Eric Sunshine, Junio C Hamano, git; +Cc: Lucas Werkmeister

This new option can be used to override the implicit --syslog of
--inetd, or to disable all logging. (While --detach also implies
--syslog, --log-destination=stderr with --detach is useless since
--detach disassociates the process from the original stderr.) --syslog
is retained as an alias for --log-destination=syslog.

--log-destination always overrides implicit --syslog regardless of
option order. This is different than the “last one wins” logic that
applies to some implicit options elsewhere in Git, but should hopefully
be less confusing. (I also don’t know if *all* implicit options in Git
follow “last one wins”.)

The combination of --inetd with --log-destination=stderr is useful, for
instance, when running `git daemon` as an instanced systemd service
(with associated socket unit). In this case, log messages sent via
syslog are received by the journal daemon, but run the risk of being
processed at a time when the `git daemon` process has already exited
(especially if the process was very short-lived, e.g. due to client
error), so that the journal daemon can no longer read its cgroup and
attach the message to the correct systemd unit (see systemd/systemd#2913
[1]). Logging to stderr instead can solve this problem, because systemd
can connect stderr directly to the journal daemon, which then already
knows which unit is associated with this stream.

[1]: https://github.com/systemd/systemd/issues/2913

Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Lucas Werkmeister <mail@lucaswerkmeister.de>
---

Notes:
    Fixes log_destination not being initialized correctly and some minor
    style issues.

 Documentation/git-daemon.txt | 28 ++++++++++++++++++++++++---
 daemon.c                     | 46 +++++++++++++++++++++++++++++++++++++-------
 2 files changed, 64 insertions(+), 10 deletions(-)

diff --git a/Documentation/git-daemon.txt b/Documentation/git-daemon.txt
index 3c91db7be..56d54a489 100644
--- a/Documentation/git-daemon.txt
+++ b/Documentation/git-daemon.txt
@@ -20,6 +20,7 @@ SYNOPSIS
 	     [--inetd |
 	      [--listen=<host_or_ipaddr>] [--port=<n>]
 	      [--user=<user> [--group=<group>]]]
+	     [--log-destination=(stderr|syslog|none)]
 	     [<directory>...]
 
 DESCRIPTION
@@ -80,7 +81,8 @@ OPTIONS
 	do not have the 'git-daemon-export-ok' file.
 
 --inetd::
-	Have the server run as an inetd service. Implies --syslog.
+	Have the server run as an inetd service. Implies --syslog (may be
+	overridden with `--log-destination=`).
 	Incompatible with --detach, --port, --listen, --user and --group
 	options.
 
@@ -110,8 +112,28 @@ OPTIONS
 	zero for no limit.
 
 --syslog::
-	Log to syslog instead of stderr. Note that this option does not imply
-	--verbose, thus by default only error conditions will be logged.
+	Short for `--log-destination=syslog`.
+
+--log-destination=<destination>::
+	Send log messages to the specified destination.
+	Note that this option does not imply --verbose,
+	thus by default only error conditions will be logged.
+	The <destination> must be one of:
++
+--
+stderr::
+	Write to standard error.
+	Note that if `--detach` is specified,
+	the process disconnects from the real standard error,
+	making this destination effectively equivalent to `none`.
+syslog::
+	Write to syslog, using the `git-daemon` identifier.
+none::
+	Disable all logging.
+--
++
+The default destination is `syslog` if `--inetd` or `--detach` is specified,
+otherwise `stderr`.
 
 --user-path::
 --user-path=<path>::
diff --git a/daemon.c b/daemon.c
index e37e343d0..fb538e367 100644
--- a/daemon.c
+++ b/daemon.c
@@ -9,7 +9,12 @@
 #define initgroups(x, y) (0) /* nothing */
 #endif
 
-static int log_syslog;
+static enum log_destination {
+	LOG_DESTINATION_UNSET = -1,
+	LOG_DESTINATION_NONE = 0,
+	LOG_DESTINATION_STDERR = 1,
+	LOG_DESTINATION_SYSLOG = 2,
+} log_destination = LOG_DESTINATION_UNSET;
 static int verbose;
 static int reuseaddr;
 static int informative_errors;
@@ -25,6 +30,7 @@ static const char daemon_usage[] =
 "           [--access-hook=<path>]\n"
 "           [--inetd | [--listen=<host_or_ipaddr>] [--port=<n>]\n"
 "                      [--detach] [--user=<user> [--group=<group>]]\n"
+"           [--log-destination=(stderr|syslog|none)]\n"
 "           [<directory>...]";
 
 /* List of acceptable pathname prefixes */
@@ -74,11 +80,14 @@ static const char *get_ip_address(struct hostinfo *hi)
 
 static void logreport(int priority, const char *err, va_list params)
 {
-	if (log_syslog) {
+	switch (log_destination) {
+	case LOG_DESTINATION_SYSLOG: {
 		char buf[1024];
 		vsnprintf(buf, sizeof(buf), err, params);
 		syslog(priority, "%s", buf);
-	} else {
+		break;
+	}
+	case LOG_DESTINATION_STDERR:
 		/*
 		 * Since stderr is set to buffered mode, the
 		 * logging of different processes will not overlap
@@ -88,6 +97,11 @@ static void logreport(int priority, const char *err, va_list params)
 		vfprintf(stderr, err, params);
 		fputc('\n', stderr);
 		fflush(stderr);
+		break;
+	case LOG_DESTINATION_NONE:
+		break;
+	case LOG_DESTINATION_UNSET:
+		BUG("log destination not initialized correctly");
 	}
 }
 
@@ -1289,7 +1303,6 @@ int cmd_main(int argc, const char **argv)
 		}
 		if (!strcmp(arg, "--inetd")) {
 			inetd_mode = 1;
-			log_syslog = 1;
 			continue;
 		}
 		if (!strcmp(arg, "--verbose")) {
@@ -1297,9 +1310,22 @@ int cmd_main(int argc, const char **argv)
 			continue;
 		}
 		if (!strcmp(arg, "--syslog")) {
-			log_syslog = 1;
+			log_destination = LOG_DESTINATION_SYSLOG;
 			continue;
 		}
+		if (skip_prefix(arg, "--log-destination=", &v)) {
+			if (!strcmp(v, "syslog")) {
+				log_destination = LOG_DESTINATION_SYSLOG;
+				continue;
+			} else if (!strcmp(v, "stderr")) {
+				log_destination = LOG_DESTINATION_STDERR;
+				continue;
+			} else if (!strcmp(v, "none")) {
+				log_destination = LOG_DESTINATION_NONE;
+				continue;
+			} else
+				die("unknown log destination '%s'", v);
+		}
 		if (!strcmp(arg, "--export-all")) {
 			export_all_trees = 1;
 			continue;
@@ -1356,7 +1382,6 @@ int cmd_main(int argc, const char **argv)
 		}
 		if (!strcmp(arg, "--detach")) {
 			detach = 1;
-			log_syslog = 1;
 			continue;
 		}
 		if (skip_prefix(arg, "--user=", &v)) {
@@ -1402,7 +1427,14 @@ int cmd_main(int argc, const char **argv)
 		usage(daemon_usage);
 	}
 
-	if (log_syslog) {
+	if (log_destination == LOG_DESTINATION_UNSET) {
+		if (inetd_mode || detach)
+			log_destination = LOG_DESTINATION_SYSLOG;
+		else
+			log_destination = LOG_DESTINATION_STDERR;
+	}
+
+	if (log_destination == LOG_DESTINATION_SYSLOG) {
 		openlog("git-daemon", LOG_PID, LOG_DAEMON);
 		set_die_routine(daemon_die);
 	} else
-- 
2.16.1


^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH v4] daemon: add --log-destination=(stderr|syslog|none)
  2018-02-04 18:30                       ` [PATCH v4] " Lucas Werkmeister
@ 2018-02-04 18:55                         ` Ævar Arnfjörð Bjarmason
  2018-02-04 18:58                           ` Lucas Werkmeister
  2018-02-04 19:44                           ` Eric Sunshine
  2018-02-04 19:36                         ` Eric Sunshine
  1 sibling, 2 replies; 21+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-04 18:55 UTC (permalink / raw)
  To: Lucas Werkmeister; +Cc: Eric Sunshine, Junio C Hamano, git


On Sun, Feb 04 2018, Lucas Werkmeister jotted:

>  	     [--inetd |
>  	      [--listen=<host_or_ipaddr>] [--port=<n>]
>  	      [--user=<user> [--group=<group>]]]
> +	     [--log-destination=(stderr|syslog|none)]

I micronit, but maybe worthwhile to have a preceeding commit to fix up
that indentation of --listen and --user.

> +--log-destination=<destination>::
> +	Send log messages to the specified destination.
> +	Note that this option does not imply --verbose,

Should `` quote --verbose, although I see similar to the WS change I
noted above there's plenty of existing stuff in that doc doing it wrong.
> +			} else
> +				die("unknown log destination '%s'", v);

Should be die(_("unknown..., i.e. use the _() macro.

Anyway, this looks fine to be with our without these proposed
bikeshedding changes above. Thanks.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v4] daemon: add --log-destination=(stderr|syslog|none)
  2018-02-04 18:55                         ` Ævar Arnfjörð Bjarmason
@ 2018-02-04 18:58                           ` Lucas Werkmeister
  2018-02-05 20:09                             ` Ævar Arnfjörð Bjarmason
  2018-02-04 19:44                           ` Eric Sunshine
  1 sibling, 1 reply; 21+ messages in thread
From: Lucas Werkmeister @ 2018-02-04 18:58 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: Eric Sunshine, Junio C Hamano, git

[-- Attachment #1: Type: text/plain, Size: 1261 bytes --]

On 04.02.2018 19:55, Ævar Arnfjörð Bjarmason wrote:
> 
> On Sun, Feb 04 2018, Lucas Werkmeister jotted:
> 
>>  	     [--inetd |
>>  	      [--listen=<host_or_ipaddr>] [--port=<n>]
>>  	      [--user=<user> [--group=<group>]]]
>> +	     [--log-destination=(stderr|syslog|none)]
> 
> I micronit, but maybe worthwhile to have a preceeding commit to fix up
> that indentation of --listen and --user.

I thought the indentation here is intentional, since we’re still inside
the [] pair (either --inetd or --listen, --port, …).

> 
>> +--log-destination=<destination>::
>> +	Send log messages to the specified destination.
>> +	Note that this option does not imply --verbose,
> 
> Should `` quote --verbose, although I see similar to the WS change I
> noted above there's plenty of existing stuff in that doc doing it wrong.

I could send a follow-up to consistently ``-quote all options in
git-daemon.txt… or would that be rejected as unnecessarily cluttering
the history or the `git blame`?

>> +			} else
>> +				die("unknown log destination '%s'", v);
> 
> Should be die(_("unknown..., i.e. use the _() macro.
> 
> Anyway, this looks fine to be with our without these proposed
> bikeshedding changes above. Thanks.
>


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4165 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v4] daemon: add --log-destination=(stderr|syslog|none)
  2018-02-04 18:30                       ` [PATCH v4] " Lucas Werkmeister
  2018-02-04 18:55                         ` Ævar Arnfjörð Bjarmason
@ 2018-02-04 19:36                         ` Eric Sunshine
  2018-02-05 18:31                           ` Junio C Hamano
  1 sibling, 1 reply; 21+ messages in thread
From: Eric Sunshine @ 2018-02-04 19:36 UTC (permalink / raw)
  To: Lucas Werkmeister; +Cc: Junio C Hamano, Git List

On Sun, Feb 4, 2018 at 1:30 PM, Lucas Werkmeister
<mail@lucaswerkmeister.de> wrote:
> This new option can be used to override the implicit --syslog of
> --inetd, or to disable all logging. (While --detach also implies
> --syslog, --log-destination=stderr with --detach is useless since
> --detach disassociates the process from the original stderr.) --syslog
> is retained as an alias for --log-destination=syslog.
> [...]
> Signed-off-by: Lucas Werkmeister <mail@lucaswerkmeister.de>
> ---
> Notes:
>     Fixes log_destination not being initialized correctly and some minor
>     style issues.

Thanks. With the 'log_destination' initialization bug fixed, this
version looks good; I didn't find anything else worth commenting upon.
Ævar's micronits[1] could be addressed by a follow-up patch (if
desirable), but probably needn't hold up this patch.

[1]: https://public-inbox.org/git/871si0mvo0.fsf@evledraar.gmail.com/

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v4] daemon: add --log-destination=(stderr|syslog|none)
  2018-02-04 18:55                         ` Ævar Arnfjörð Bjarmason
  2018-02-04 18:58                           ` Lucas Werkmeister
@ 2018-02-04 19:44                           ` Eric Sunshine
  1 sibling, 0 replies; 21+ messages in thread
From: Eric Sunshine @ 2018-02-04 19:44 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: Lucas Werkmeister, Junio C Hamano, Git List

On Sun, Feb 4, 2018 at 1:55 PM, Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
> On Sun, Feb 04 2018, Lucas Werkmeister jotted:
>>            [--inetd |
>>             [--listen=<host_or_ipaddr>] [--port=<n>]
>>             [--user=<user> [--group=<group>]]]
>> +          [--log-destination=(stderr|syslog|none)]
>
> I micronit, but maybe worthwhile to have a preceeding commit to fix up
> that indentation of --listen and --user.

The '--listen' and '--user' lines are in the "alternate" ('|') branch
of '--inetd' so, as Lucas points out, this indentation appears
intentional, thus seems okay as-is.

>> +--log-destination=<destination>::
>> +     Send log messages to the specified destination.
>> +     Note that this option does not imply --verbose,
>
> Should `` quote --verbose, although I see similar to the WS change I
> noted above there's plenty of existing stuff in that doc doing it wrong.

As you mention, there are plenty of existing offenders already in this
file, so probably not worth a re-roll (perhaps Junio can fix this new
instance locally), but certainly good fodder for a follow-up patch.

>> +                     } else
>> +                             die("unknown log destination '%s'", v);
>
> Should be die(_("unknown..., i.e. use the _() macro.

No message in this source file use _(...) yet so probably not worth a
re-roll, but definitely something for a follow-up patch (by someone).

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v4] daemon: add --log-destination=(stderr|syslog|none)
  2018-02-04 19:36                         ` Eric Sunshine
@ 2018-02-05 18:31                           ` Junio C Hamano
  0 siblings, 0 replies; 21+ messages in thread
From: Junio C Hamano @ 2018-02-05 18:31 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Lucas Werkmeister, Git List

Eric Sunshine <sunshine@sunshineco.com> writes:

> On Sun, Feb 4, 2018 at 1:30 PM, Lucas Werkmeister
> <mail@lucaswerkmeister.de> wrote:
>> This new option can be used to override the implicit --syslog of
>> ...
> Thanks. With the 'log_destination' initialization bug fixed, this
> version looks good; I didn't find anything else worth commenting upon.
> Ævar's micronits[1] could be addressed by a follow-up patch (if
> desirable), but probably needn't hold up this patch.
>
> [1]: https://public-inbox.org/git/871si0mvo0.fsf@evledraar.gmail.com/

Nicely done.  Thanks, all.

Will queue.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v4] daemon: add --log-destination=(stderr|syslog|none)
  2018-02-04 18:58                           ` Lucas Werkmeister
@ 2018-02-05 20:09                             ` Ævar Arnfjörð Bjarmason
  0 siblings, 0 replies; 21+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2018-02-05 20:09 UTC (permalink / raw)
  To: Lucas Werkmeister; +Cc: Eric Sunshine, Junio C Hamano, git


On Sun, Feb 04 2018, Lucas Werkmeister jotted:

> On 04.02.2018 19:55, Ævar Arnfjörð Bjarmason wrote:
>> 
>> On Sun, Feb 04 2018, Lucas Werkmeister jotted:
>> 
>>>  	     [--inetd |
>>>  	      [--listen=<host_or_ipaddr>] [--port=<n>]
>>>  	      [--user=<user> [--group=<group>]]]
>>> +	     [--log-destination=(stderr|syslog|none)]
>> 
>> I micronit, but maybe worthwhile to have a preceeding commit to fix up
>> that indentation of --listen and --user.
>
> I thought the indentation here is intentional, since we’re still inside
> the [] pair (either --inetd or --listen, --port, …).

Yes, sorry. Nevrmind.

>> 
>>> +--log-destination=<destination>::
>>> +	Send log messages to the specified destination.
>>> +	Note that this option does not imply --verbose,
>> 
>> Should `` quote --verbose, although I see similar to the WS change I
>> noted above there's plenty of existing stuff in that doc doing it wrong.
>
> I could send a follow-up to consistently ``-quote all options in
> git-daemon.txt… or would that be rejected as unnecessarily cluttering
> the history or the `git blame`?

I don't think anyone would mind. Tiny doc cleanups are neat-o.

>>> +			} else
>>> +				die("unknown log destination '%s'", v);
>> 
>> Should be die(_("unknown..., i.e. use the _() macro.
>> 
>> Anyway, this looks fine to be with our without these proposed
>> bikeshedding changes above. Thanks.
>>


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2018-02-05 20:09 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-22 23:23 [PATCH] daemon: add --no-syslog to undo implicit --syslog Lucas Werkmeister
2018-01-23  0:00 ` Ævar Arnfjörð Bjarmason
2018-01-23 18:30   ` Junio C Hamano
2018-01-23 22:06     ` Lucas Werkmeister
2018-01-24 10:05       ` Lucas Werkmeister
2018-01-24 18:33       ` Junio C Hamano
2018-01-24 19:48         ` Lucas Werkmeister
2018-01-27 18:31         ` [PATCH v2] daemon: add --send-log-to=(stderr|syslog|none) Lucas Werkmeister
2018-01-28  6:40           ` Eric Sunshine
2018-01-28 22:58             ` Lucas Werkmeister
2018-01-29  0:10               ` Eric Sunshine
2018-02-03 23:08                 ` [PATCH v3] daemon: add --log-destination=(stderr|syslog|none) Lucas Werkmeister
2018-02-04  6:36                   ` Eric Sunshine
2018-02-04 18:29                     ` Lucas Werkmeister
2018-02-04 18:30                       ` [PATCH v4] " Lucas Werkmeister
2018-02-04 18:55                         ` Ævar Arnfjörð Bjarmason
2018-02-04 18:58                           ` Lucas Werkmeister
2018-02-05 20:09                             ` Ævar Arnfjörð Bjarmason
2018-02-04 19:44                           ` Eric Sunshine
2018-02-04 19:36                         ` Eric Sunshine
2018-02-05 18:31                           ` Junio C Hamano

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).