From: lon Date: Thu, 5 Oct 2000 19:12:32 +0000 (+0000) Subject: Added logging-to-stderr support (for helping debug and such). X-Git-Tag: nfs-utils-0-3~29 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=0a05810fb40b01d846b4d8e8cbde14ea85598cbc;p=nfs-utils.git Added logging-to-stderr support (for helping debug and such). --- diff --git a/utils/statd/log.c b/utils/statd/log.c index bf66547..91e608a 100644 --- a/utils/statd/log.c +++ b/utils/statd/log.c @@ -2,6 +2,7 @@ * Copyright (C) 1995 Olaf Kirch * Modified by Jeffrey A. Uphoff, 1995, 1997, 1999. * Modified by H.J. Lu, 1998. + * Modified by Lon Hohberger, Oct. 2000 * * NSM for Linux. */ @@ -22,88 +23,69 @@ #include #include #include "log.h" +#include "statd.h" -static char progname[256]; static pid_t mypid; - /* Turns on logging to console/stderr. */ + /* Turns on logging to console/stderr. */ static int opt_debug = 0; /* Will be command-line option, eventually */ -void -log_init(char *name) +void log_init() { - char *sp; - - openlog(name, LOG_PID, LOG_LOCAL5); - if ((sp = strrchr(name, '/')) != NULL) - name = ++sp; - strncpy(progname, name, sizeof (progname) - 1); - progname[sizeof (progname) - 1] = '\0'; - mypid = getpid(); -} + if (!(run_mode & MODE_LOG_STDERR)) + openlog(name_p, LOG_PID, LOG_LOCAL5); -void -log_background(void) -{ - /* NOP */ -} + mypid = getpid(); -void -log_enable(int level) -{ - opt_debug = 1; + log(L_WARNING,"Version %s Starting",version_p); } -int -log_enabled(int level) +void log_background(void) { - return opt_debug; + /* NOP */ } -void -die(char *fmt, ...) +void die(char *fmt, ...) { - char buffer[1024]; - va_list ap; + char buffer[1024]; + va_list ap; - va_start(ap, fmt); - vsnprintf (buffer, 1024, fmt, ap); - va_end(ap); - buffer[1023]=0; + va_start(ap, fmt); + vsnprintf (buffer, 1024, fmt, ap); + va_end(ap); + buffer[1023]=0; - log(L_FATAL, "%s", buffer); + log(L_FATAL, "%s", buffer); #ifndef DEBUG - exit (2); + exit (2); #else - abort(); /* make a core */ + abort(); /* make a core */ #endif } -void -log(int level, char *fmt, ...) +void log(int level, char *fmt, ...) { - char buffer[1024]; - va_list ap; - - va_start(ap, fmt); - vsnprintf (buffer, 1024, fmt, ap); - va_end(ap); - buffer[1023]=0; - - if (level < L_DEBUG) { - syslog(level, "%s", buffer); - } - - if (opt_debug) { - time_t now; - struct tm * tm; - - time(&now); - tm = localtime(&now); - fprintf (stderr, "%02d.%02d.%02d %02d:%02d:%02d %s[%d]: %s\n", - tm->tm_mday, tm->tm_mon, tm->tm_year, + char buffer[1024]; + va_list ap; + + va_start(ap, fmt); + vsnprintf (buffer, 1024, fmt, ap); + va_end(ap); + buffer[1023]=0; + + if ((!(run_mode & MODE_LOG_STDERR)) && (level < L_DEBUG)) { + syslog(level, "%s", buffer); + } else if (run_mode & MODE_LOG_STDERR) { + /* Log everything, including dprintf() stuff to stderr */ + time_t now; + struct tm * tm; + + time(&now); + tm = localtime(&now); + fprintf (stderr, "%02d/%02d/%04d %02d:%02d:%02d %s[%d]: %s\n", + tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900, tm->tm_hour, tm->tm_min, tm->tm_sec, - progname, mypid, + name_p, mypid, buffer); - } + } }