@matheusbsbs / matheus-bagliano / commits / 9048fe1c50
Fork 0

[PATCH] git-daemon --syslog to log through syslog

Well, this makes it even more clear that we need the packet reader and friends to use the daemon logging code. :/ Therefore, we at least indicate in the "Disconnect" log message if the child process exitted with an error code or not. Idea by Linus. Signed-off-by: Petr Baudis <pasky@suse.cz> Signed-off-by: Junio C Hamano <junkio@cox.net>

Petr Baudis committed Sep 24, 2005 at 16:13 UTC 9048fe1c50499d562dcf73094f173b12bdb084c4
2 files changed +32 -8
Documentation/git-daemon.txt
+5 -1
@@ -7,7 +7,7 @@ git-daemon - A really simple server for GIT repositories.
7
8 SYNOPSIS
9 --------
10 -'git-daemon' [--verbose] [--inetd | --port=n]
10 +'git-daemon' [--verbose] [--syslog] [--inetd | --port=n]
11
12 DESCRIPTION
13 -----------
@@ -32,6 +32,10 @@ OPTIONS
32 --port::
33 Listen on an alternative port.
34
35 +--syslog::
36 + Log to syslog instead of stderr. Note that this option does not imply
37 + --verbose, thus by default only error conditions will be logged.
38 +
39 --verbose::
40 Log details about the incoming connections and requested files.
41
daemon.c
+27 -7
@@ -7,13 +7,15 @@
7 #include <netdb.h>
8 #include <netinet/in.h>
9 #include <arpa/inet.h>
10 +#include <syslog.h>
11
12 +static int log_syslog;
13 static int verbose;
14
13 -static const char daemon_usage[] = "git-daemon [--verbose] [--inetd | --port=n]";
15 +static const char daemon_usage[] = "git-daemon [--verbose] [--syslog] [--inetd | --port=n]";
16
17
16 -static void logreport(const char *err, va_list params)
18 +static void logreport(int priority, const char *err, va_list params)
19 {
20 /* We should do a single write so that it is atomic and output
21 * of several processes do not get intermingled. */
@@ -27,6 +29,11 @@ static void logreport(const char *err, va_list params)
29 maxlen = sizeof(buf) - buflen - 1; /* -1 for our own LF */
30 msglen = vsnprintf(buf + buflen, maxlen, err, params);
31
32 + if (log_syslog) {
33 + syslog(priority, "%s", buf);
34 + return;
35 + }
36 +
37 /* maxlen counted our own LF but also counts space given to
38 * vsnprintf for the terminating NUL. We want to make sure that
39 * we have space for our own LF and NUL after the "meat" of the
@@ -48,7 +55,7 @@ void logerror(const char *err, ...)
55 {
56 va_list params;
57 va_start(params, err);
51 - logreport(err, params);
58 + logreport(LOG_ERR, err, params);
59 va_end(params);
60 }
61
@@ -58,7 +65,7 @@ void lognotice(const char *err, ...)
65 if (!verbose)
66 return;
67 va_start(params, err);
61 - logreport(err, params);
68 + logreport(LOG_INFO, err, params);
69 va_end(params);
70 }
71
@@ -285,15 +292,23 @@ static void handle(int incoming, struct sockaddr *addr, int addrlen)
292 static void child_handler(int signo)
293 {
294 for (;;) {
288 - pid_t pid = waitpid(-1, NULL, WNOHANG);
295 + int status;
296 + pid_t pid = waitpid(-1, &status, WNOHANG);
297
298 if (pid > 0) {
299 unsigned reaped = children_reaped;
300 dead_child[reaped % MAX_CHILDREN] = pid;
301 children_reaped = reaped + 1;
302 /* XXX: Custom logging, since we don't wanna getpid() */
295 - if (verbose)
296 - fprintf(stderr, "[%d] Disconnected\n", pid);
303 + if (verbose) {
304 + char *dead = "";
305 + if (!WIFEXITED(status) || WEXITSTATUS(status) > 0)
306 + dead = " (with error)";
307 + if (log_syslog)
308 + syslog(LOG_INFO, "[%d] Disconnected%s", pid, dead);
309 + else
310 + fprintf(stderr, "[%d] Disconnected%s\n", pid, dead);
311 + }
312 continue;
313 }
314 break;
@@ -435,6 +450,11 @@ int main(int argc, char **argv)
450 verbose = 1;
451 continue;
452 }
453 + if (!strcmp(arg, "--syslog")) {
454 + log_syslog = 1;
455 + openlog("git-daemon", 0, LOG_DAEMON);
456 + continue;
457 + }
458
459 usage(daemon_usage);
460 }