[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>
This commit is contained in:
parent
b5cf3c8b77
commit
9048fe1c50
@ -7,7 +7,7 @@ git-daemon - A really simple server for GIT repositories.
|
|||||||
|
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
--------
|
--------
|
||||||
'git-daemon' [--verbose] [--inetd | --port=n]
|
'git-daemon' [--verbose] [--syslog] [--inetd | --port=n]
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
@ -32,6 +32,10 @@ OPTIONS
|
|||||||
--port::
|
--port::
|
||||||
Listen on an alternative 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::
|
--verbose::
|
||||||
Log details about the incoming connections and requested files.
|
Log details about the incoming connections and requested files.
|
||||||
|
|
||||||
|
34
daemon.c
34
daemon.c
@ -7,13 +7,15 @@
|
|||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
|
static int log_syslog;
|
||||||
static int verbose;
|
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
|
/* We should do a single write so that it is atomic and output
|
||||||
* of several processes do not get intermingled. */
|
* of several processes do not get intermingled. */
|
||||||
@ -27,6 +29,11 @@ static void logreport(const char *err, va_list params)
|
|||||||
maxlen = sizeof(buf) - buflen - 1; /* -1 for our own LF */
|
maxlen = sizeof(buf) - buflen - 1; /* -1 for our own LF */
|
||||||
msglen = vsnprintf(buf + buflen, maxlen, err, params);
|
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
|
/* maxlen counted our own LF but also counts space given to
|
||||||
* vsnprintf for the terminating NUL. We want to make sure that
|
* 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
|
* we have space for our own LF and NUL after the "meat" of the
|
||||||
@ -48,7 +55,7 @@ void logerror(const char *err, ...)
|
|||||||
{
|
{
|
||||||
va_list params;
|
va_list params;
|
||||||
va_start(params, err);
|
va_start(params, err);
|
||||||
logreport(err, params);
|
logreport(LOG_ERR, err, params);
|
||||||
va_end(params);
|
va_end(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +65,7 @@ void lognotice(const char *err, ...)
|
|||||||
if (!verbose)
|
if (!verbose)
|
||||||
return;
|
return;
|
||||||
va_start(params, err);
|
va_start(params, err);
|
||||||
logreport(err, params);
|
logreport(LOG_INFO, err, params);
|
||||||
va_end(params);
|
va_end(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,15 +292,23 @@ static void handle(int incoming, struct sockaddr *addr, int addrlen)
|
|||||||
static void child_handler(int signo)
|
static void child_handler(int signo)
|
||||||
{
|
{
|
||||||
for (;;) {
|
for (;;) {
|
||||||
pid_t pid = waitpid(-1, NULL, WNOHANG);
|
int status;
|
||||||
|
pid_t pid = waitpid(-1, &status, WNOHANG);
|
||||||
|
|
||||||
if (pid > 0) {
|
if (pid > 0) {
|
||||||
unsigned reaped = children_reaped;
|
unsigned reaped = children_reaped;
|
||||||
dead_child[reaped % MAX_CHILDREN] = pid;
|
dead_child[reaped % MAX_CHILDREN] = pid;
|
||||||
children_reaped = reaped + 1;
|
children_reaped = reaped + 1;
|
||||||
/* XXX: Custom logging, since we don't wanna getpid() */
|
/* XXX: Custom logging, since we don't wanna getpid() */
|
||||||
if (verbose)
|
if (verbose) {
|
||||||
fprintf(stderr, "[%d] Disconnected\n", pid);
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -435,6 +450,11 @@ int main(int argc, char **argv)
|
|||||||
verbose = 1;
|
verbose = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!strcmp(arg, "--syslog")) {
|
||||||
|
log_syslog = 1;
|
||||||
|
openlog("git-daemon", 0, LOG_DAEMON);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
usage(daemon_usage);
|
usage(daemon_usage);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user