summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b5cf3c8)
raw | patch | inline | side by side (parent: b5cf3c8)
author | Petr Baudis <pasky@suse.cz> | |
Sat, 24 Sep 2005 14:13:01 +0000 (16:13 +0200) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Sat, 24 Sep 2005 18:20:45 +0000 (11:20 -0700) |
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>
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>
Documentation/git-daemon.txt | patch | blob | history | |
daemon.c | patch | blob | history |
index 250e93974044ba678b29db013f2d964c7b6510c5..065f2aa721feef01d57c5dc6ecab79223eda5363 100644 (file)
SYNOPSIS
--------
-'git-daemon' [--verbose] [--inetd | --port=n]
+'git-daemon' [--verbose] [--syslog] [--inetd | --port=n]
DESCRIPTION
-----------
--port::
Listen on an alternative port.
+--syslog::
+ Log to syslog instead of stderr. Note that this option does not imply
+ --verbose, thus by default only error conditions will be logged.
+
--verbose::
Log details about the incoming connections and requested files.
diff --git a/daemon.c b/daemon.c
index b1fd60dd0c6ea5915340675a9f9691b027ca87e5..5547e6432e208633590dc431bf6a891055ba6bc1 100644 (file)
--- a/daemon.c
+++ b/daemon.c
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <syslog.h>
+static int log_syslog;
static int verbose;
-static const char daemon_usage[] = "git-daemon [--verbose] [--inetd | --port=n]";
+static const char daemon_usage[] = "git-daemon [--verbose] [--syslog] [--inetd | --port=n]";
-static void logreport(const char *err, va_list params)
+static void logreport(int priority, const char *err, va_list params)
{
/* We should do a single write so that it is atomic and output
* of several processes do not get intermingled. */
maxlen = sizeof(buf) - buflen - 1; /* -1 for our own LF */
msglen = vsnprintf(buf + buflen, maxlen, err, params);
+ if (log_syslog) {
+ syslog(priority, "%s", buf);
+ return;
+ }
+
/* maxlen counted our own LF but also counts space given to
* vsnprintf for the terminating NUL. We want to make sure that
* we have space for our own LF and NUL after the "meat" of the
{
va_list params;
va_start(params, err);
- logreport(err, params);
+ logreport(LOG_ERR, err, params);
va_end(params);
}
if (!verbose)
return;
va_start(params, err);
- logreport(err, params);
+ logreport(LOG_INFO, err, params);
va_end(params);
}
static void child_handler(int signo)
{
for (;;) {
- pid_t pid = waitpid(-1, NULL, WNOHANG);
+ int status;
+ pid_t pid = waitpid(-1, &status, WNOHANG);
if (pid > 0) {
unsigned reaped = children_reaped;
dead_child[reaped % MAX_CHILDREN] = pid;
children_reaped = reaped + 1;
/* XXX: Custom logging, since we don't wanna getpid() */
- if (verbose)
- fprintf(stderr, "[%d] Disconnected\n", pid);
+ if (verbose) {
+ char *dead = "";
+ if (!WIFEXITED(status) || WEXITSTATUS(status) > 0)
+ dead = " (with error)";
+ if (log_syslog)
+ syslog(LOG_INFO, "[%d] Disconnected%s", pid, dead);
+ else
+ fprintf(stderr, "[%d] Disconnected%s\n", pid, dead);
+ }
continue;
}
break;
verbose = 1;
continue;
}
+ if (!strcmp(arg, "--syslog")) {
+ log_syslog = 1;
+ openlog("git-daemon", 0, LOG_DAEMON);
+ continue;
+ }
usage(daemon_usage);
}