From f1f1ee3563f792dc0a96430e10c3e9caacf521c6 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sun, 5 Aug 2018 18:54:27 +0200 Subject: [PATCH] Reindent to Linux KNF Most of the code base seemed to follow Linux style, loosely. This patch brings it all together. Signed-off-by: Joachim Nilsson --- src/klogd.c | 889 ++++++++++++--------------- src/klogd.h | 48 +- src/ksym.c | 540 +++++++---------- src/ksym_mod.c | 360 +++++------ src/ksyms.h | 47 +- src/module.h | 54 +- src/oops.c | 231 +++---- src/pidfile.c | 170 +++--- src/pidfile.h | 38 +- src/syslog.c | 117 ++-- src/syslog_tst.c | 52 +- src/syslogd.c | 1504 ++++++++++++++++++++++------------------------ 12 files changed, 1850 insertions(+), 2200 deletions(-) diff --git a/src/klogd.c b/src/klogd.c index 0eb701a..4c7b4fc 100644 --- a/src/klogd.c +++ b/src/klogd.c @@ -255,22 +255,21 @@ * Remove special treatment of the percent sign. */ - /* Includes. */ -#include -#include #include +#include +#include #ifdef SYSV #include #else #include #endif -#include -#include -#include -#include #include "klogd.h" #include "ksyms.h" +#include +#include +#include +#include #ifndef TESTING #include "pidfile.h" #endif @@ -286,194 +285,155 @@ #ifndef TESTING #if defined(FSSTND) -static char *PidFile = _PATH_VARRUN "klogd.pid"; +static char *PidFile = _PATH_VARRUN "klogd.pid"; #else -static char *PidFile = "/etc/klogd.pid"; +static char *PidFile = "/etc/klogd.pid"; #endif #endif -static int kmsg, - change_state = 0, - terminate = 0, - caught_TSTP = 0, - reload_symbols = 0, - console_log_level = -1; +static int kmsg; +static int change_state = 0; +static int terminate = 0; +static int caught_TSTP = 0; +static int reload_symbols = 0; +static int console_log_level = -1; -static int use_syscall = 0, - one_shot = 0, - symbol_lookup = 1, - no_fork = 0; /* don't fork - don't run in daemon mode */ +static int use_syscall = 0; +static int one_shot = 0; +static int symbol_lookup = 1; +static int no_fork = 0; /* don't fork - don't run in daemon mode */ -static char *symfile = (char *) 0, - log_buffer[LOG_BUFFER_SIZE]; +static char *symfile = NULL; +static char log_buffer[LOG_BUFFER_SIZE]; -static FILE *output_file = (FILE *) 0; +static FILE *output_file = NULL; -static enum LOGSRC {none, proc, kernel} logsrc; +static enum LOGSRC { none, proc, kernel } logsrc; -int debugging = 0; +int debugging = 0; int symbols_twice = 0; - /* Function prototypes. */ -extern int ksyslog(int type, char *buf, int len); -static void CloseLogSrc(void); -extern void restart(int sig); -extern void stop_logging(int sig); -extern void stop_daemon(int sig); -extern void reload_daemon(int sig); -static void Terminate(void); -static void SignalDaemon(int); -static void ReloadSymbols(void); -static void ChangeLogging(void); +extern int ksyslog(int type, char *buf, int len); +static void CloseLogSrc(void); +extern void restart(int sig); +extern void stop_logging(int sig); +extern void stop_daemon(int sig); +extern void reload_daemon(int sig); +static void Terminate(void); +static void SignalDaemon(int); +static void ReloadSymbols(void); +static void ChangeLogging(void); static enum LOGSRC GetKernelLogSrc(void); -static void LogLine(char *ptr, int len); -static void LogKernelLine(void); -static void LogProcLine(void); -extern int main(int argc, char *argv[]); - - -static void CloseLogSrc() +static void LogLine(char *ptr, int len); +static void LogKernelLine(void); +static void LogProcLine(void); +extern int main(int argc, char *argv[]); +static void CloseLogSrc(void) { - /* Shutdown the log sources. */ - switch ( logsrc ) - { - case kernel: + /* Shutdown the log sources. */ + switch (logsrc) { + case kernel: ksyslog(0, 0, 0); Syslog(LOG_INFO, "Kernel logging (ksyslog) stopped."); break; - case proc: + + case proc: close(kmsg); Syslog(LOG_INFO, "Kernel logging (proc) stopped."); break; - case none: + + case none: break; } - if ( output_file != (FILE *) 0 ) + if (output_file != (FILE *)0) fflush(output_file); - return; } - /* * Signal handler to terminate the parent process. */ #ifndef TESTING -void doexit(sig) - - int sig; - +void doexit(int signo) { - exit (0); + exit(0); } #endif -void restart(sig) - - int sig; - +void restart(int signo) { signal(SIGCONT, restart); change_state = 1; caught_TSTP = 0; - return; } - -void stop_logging(sig) - - int sig; - +void stop_logging(int signo) { signal(SIGTSTP, stop_logging); change_state = 1; caught_TSTP = 1; - return; } - -void stop_daemon(sig) - - int sig; - +void stop_daemon(int signo) { Terminate(); - return; } - -void reload_daemon(sig) - - int sig; - +void reload_daemon(int signo) { change_state = 1; reload_symbols = 1; - - if ( sig == SIGUSR2 ) - { + if (signo == SIGUSR2) { ++reload_symbols; signal(SIGUSR2, reload_daemon); - } - else + } else signal(SIGUSR1, reload_daemon); - + return; } - -static void Terminate() - +static void Terminate(void) { CloseLogSrc(); Syslog(LOG_INFO, "Kernel log daemon terminating."); sleep(1); - if ( output_file != (FILE *) 0 ) + if (output_file != (FILE *)0) fclose(output_file); closelog(); #ifndef TESTING - (void) remove_pid(PidFile); + (void)remove_pid(PidFile); #endif exit(1); } -static void SignalDaemon(sig) - - int sig; - +static void SignalDaemon(int signo) { #ifndef TESTING - auto int pid = check_pid(PidFile); + int pid = check_pid(PidFile); - kill(pid, sig); + kill(pid, signo); #else - kill(getpid(), sig); + kill(getpid(), signo); #endif - return; } - -static void ReloadSymbols() - +static void ReloadSymbols(void) { if (symbol_lookup) { - if ( reload_symbols > 1 ) + if (reload_symbols > 1) InitKsyms(symfile); InitMsyms(); } reload_symbols = change_state = 0; - return; } - static void ChangeLogging(void) - { /* Terminate kernel logging. */ - if ( terminate == 1 ) + if (terminate == 1) Terminate(); /* Indicate that something is happening. */ @@ -481,21 +441,19 @@ static void ChangeLogging(void) PACKAGE_VERSION); /* Reload symbols. */ - if ( reload_symbols > 0 ) - { + if (reload_symbols > 0) { ReloadSymbols(); return; } /* Stop kernel logging. */ - if ( caught_TSTP == 1 ) - { + if (caught_TSTP == 1) { CloseLogSrc(); logsrc = none; change_state = 0; return; } - + /* * The rest of this function is responsible for restarting * kernel logging after it was stopped. @@ -504,8 +462,7 @@ static void ChangeLogging(void) * kernel log state as to what is causing us to restart. Somewhat * groady but it keeps us from creating another static variable. */ - if ( logsrc != none ) - { + if (logsrc != none) { Syslog(LOG_INFO, "Kernel logging re-started after SIGSTOP."); change_state = 0; return; @@ -514,21 +471,15 @@ static void ChangeLogging(void) /* Restart logging. */ logsrc = GetKernelLogSrc(); change_state = 0; - return; } - static enum LOGSRC GetKernelLogSrc(void) - { - auto struct stat sb; - + struct stat sb; /* Set level of kernel console messaging.. */ - if ( (console_log_level != -1) - && (ksyslog(8, NULL, console_log_level) < 0) && \ - (errno == EINVAL) ) - { + if ((console_log_level != -1) && (ksyslog(8, NULL, console_log_level) < 0) && + (errno == EINVAL)) { /* * An invalid arguement error probably indicates that * a pre-0.14 kernel is being run. At this point we @@ -536,28 +487,28 @@ static enum LOGSRC GetKernelLogSrc(void) * logging completely. */ Syslog(LOG_WARNING, "Cannot set console log level - disabling " - "console output."); + "console output."); } /* * First do a stat to determine whether or not the proc based * file system is available to get kernel messages from. */ - if ( use_syscall || - ((stat(_PATH_KLOG, &sb) < 0) && (errno == ENOENT)) ) - { - /* Initialize kernel logging. */ - ksyslog(1, NULL, 0); + if (use_syscall || + ((stat(_PATH_KLOG, &sb) < 0) && (errno == ENOENT))) { + /* Initialize kernel logging. */ + ksyslog(1, NULL, 0); Syslog(LOG_INFO, "klogd v%s, log source = ksyslog " - "started.", PACKAGE_VERSION); - return(kernel); + "started.", + PACKAGE_VERSION); + return (kernel); } #ifndef TESTING - if ( (kmsg = open(_PATH_KLOG, O_RDONLY)) < 0 ) - { - fprintf(stderr, "klogd: Cannot open proc file system, " \ - "%d - %s.\n", errno, strerror(errno)); + if ((kmsg = open(_PATH_KLOG, O_RDONLY)) < 0) { + fprintf(stderr, "klogd: Cannot open proc file system, " + "%d - %s.\n", + errno, strerror(errno)); ksyslog(7, NULL, 0); exit(1); } @@ -567,26 +518,23 @@ static enum LOGSRC GetKernelLogSrc(void) Syslog(LOG_INFO, "klogd v%s, log source = %s started.", VERSION, _PATH_KLOG); - return(proc); + return (proc); } - extern void Syslog(int priority, char *fmt, ...) { va_list ap; char *argl; - if ( debugging ) - { + if (debugging) { fputs("Logging line:\n", stderr); fprintf(stderr, "\tLine: %s\n", fmt); fprintf(stderr, "\tPriority: %d\n", priority); } /* Handle output to a file. */ - if ( output_file != (FILE *) 0 ) - { + if (output_file != (FILE *)0) { va_start(ap, fmt); vfprintf(output_file, fmt, ap); va_end(ap); @@ -596,16 +544,13 @@ extern void Syslog(int priority, char *fmt, ...) fsync(fileno(output_file)); return; } - + /* Output using syslog. */ - if (!strcmp(fmt, "%s")) - { + if (!strcmp(fmt, "%s")) { va_start(ap, fmt); argl = va_arg(ap, char *); - if (argl[0] == '<' && argl[1] && argl[2] == '>') - { - switch ( argl[1] ) - { + if (argl[0] == '<' && argl[1] && argl[2] == '>') { + switch (argl[1]) { case '0': priority = LOG_EMERG; break; @@ -645,13 +590,10 @@ extern void Syslog(int priority, char *fmt, ...) vsyslog(priority, fmt, ap); va_end(ap); #ifdef TESTING - printf ("\n"); + printf("\n"); #endif - - return; } - /* * Copy characters from ptr to line until a char in the delim * string is encountered or until min( space, len ) chars have @@ -659,18 +601,19 @@ extern void Syslog(int priority, char *fmt, ...) * * Returns the actual number of chars copied. */ -static int copyin( char *line, int space, - const char *ptr, int len, - const char *delim ) +static int copyin(char *line, int space, + const char *ptr, int len, + const char *delim) { - auto int i; - auto int count; + int i; + int count; - count = len < space ? len : space; + count = len < space ? len : space; - for(i=0; i 0 ) - { - if( space == 0 ) /* line buffer is full */ - { - /* - ** Line too long. Start a new line. - */ - *line = 0; /* force null terminator */ + while (len > 0) { + if (space == 0) { /* line buffer is full */ + /* + ** Line too long. Start a new line. + */ + *line = 0; /* force null terminator */ - if ( debugging ) - { - fputs("Line buffer full:\n", stderr); - fprintf(stderr, "\tLine: %s\n", line); - } + if (debugging) { + fputs("Line buffer full:\n", stderr); + fprintf(stderr, "\tLine: %s\n", line); + } - Syslog( LOG_INFO, "%s", line_buff ); - line = line_buff; - space = sizeof(line_buff)-1; - parse_state = PARSING_TEXT; - symbols_expanded = 0; - skip_symbol_lookup = 0; - save_ptr = ptr; - save_len = len; - } + Syslog(LOG_INFO, "%s", line_buff); + line = line_buff; + space = sizeof(line_buff) - 1; + parse_state = PARSING_TEXT; + symbols_expanded = 0; + skip_symbol_lookup = 0; + save_ptr = ptr; + save_len = len; + } - switch( parse_state ) - { - case PARSING_TEXT: - delta = copyin( line, space, ptr, len, "\n[" ); - line += delta; - ptr += delta; - space -= delta; - len -= delta; + switch (parse_state) { + case PARSING_TEXT: + delta = copyin(line, space, ptr, len, "\n["); + line += delta; + ptr += delta; + space -= delta; + len -= delta; - if( space == 0 || len == 0 ) - { - break; /* full line_buff or end of input buffer */ - } + if (space == 0 || len == 0) + break; /* full line_buff or end of input buffer */ - if( *ptr == '\0' ) /* zero byte */ - { - ptr++; /* skip zero byte */ - space -= 1; - len -= 1; + if (*ptr == '\0') { /* zero byte */ + ptr++; /* skip zero byte */ + space -= 1; + len -= 1; - break; - } + break; + } - if( *ptr == '\n' ) /* newline */ - { - ptr++; /* skip newline */ - space -= 1; - len -= 1; + if (*ptr == '\n') { /* newline */ + ptr++; /* skip newline */ + space -= 1; + len -= 1; - *line = 0; /* force null terminator */ - Syslog( LOG_INFO, "%s", line_buff ); - line = line_buff; - space = sizeof(line_buff)-1; - if (symbols_twice) { - if (symbols_expanded) { - /* reprint this line without symbol lookup */ - symbols_expanded = 0; - skip_symbol_lookup = 1; - ptr = save_ptr; - len = save_len; - } - else - { - skip_symbol_lookup = 0; - save_ptr = ptr; - save_len = len; - } - } - break; - } - if( *ptr == '[' ) /* possible kernel symbol */ - { - *line++ = *ptr++; - space -= 1; - len -= 1; - if (!skip_symbol_lookup) - parse_state = PARSING_SYMSTART; /* at < */ - break; - } - break; - - case PARSING_SYMSTART: - if( *ptr != '<' ) - { - parse_state = PARSING_TEXT; /* not a symbol */ - break; - } + *line = 0; /* force null terminator */ + Syslog(LOG_INFO, "%s", line_buff); + line = line_buff; + space = sizeof(line_buff) - 1; + if (symbols_twice) { + if (symbols_expanded) { + /* reprint this line without symbol lookup */ + symbols_expanded = 0; + skip_symbol_lookup = 1; + ptr = save_ptr; + len = save_len; + } else { + skip_symbol_lookup = 0; + save_ptr = ptr; + save_len = len; + } + } + break; + } + if (*ptr == '[') { /* possible kernel symbol */ + *line++ = *ptr++; + space -= 1; + len -= 1; + if (!skip_symbol_lookup) + parse_state = PARSING_SYMSTART; /* at < */ + break; + } + break; - /* - ** Save this character for now. If this turns out to - ** be a valid symbol, this char will be replaced later. - ** If not, we'll just leave it there. - */ + case PARSING_SYMSTART: + if (*ptr != '<') { + parse_state = PARSING_TEXT; /* not a symbol */ + break; + } - sym_start = line; /* this will point at the '<' */ + /* + ** Save this character for now. If this turns out to + ** be a valid symbol, this char will be replaced later. + ** If not, we'll just leave it there. + */ + sym_start = line; /* this will point at the '<' */ - *line++ = *ptr++; - space -= 1; - len -= 1; - parse_state = PARSING_SYMBOL; /* symbol... */ - break; + *line++ = *ptr++; + space -= 1; + len -= 1; + parse_state = PARSING_SYMBOL; /* symbol... */ + break; - case PARSING_SYMBOL: - delta = copyin( line, space, ptr, len, ">\n[" ); - line += delta; - ptr += delta; - space -= delta; - len -= delta; - if( space == 0 || len == 0 ) - { - break; /* full line_buff or end of input buffer */ - } - if( *ptr != '>' ) - { - parse_state = PARSING_TEXT; - break; - } + case PARSING_SYMBOL: + delta = copyin(line, space, ptr, len, ">\n["); + line += delta; + ptr += delta; + space -= delta; + len -= delta; + if (space == 0 || len == 0) + break; /* full line_buff or end of input buffer */ - *line++ = *ptr++; /* copy the '>' */ - space -= 1; - len -= 1; + if (*ptr != '>') { + parse_state = PARSING_TEXT; + break; + } - parse_state = PARSING_SYMEND; + *line++ = *ptr++; /* copy the '>' */ + space -= 1; + len -= 1; - break; + parse_state = PARSING_SYMEND; + break; - case PARSING_SYMEND: - if( *ptr != ']' ) - { - parse_state = PARSING_TEXT; /* not a symbol */ - break; - } + case PARSING_SYMEND: + if (*ptr != ']') { + parse_state = PARSING_TEXT; /* not a symbol */ + break; + } - /* - ** It's really a symbol! Replace address with the - ** symbol text. - */ - { - auto int sym_space; + /* + ** It's really a symbol! Replace address with the + ** symbol text. + */ + { + unsigned long value; + struct symbol sym; + char *symbol; + int sym_space; - unsigned long value; - auto struct symbol sym; - auto char *symbol; + *(line - 1) = 0; /* null terminate the address string */ + value = strtoul(sym_start + 1, (char **)0, 16); + *(line - 1) = '>'; /* put back delim */ - *(line-1) = 0; /* null terminate the address string */ - value = strtoul(sym_start+1, (char **) 0, 16); - *(line-1) = '>'; /* put back delim */ + symbol = LookupSymbol(value, &sym); + if (!symbol_lookup || symbol == (char *)0) { + parse_state = PARSING_TEXT; + break; + } - symbol = LookupSymbol(value, &sym); - if ( !symbol_lookup || symbol == (char *) 0 ) - { - parse_state = PARSING_TEXT; - break; - } + /* + ** verify there is room in the line buffer + */ + sym_space = space + (line - sym_start); + if (sym_space < strlen(symbol) + 30) { /*(30 should be overkill)*/ + parse_state = PARSING_TEXT; /* not enough space */ + break; + } - /* - ** verify there is room in the line buffer - */ - sym_space = space + ( line - sym_start ); - if( sym_space < strlen(symbol) + 30 ) /*(30 should be overkill)*/ - { - parse_state = PARSING_TEXT; /* not enough space */ - break; - } + delta = sprintf(sym_start, "%s+0x%x/0x%02x]", + symbol, sym.offset, sym.size); - delta = sprintf( sym_start, "%s+0x%x/0x%02x]", - symbol, sym.offset, sym.size ); + space = sym_space + delta; + line = sym_start + delta; + symbols_expanded = 1; + } + ptr++; + len--; + parse_state = PARSING_TEXT; + break; - space = sym_space + delta; - line = sym_start + delta; - symbols_expanded = 1; - } - ptr++; - len--; - parse_state = PARSING_TEXT; - break; - - default: /* Can't get here! */ - parse_state = PARSING_TEXT; - - } - } - - return; + default: /* Can't get here! */ + parse_state = PARSING_TEXT; + break; + } + } } - static void LogKernelLine(void) - { - auto int rdcnt; + int rdcnt; /* * Zero-fill the log buffer. This should cure a multitude of @@ -919,23 +838,21 @@ static void LogKernelLine(void) * messages into this fresh buffer. */ memset(log_buffer, '\0', sizeof(log_buffer)); - if ( (rdcnt = ksyslog(2, log_buffer, sizeof(log_buffer)-1)) < 0 ) - { - if ( errno == EINTR ) + if ((rdcnt = ksyslog(2, log_buffer, sizeof(log_buffer) - 1)) < 0) { + if (errno == EINTR) return; - fprintf(stderr, "klogd: Error return from sys_sycall: " \ - "%d - %s\n", errno, strerror(errno)); + fprintf(stderr, + "klogd: Error return from sys_sycall: %d - %s\n", + errno, strerror(errno)); + return; } - else - LogLine(log_buffer, rdcnt); - return; + + LogLine(log_buffer, rdcnt); } - static void LogProcLine(void) - { - auto int rdcnt; + int rdcnt; /* * Zero-fill the log buffer. This should cure a multitude of @@ -944,130 +861,133 @@ static void LogProcLine(void) * from the message pseudo-file into this fresh buffer. */ memset(log_buffer, '\0', sizeof(log_buffer)); - if ( (rdcnt = read(kmsg, log_buffer, sizeof(log_buffer)-1)) < 0 ) - { - if ( errno == EINTR ) + if ((rdcnt = read(kmsg, log_buffer, sizeof(log_buffer) - 1)) < 0) { + if (errno == EINTR) return; - Syslog(LOG_ERR, "Cannot read proc file system: %d - %s.", \ + Syslog(LOG_ERR, "Cannot read proc file system: %d - %s.", errno, strerror(errno)); + return; } - else - LogLine(log_buffer, rdcnt); - return; + LogLine(log_buffer, rdcnt); } - int usage(int code) { fprintf(stdout, - "Usage:\n" - " klogd [-2diInopsvx?] [-c NUM] [-f FILE] [-k FILE]\n" - "\n" - "Options:\n" - " -? Show this help text\n" - " -2 Print line twice if symbols are successfully expanded\n" - " -c NUM Set default log level of console messages to NUM (1-8)\n" - " -d Enable debug mode\n" - " -f FILE Log messages to FILE rather than the syslog facility\n" - " -i Signal klogd to reload kernel module symbols\n" - " -I Signal klogd to reload kernel module *and* static kernel symbols\n" - " -k FILE Location of kernel symbols (System.map), default: auto\n" - " -n Run in foreground, required when run from a modern init/supervisor\n" - " -o Run once, read kernel log messages and syslog them, then exit\n" - " -p Paranoia mode, forces klogd to reload all kernel symbols on Ooops\n" - " -s Force use of system call interface to kernel message buffers\n" - " -v Show program version and exit\n" - " -x Omit EIP translation, i.e. do not read System.map file\n" - "\n" - "Bug report address: %s\n", PACKAGE_BUGREPORT); + "Usage:\n" + " klogd [-2diInopsvx?] [-c NUM] [-f FILE] [-k FILE]\n" + "\n" + "Options:\n" + " -? Show this help text\n" + " -2 Print line twice if symbols are successfully expanded\n" + " -c NUM Set default log level of console messages to NUM (1-8)\n" + " -d Enable debug mode\n" + " -f FILE Log messages to FILE rather than the syslog facility\n" + " -i Signal klogd to reload kernel module symbols\n" + " -I Signal klogd to reload kernel module *and* static kernel symbols\n" + " -k FILE Location of kernel symbols (System.map), default: auto\n" + " -n Run in foreground, required when run from a modern init/supervisor\n" + " -o Run once, read kernel log messages and syslog them, then exit\n" + " -p Paranoia mode, forces klogd to reload all kernel symbols on Ooops\n" + " -s Force use of system call interface to kernel message buffers\n" + " -v Show program version and exit\n" + " -x Omit EIP translation, i.e. do not read System.map file\n" + "\n" + "Bug report address: %s\n", + PACKAGE_BUGREPORT); exit(code); } - -int main(argc, argv) - - int argc; - - char *argv[]; - +int main(int argc, char *argv[]) { - auto int ch, - use_output = 0; - - auto char *log_level = (char *) 0, - *output = (char *) 0; - + char *log_level = NULL; + char *output = NULL; + int use_output = 0; + int ch; #ifndef TESTING pid_t ppid = getpid(); - chdir ("/"); + + chdir("/"); #endif + /* Parse the command-line. */ - while ((ch = getopt(argc, argv, "c:df:iIk:nopsvx2?")) != EOF) - switch((char)ch) - { - case '2': /* Print lines with symbols twice. */ + while ((ch = getopt(argc, argv, "c:df:iIk:nopsvx2?")) != EOF) { + switch (ch) { + case '2': /* Print lines with symbols twice. */ symbols_twice = 1; break; - case 'c': /* Set console message level. */ + + case 'c': /* Set console message level. */ log_level = optarg; break; - case 'd': /* Activity debug mode. */ + + case 'd': /* Activity debug mode. */ debugging = 1; break; - case 'f': /* Define an output file. */ + + case 'f': /* Define an output file. */ output = optarg; use_output++; break; - case 'i': /* Reload module symbols. */ + + case 'i': /* Reload module symbols. */ SignalDaemon(SIGUSR1); - return(0); - case 'I': + return (0); + + case 'I': SignalDaemon(SIGUSR2); - return(0); - case 'k': /* Kernel symbol file. */ + return (0); + + case 'k': /* Kernel symbol file. */ symfile = optarg; break; - case 'n': /* don't fork */ + + case 'n': /* don't fork */ no_fork++; break; - case 'o': /* One-shot mode. */ + + case 'o': /* One-shot mode. */ one_shot = 1; break; - case 'p': - SetParanoiaLevel(1); /* Load symbols on oops. */ - break; - case 's': /* Use syscall interface. */ + + case 'p': + SetParanoiaLevel(1); /* Load symbols on oops. */ + break; + + case 's': /* Use syscall interface. */ use_syscall = 1; break; - case 'v': + + case 'v': printf("klogd v%s\n", VERSION); - exit (1); - case 'x': + exit(1); + + case 'x': symbol_lookup = 0; break; - case '?': + + case '?': usage(0); break; - default: + + default: usage(1); break; } - + } /* Set console logging level. */ - if ( log_level != (char *) 0 ) - { - if ( (strlen(log_level) > 1) || \ - (strchr("12345678", *log_level) == (char *) 0) ) - { + if (log_level != (char *)0) { + if ((strlen(log_level) > 1) || + (strchr("12345678", *log_level) == (char *)0)) { fprintf(stderr, "klogd: Invalid console logging " - "level <%s> specified.\n", log_level); - return(1); + "level <%s> specified.\n", + log_level); + return (1); } console_log_level = *log_level - '0'; - } - + } #ifndef TESTING /* @@ -1081,31 +1001,25 @@ int main(argc, argv) * not disabled with the command line argument and there's no * such process running. */ - if ( (!one_shot) && (!no_fork) ) - { - if (!check_pid(PidFile)) - { - signal (SIGTERM, doexit); - if ( fork() == 0 ) - { - auto int fl; + if ((!one_shot) && (!no_fork)) { + if (!check_pid(PidFile)) { + signal(SIGTERM, doexit); + if (fork() == 0) { int num_fds = getdtablesize(); + int fl; + + signal(SIGTERM, SIG_DFL); - signal (SIGTERM, SIG_DFL); - /* This is the child closing its file descriptors. */ - for (fl= 0; fl <= num_fds; ++fl) - { - if ( fileno(stdout) == fl && use_output ) - if ( strcmp(output, "-") == 0 ) + for (fl = 0; fl <= num_fds; ++fl) { + if (fileno(stdout) == fl && use_output) + if (strcmp(output, "-") == 0) continue; close(fl); } - + setsid(); - } - else - { + } else { /* * Parent process */ @@ -1115,30 +1029,24 @@ int main(argc, argv) */ exit(1); } - } - else - { + } else { fputs("klogd: Already running.\n", stderr); exit(1); } } - /* tuck my process id away */ - if (!check_pid(PidFile)) - { + if (!check_pid(PidFile)) { if (!write_pid(PidFile)) Terminate(); - } - else - { + } else { fputs("klogd: Already running.\n", stderr); Terminate(); } -#endif +#endif /* Signal setups. */ - for (ch= 1; ch < NSIG; ++ch) + for (ch = 1; ch < NSIG; ++ch) signal(ch, SIG_IGN); signal(SIGINT, stop_daemon); signal(SIGKILL, stop_daemon); @@ -1149,31 +1057,26 @@ int main(argc, argv) signal(SIGUSR1, reload_daemon); signal(SIGUSR2, reload_daemon); - /* Open outputs. */ - if ( use_output ) - { - if ( strcmp(output, "-") == 0 ) + if (use_output) { + if (strcmp(output, "-") == 0) output_file = stdout; - else if ( (output_file = fopen(output, "w")) == (FILE *) 0 ) - { - fprintf(stderr, "klogd: Cannot open output file " \ - "%s - %s\n", output, strerror(errno)); - return(1); + else if ((output_file = fopen(output, "w")) == (FILE *)0) { + fprintf(stderr, "klogd: Cannot open output file " + "%s - %s\n", + output, strerror(errno)); + return (1); } - } - else + } else openlog("kernel", 0, LOG_KERN); - /* Handle one-shot logging. */ - if ( one_shot ) - { + if (one_shot) { if (symbol_lookup) { InitKsyms(symfile); InitMsyms(); } - if ( (logsrc = GetKernelLogSrc()) == kernel ) + if ((logsrc = GetKernelLogSrc()) == kernel) LogKernelLine(); else LogProcLine(); @@ -1192,33 +1095,33 @@ int main(argc, argv) #ifndef TESTING if (getpid() != ppid) - kill (ppid, SIGTERM); + kill(ppid, SIGTERM); #endif - /* The main loop. */ - while (1) - { - if ( change_state ) + /* The main loop. */ + while (1) { + if (change_state) ChangeLogging(); - switch ( logsrc ) - { - case kernel: - LogKernelLine(); - break; - case proc: - LogProcLine(); - break; - case none: - pause(); - break; + + switch (logsrc) { + case kernel: + LogKernelLine(); + break; + + case proc: + LogProcLine(); + break; + + case none: + pause(); + break; } } } /** - * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 + * Local Variables: + * indent-tabs-mode: t + * c-file-style: "linux" * End: */ diff --git a/src/klogd.h b/src/klogd.h index ef60f08..a741bba 100644 --- a/src/klogd.h +++ b/src/klogd.h @@ -1,23 +1,23 @@ /* - klogd.h - main header file for Linux kernel log daemon. - Copyright (c) 1995 Dr. G.W. Wettstein - - This file is part of the sysklogd package, a kernel and system log daemon. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ + * klogd.h - main header file for Linux kernel log daemon. + * Copyright (c) 1995 Dr. G.W. Wettstein + * + * This file is part of the sysklogd package, a kernel and system log daemon. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ /* * Symbols and definitions needed by klogd. @@ -33,8 +33,8 @@ /* Function prototypes. */ -extern int InitKsyms(char *); -extern int InitMsyms(void); -extern char * ExpandKadds(char *, char *); -extern void SetParanoiaLevel(int); -extern void Syslog(int priority, char *fmt, ...); +extern int InitKsyms(char *); +extern int InitMsyms(void); +extern char *ExpandKadds(char *, char *); +extern void SetParanoiaLevel(int); +extern void Syslog(int priority, char *fmt, ...); diff --git a/src/ksym.c b/src/ksym.c index bd48084..f467eaf 100644 --- a/src/ksym.c +++ b/src/ksym.c @@ -125,34 +125,31 @@ * the first hit. */ - /* Includes. */ -#include -#include -#include #include "klogd.h" #include "ksyms.h" #include "module.h" +#include +#include +#include #define VERBOSE_DEBUGGING 0 - -int num_syms = 0; -static int i_am_paranoid = 0; -static char vstring[12]; -static struct sym_table *sym_array = (struct sym_table *) 0; +int num_syms = 0; +static int i_am_paranoid = 0; +static char vstring[12]; +static struct sym_table *sym_array = (struct sym_table *)0; static char *system_maps[] = -{ - "/boot/System.map", - "/System.map", - "/usr/src/linux/System.map", + { + "/boot/System.map", + "/System.map", + "/usr/src/linux/System.map", #if defined(TEST) - "./System.map", + "./System.map", #endif - (char *) 0 -}; - + (char *)0 + }; #if defined(TEST) int debugging; @@ -160,14 +157,12 @@ int debugging; extern int debugging; #endif - /* Function prototypes. */ -static char * FindSymbolFile(void); -static int AddSymbol(unsigned long, char*); -static void FreeSymbols(void); -static int CheckVersion(char *); -static int CheckMapVersion(char *); - +static char *FindSymbolFile(void); +static int AddSymbol(unsigned long, char *); +static void FreeSymbols(void); +static int CheckVersion(char *); +static int CheckMapVersion(char *); /************************************************************************** * Function: InitKsyms @@ -186,47 +181,35 @@ static int CheckMapVersion(char *); * A boolean style context is returned. The return value will * be true if initialization was successful. False if not. **************************************************************************/ - -extern int InitKsyms(mapfile) - - char *mapfile; - +int InitKsyms(char *mapfile) { - auto char type, - sym[512]; - - auto int version = 0; - - auto unsigned long int address; - - auto FILE *sym_file; - + unsigned long int address; + FILE *sym_file; + char sym[512]; + char type; + int version = 0; /* Check and make sure that we are starting with a clean slate. */ - if ( num_syms > 0 ) + if (num_syms > 0) FreeSymbols(); - /* * Search for and open the file containing the kernel symbols. */ - if ( mapfile == (char *) 0 ) - { - if ( (mapfile = FindSymbolFile()) == (char *) 0 ) - { + if (mapfile == NULL) { + if ((mapfile = FindSymbolFile()) == NULL) { Syslog(LOG_WARNING, "Cannot find a map file."); - if ( debugging ) + if (debugging) fputs("Cannot find a map file.\n", stderr); - return(0); + return (0); } } - - if ( (sym_file = fopen(mapfile, "r")) == (FILE *) 0 ) - { + + if ((sym_file = fopen(mapfile, "r")) == NULL) { Syslog(LOG_WARNING, "Cannot open map file: %s.", mapfile); - if ( debugging ) + if (debugging) fprintf(stderr, "Cannot open map file: %s.\n", mapfile); - return(0); + return (0); } /* @@ -237,53 +220,46 @@ extern int InitKsyms(mapfile) * e-mail me a diff containing a parser with suitable political * correctness -- GW. */ - while ( !feof(sym_file) ) - { - if ( fscanf(sym_file, "%lx %c %511s\n", &address, &type, sym) - != 3 ) - { + while (!feof(sym_file)) { + if (fscanf(sym_file, "%lx %c %511s\n", &address, &type, sym) != 3) { Syslog(LOG_ERR, "Error in symbol table input (#1)."); fclose(sym_file); - return(0); + return (0); } - if ( VERBOSE_DEBUGGING && debugging ) + if (VERBOSE_DEBUGGING && debugging) fprintf(stderr, "Address: %lx, Type: %c, Symbol: %s\n", - address, type, sym); + address, type, sym); - if ( AddSymbol(address, sym) == 0 ) - { + if (AddSymbol(address, sym) == 0) { Syslog(LOG_ERR, "Error adding symbol - %s.", sym); fclose(sym_file); - return(0); + return (0); } - if ( version == 0 ) + if (version == 0) version = CheckVersion(sym); } - Syslog(LOG_INFO, "Loaded %d symbols from %s.", num_syms, mapfile); - switch ( version ) - { - case -1: + switch (version) { + case -1: Syslog(LOG_WARNING, "Symbols do not match kernel version."); num_syms = 0; break; - case 0: - Syslog(LOG_WARNING, "Cannot verify that symbols match " \ - "kernel version."); + case 0: + Syslog(LOG_WARNING, "Cannot verify that symbols match " + "kernel version."); break; - - case 1: + + case 1: Syslog(LOG_INFO, "Symbols match kernel version %s.", vstring); break; } - - fclose(sym_file); - return(1); -} + fclose(sym_file); + return (1); +} /************************************************************************** * Function: FindSymbolFile @@ -317,61 +293,53 @@ extern int InitKsyms(mapfile) * caller which points to the name of the file containing * the symbol table to be used. **************************************************************************/ - -static char * FindSymbolFile() - +static char *FindSymbolFile(void) { - auto char *file = (char *) 0, - **mf = system_maps; - - auto struct utsname utsname; static char symfile[100]; + struct utsname utsname; + FILE *sym_file = NULL; + char **mf = system_maps; + char *file = NULL; - auto FILE *sym_file = (FILE *) 0; + if (uname(&utsname) < 0) { + Syslog(LOG_ERR, "Cannot get kernel version information."); + return (0); + } - if ( uname(&utsname) < 0 ) - { - Syslog(LOG_ERR, "Cannot get kernel version information."); - return(0); - } - - if ( debugging ) + if (debugging) fputs("Searching for symbol map.\n", stderr); - - for (mf = system_maps; *mf != (char *) 0 && file == (char *) 0; ++mf) - { - - sprintf (symfile, "%s-%s", *mf, utsname.release); - if ( debugging ) + + for (mf = system_maps; *mf != (char *)0 && file == (char *)0; ++mf) { + + sprintf(symfile, "%s-%s", *mf, utsname.release); + if (debugging) fprintf(stderr, "Trying %s.\n", symfile); - if ( (sym_file = fopen(symfile, "r")) != (FILE *) 0 ) { + if ((sym_file = fopen(symfile, "r")) != (FILE *)0) { if (CheckMapVersion(symfile) == 1) file = symfile; - fclose (sym_file); + fclose(sym_file); } - if (sym_file == (FILE *) 0 || file == (char *) 0) { - sprintf (symfile, "%s", *mf); - if ( debugging ) + if (sym_file == (FILE *)0 || file == (char *)0) { + sprintf(symfile, "%s", *mf); + if (debugging) fprintf(stderr, "Trying %s.\n", symfile); - if ( (sym_file = fopen(symfile, "r")) != (FILE *) 0 ) { + if ((sym_file = fopen(symfile, "r")) != (FILE *)0) { if (CheckMapVersion(symfile) == 1) file = symfile; - fclose (sym_file); + fclose(sym_file); } } - } /* * At this stage of the game we are at the end of the symbol * tables. */ - if ( debugging ) + if (debugging) fprintf(stderr, "End of search list encountered.\n"); - return(file); + return (file); } - /************************************************************************** * Function: CheckVersion * @@ -408,34 +376,25 @@ static char * FindSymbolFile() * 1:-> The executing kernel is of the same version * as the version string. **************************************************************************/ - -static int CheckVersion(version) - - char *version; - - +static int CheckVersion(char *version) { - auto int vnum, - major, - minor, - patch; - + static char *prefix = { "Version_" }; + int vnum; + int major; + int minor; + int patch; #ifndef TESTING + struct utsname utsname; int kvnum; - auto struct utsname utsname; #endif - static char *prefix = { "Version_" }; - - /* Early return if there is no hope. */ - if ( strncmp(version, prefix, strlen(prefix)) == 0 /* ELF */ || - (*version == '_' && - strncmp(++version, prefix, strlen(prefix)) == 0 ) /* a.out */ ) + if (strncmp(version, prefix, strlen(prefix)) == 0 /* ELF */ || + (*version == '_' && + strncmp(++version, prefix, strlen(prefix)) == 0) /* a.out */) ; else - return(0); - + return (0); /* * Since the symbol looks like a kernel version we can start @@ -446,11 +405,13 @@ static int CheckVersion(version) patch = vnum & 0x000000FF; minor = (vnum >> 8) & 0x000000FF; major = (vnum >> 16) & 0x000000FF; - if ( debugging ) - fprintf(stderr, "Version string = %s, Major = %d, " \ - "Minor = %d, Patch = %d.\n", version + - strlen(prefix), major, minor, \ - patch); + if (debugging) + fprintf(stderr, "Version string = %s, Major = %d, " + "Minor = %d, Patch = %d.\n", + version + + strlen(prefix), + major, minor, + patch); sprintf(vstring, "%d.%d.%d", major, minor, patch); #ifndef TESTING @@ -461,35 +422,32 @@ static int CheckVersion(version) * values to determine if our system map matches the kernel * version level. */ - if ( uname(&utsname) < 0 ) - { + if (uname(&utsname) < 0) { Syslog(LOG_ERR, "Cannot get kernel version information."); - return(0); + return (0); } - if ( debugging ) - fprintf(stderr, "Comparing kernel %s with symbol table %s.\n",\ - utsname.release, vstring); + if (debugging) + fprintf(stderr, "Comparing kernel %s with symbol table %s.\n", + utsname.release, vstring); - if ( sscanf (utsname.release, "%d.%d.%d", &major, &minor, &patch) < 3 ) - { + if (sscanf(utsname.release, "%d.%d.%d", &major, &minor, &patch) < 3) { Syslog(LOG_ERR, "Kernel send bogus release string `%s'.", utsname.release); - return(0); + return (0); } /* Compute the version code from data sent by the kernel */ kvnum = (major << 16) | (minor << 8) | patch; /* Failure. */ - if ( vnum != kvnum ) - return(-1); + if (vnum != kvnum) + return (-1); - /* Success. */ + /* Success. */ #endif - return(1); + return (1); } - /************************************************************************** * Function: CheckMapVersion * @@ -514,20 +472,15 @@ static int CheckVersion(version) * 1:-> The executing kernel is of the same version * as the version of the map file. **************************************************************************/ - -static int CheckMapVersion(fname) - - char *fname; - - +static int CheckMapVersion(char *fname) { - int version; - FILE *sym_file; - auto unsigned long int address; - auto char type, - sym[512]; + unsigned long int address; + FILE *sym_file; + char sym[512]; + char type; + int version; - if ( (sym_file = fopen(fname, "r")) != (FILE *) 0 ) { + if ((sym_file = fopen(fname, "r")) != (FILE *)0) { /* * At this point a map file was successfully opened. We * now need to search this file and look for version @@ -536,49 +489,46 @@ static int CheckMapVersion(fname) Syslog(LOG_INFO, "Inspecting %s", fname); version = 0; - while ( !feof(sym_file) && (version == 0) ) - { - if ( fscanf(sym_file, "%lx %c %511s\n", &address, \ - &type, sym) != 3 ) - { + while (!feof(sym_file) && (version == 0)) { + if (fscanf(sym_file, "%lx %c %511s\n", &address, + &type, sym) != 3) { Syslog(LOG_ERR, "Error in symbol table input (#2)."); fclose(sym_file); - return(0); + return (0); } - if ( VERBOSE_DEBUGGING && debugging ) - fprintf(stderr, "Address: %lx, Type: %c, " \ - "Symbol: %s\n", address, type, sym); + if (VERBOSE_DEBUGGING && debugging) + fprintf(stderr, "Address: %lx, Type: %c, " + "Symbol: %s\n", + address, type, sym); version = CheckVersion(sym); } fclose(sym_file); - switch ( version ) - { - case -1: - Syslog(LOG_ERR, "Symbol table has incorrect " \ - "version number.\n"); + switch (version) { + case -1: + Syslog(LOG_ERR, "Symbol table has incorrect " + "version number.\n"); break; - - case 0: - if ( debugging ) - fprintf(stderr, "No version information " \ - "found.\n"); + + case 0: + if (debugging) + fprintf(stderr, "No version information " + "found.\n"); break; - case 1: - if ( debugging ) - fprintf(stderr, "Found table with " \ - "matching version number.\n"); + case 1: + if (debugging) + fprintf(stderr, "Found table with " + "matching version number.\n"); break; } - return(version); + return (version); } - return(0); + return (0); } - /************************************************************************** * Function: AddSymbol * @@ -592,33 +542,24 @@ static int CheckMapVersion(fname) * A boolean value is assumed. True if the addition is * successful. False if not. **************************************************************************/ - -static int AddSymbol(address, symbol) - - unsigned long address; - - char *symbol; - +static int AddSymbol(unsigned long address, char *symbol) { /* Allocate the the symbol table entry. */ - sym_array = (struct sym_table *) realloc(sym_array, (num_syms+1) * \ - sizeof(struct sym_table)); - if ( sym_array == (struct sym_table *) 0 ) - return(0); + sym_array = realloc(sym_array, (num_syms + 1) * sizeof(struct sym_table)); + if (sym_array == NULL) + return (0); /* Then the space for the symbol. */ - sym_array[num_syms].name = (char *) malloc(strlen(symbol)*sizeof(char)\ - + 1); - if ( sym_array[num_syms].name == (char *) 0 ) - return(0); - + sym_array[num_syms].name = malloc(strlen(symbol) * sizeof(char) + 1); + if (sym_array[num_syms].name == NULL) + return (0); + sym_array[num_syms].value = address; strcpy(sym_array[num_syms].name, symbol); ++num_syms; - return(1); + return (1); } - /************************************************************************** * Function: LookupSymbol * @@ -638,37 +579,27 @@ static int AddSymbol(address, symbol) * If a match is found the pointer to the symbolic name most * closely matching the address is returned. **************************************************************************/ - -char * LookupSymbol(value, sym) - - unsigned long value; - - struct symbol *sym; - +char *LookupSymbol(unsigned long value, struct symbol *sym) { - auto int lp; - - auto char *last; - auto char *name; - struct symbol ksym, msym; + char *last; + char *name; + int lp; if (!sym_array) - return((char *) 0); + return ((char *)0); last = sym_array[0].name; ksym.offset = 0; ksym.size = 0; - if ( value < sym_array[0].value ) - return((char *) 0); - - for(lp = 0; lp <= num_syms; ++lp) - { - if ( sym_array[lp].value > value ) - { - ksym.offset = value - sym_array[lp-1].value; - ksym.size = sym_array[lp].value - \ - sym_array[lp-1].value; + if (value < sym_array[0].value) + return ((char *)0); + + for (lp = 0; lp <= num_syms; ++lp) { + if (sym_array[lp].value > value) { + ksym.offset = value - sym_array[lp - 1].value; + ksym.size = sym_array[lp].value - + sym_array[lp - 1].value; break; } last = sym_array[lp].name; @@ -676,30 +607,24 @@ char * LookupSymbol(value, sym) name = LookupModuleSymbol(value, &msym); - if ( ksym.offset == 0 && msym.offset == 0 ) - { - return((char *) 0); + if (ksym.offset == 0 && msym.offset == 0) { + return NULL; } - if ( ksym.offset == 0 || msym.offset < 0 || - (ksym.offset > 0 && ksym.offset < msym.offset) ) - { + if (ksym.offset == 0 || msym.offset < 0 || + (ksym.offset > 0 && ksym.offset < msym.offset)) { sym->offset = ksym.offset; sym->size = ksym.size; - return(last); - } - else - { + return (last); + } else { sym->offset = msym.offset; sym->size = msym.size; - return(name); + return (name); } - - return((char *) 0); + return NULL; } - /************************************************************************** * Function: FreeSymbols * @@ -713,24 +638,20 @@ char * LookupSymbol(value, sym) * Return: void **************************************************************************/ -static void FreeSymbols() - +static void FreeSymbols(void) { - auto int lp; + int lp; /* Free each piece of memory allocated for symbol names. */ - for(lp = 0; lp < num_syms; ++lp) + for (lp = 0; lp < num_syms; ++lp) free(sym_array[lp].name); /* Whack the entire array and initialize everything. */ free(sym_array); - sym_array = (struct sym_table *) 0; + sym_array = (struct sym_table *)0; num_syms = 0; - - return; } - /************************************************************************** * Function: LogExpanded * @@ -749,23 +670,16 @@ static void FreeSymbols() * Return: void **************************************************************************/ -extern char * ExpandKadds(line, el) - - char *line; - - char *el; - +char *ExpandKadds(char *line, char *el) { - auto char dlm, - *kp, - *sl = line, - *elp = el, - *symbol; - + unsigned long int value; + struct symbol sym; + char *symbol; + char *elp = el; + char *sl = line; + char *kp; char num[15]; - auto unsigned long int value; - - auto struct symbol sym; + char dlm; sym.offset = 0; sym.size = 0; @@ -787,52 +701,47 @@ extern char * ExpandKadds(line, el) * kernel whenever a module is loaded or unloaded. I am * open for patches. */ - if ( i_am_paranoid && - (strstr(line, "Oops:") != (char *) 0) && !InitMsyms() ) + if (i_am_paranoid && + (strstr(line, "Oops:") != (char *)0) && !InitMsyms()) Syslog(LOG_WARNING, "Cannot load kernel module symbols.\n"); - /* * Early return if there do not appear to be any kernel * messages in this line. */ - if ( (num_syms == 0) || - (kp = strstr(line, "[<")) == (char *) 0 ) - { + if ((num_syms == 0) || + (kp = strstr(line, "[<")) == (char *)0) { strcpy(el, line); - return(el); + return (el); } /* Loop through and expand all kernel messages. */ - do - { - while ( sl < kp+1 ) + do { + while (sl < kp + 1) *elp++ = *sl++; /* Now poised at a kernel delimiter. */ - if ( (kp = strstr(sl, ">]")) == (char *) 0 ) - { + if ((kp = strstr(sl, ">]")) == (char *)0) { strcpy(el, sl); - return(el); + return (el); } dlm = *kp; - strncpy(num,sl+1,kp-sl-1); - num[kp-sl-1] = '\0'; - value = strtoul(num, (char **) 0, 16); - if ( (symbol = LookupSymbol(value, &sym)) == (char *) 0 ) + strncpy(num, sl + 1, kp - sl - 1); + num[kp - sl - 1] = '\0'; + value = strtoul(num, (char **)0, 16); + if ((symbol = LookupSymbol(value, &sym)) == (char *)0) symbol = sl; - + strcat(elp, symbol); elp += strlen(symbol); - if ( debugging ) - fprintf(stderr, "Symbol: %s = %lx = %s, %x/%d\n", \ - sl+1, value, \ - (sym.size==0) ? symbol+1 : symbol, \ - sym.offset, sym.size); + if (debugging) + fprintf(stderr, "Symbol: %s = %lx = %s, %x/%d\n", + sl + 1, value, + (sym.size == 0) ? symbol + 1 : symbol, + sym.offset, sym.size); value = 2; - if ( sym.size != 0 ) - { + if (sym.size != 0) { --value; ++kp; elp += sprintf(elp, "+0x%x/0x%02x", sym.offset, sym.size); @@ -840,16 +749,14 @@ extern char * ExpandKadds(line, el) strncat(elp, kp, value); elp += value; sl = kp + value; - if ( (kp = strstr(sl, "[<")) == (char *) 0 ) + if ((kp = strstr(sl, "[<")) == (char *)0) strcat(elp, sl); - } - while ( kp != (char *) 0); - - if ( debugging ) - fprintf(stderr, "Expanded line: %s\n", el); - return(el); -} + } while (kp != (char *)0); + if (debugging) + fprintf(stderr, "Expanded line: %s\n", el); + return (el); +} /************************************************************************** * Function: SetParanoiaLevel @@ -864,17 +771,12 @@ extern char * ExpandKadds(line, el) * present when resolving kernel exceptions. * Return: void **************************************************************************/ - -extern void SetParanoiaLevel(level) - - int level; - +void SetParanoiaLevel(int level) { i_am_paranoid = level; return; } - /* * Setting the -DTEST define enables the following code fragment to * be compiled. This produces a small standalone program which will @@ -885,37 +787,30 @@ extern void SetParanoiaLevel(level) #include -extern int main(int, char **); - - -extern int main(int argc, char *argv[]) +int main(int argc, char *argv[]) { - auto char line[1024], eline[2048]; + char line[1024], eline[2048]; debugging = 1; - - - if ( !InitKsyms((char *) 0) ) - { + + if (!InitKsyms((char *)0)) { fputs("ksym: Error loading system map.\n", stderr); - return(1); + return (1); } - while ( !feof(stdin) ) - { + while (!feof(stdin)) { fgets(line, sizeof(line), stdin); - if (line[strlen(line)-1] == '\n') line[strlen(line)-1] = '\0'; /* Trash NL char */ + if (line[strlen(line) - 1] == '\n') + line[strlen(line) - 1] = '\0'; /* Trash NL char */ memset(eline, '\0', sizeof(eline)); ExpandKadds(line, eline); fprintf(stdout, "%s\n", eline); } - - return(0); + return (0); } -extern void Syslog(int priority, char *fmt, ...) - +void Syslog(int priority, char *fmt, ...) { va_list ap; @@ -930,9 +825,8 @@ extern void Syslog(int priority, char *fmt, ...) #endif /** - * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 + * Local Variables: + * indent-tabs-mode: t + * c-file-style: "linux" * End: */ diff --git a/src/ksym_mod.c b/src/ksym_mod.c index 4551510..b3f1cd3 100644 --- a/src/ksym_mod.c +++ b/src/ksym_mod.c @@ -103,34 +103,33 @@ * the first hit. */ - /* Includes. */ -#include -#include -#include #include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include #ifdef SYSV #include #else #include #endif -#include #include "module.h" -#include -#include #include +#include +#include +#include #include "klogd.h" #include "ksyms.h" -#define KSYMS "/proc/kallsyms" +#define KSYMS "/proc/kallsyms" -static int num_modules = 0; -struct Module *sym_array_modules = (struct Module *) 0; +static int num_modules = 0; +struct Module *sym_array_modules = (struct Module *)0; static int have_modules = 0; @@ -140,12 +139,11 @@ static int debugging = 1; extern int debugging; #endif - /* Function prototypes. */ -static void FreeModules(void); -static int AddSymbol(const char *); +static void FreeModules(void); +static int AddSymbol(const char *); struct Module *AddModule(const char *); -static int symsort(const void *, const void *); +static int symsort(const void *, const void *); /* Imported from ksym.c */ extern int num_syms; @@ -166,49 +164,46 @@ extern int num_syms; * True if loading is successful. **************************************************************************/ -extern int InitMsyms() - +extern int InitMsyms(void) { - auto int rtn, - tmp; - FILE *ksyms; - - char buf[128]; char *p; + char buf[128]; + int rtn; + int tmp; /* Initialize the kernel module symbol table. */ FreeModules(); ksyms = fopen(KSYMS, "r"); - if ( ksyms == NULL ) - { - if ( errno == ENOENT ) + if (ksyms == NULL) { + if (errno == ENOENT) Syslog(LOG_INFO, "No module symbols loaded - " - "kernel modules not enabled.\n"); + "kernel modules not enabled.\n"); else - Syslog(LOG_ERR, "Error loading kernel symbols " \ - "- %s\n", strerror(errno)); - return(0); + Syslog(LOG_ERR, "Error loading kernel symbols " + "- %s\n", + strerror(errno)); + return (0); } - if ( debugging ) + if (debugging) fprintf(stderr, "Loading kernel module symbols - " - "Source: %s\n", KSYMS); + "Source: %s\n", + KSYMS); - while ( fgets(buf, sizeof(buf), ksyms) != NULL ) - { + while (fgets(buf, sizeof(buf), ksyms) != NULL) { if (num_syms > 0 && index(buf, '[') == NULL) continue; p = index(buf, ' '); - if ( p == NULL ) + if (p == NULL) continue; - if ( buf[strlen(buf)-1] == '\n' ) - buf[strlen(buf)-1] = '\0'; + if (buf[strlen(buf) - 1] == '\n') + buf[strlen(buf) - 1] = '\0'; /* overlong lines will be ignored above */ AddSymbol(buf); @@ -219,45 +214,39 @@ extern int InitMsyms() have_modules = 1; /* Sort the symbol tables in each module. */ - for (rtn = tmp = 0; tmp < num_modules; ++tmp) - { + for (rtn = tmp = 0; tmp < num_modules; ++tmp) { rtn += sym_array_modules[tmp].num_syms; - if ( sym_array_modules[tmp].num_syms < 2 ) + if (sym_array_modules[tmp].num_syms < 2) continue; - qsort(sym_array_modules[tmp].sym_array, \ - sym_array_modules[tmp].num_syms, \ + qsort(sym_array_modules[tmp].sym_array, + sym_array_modules[tmp].num_syms, sizeof(struct sym_table), symsort); } - if ( rtn == 0 ) + if (rtn == 0) Syslog(LOG_INFO, "No module symbols loaded."); else - Syslog(LOG_INFO, "Loaded %d %s from %d module%s", rtn, \ - (rtn == 1) ? "symbol" : "symbols", \ + Syslog(LOG_INFO, "Loaded %d %s from %d module%s", rtn, + (rtn == 1) ? "symbol" : "symbols", num_modules, (num_modules == 1) ? "." : "s."); - return(1); + return (1); } - -static int symsort(p1, p2) - - const void *p1; - - const void *p2; - +static int symsort(const void *p1, const void *p2) { - auto const struct sym_table *sym1 = p1, - *sym2 = p2; + const struct sym_table *sym1 = p1, + *sym2 = p2; - if ( sym1->value < sym2->value ) - return(-1); - if ( sym1->value == sym2->value ) - return(0); - return(1); + if (sym1->value < sym2->value) + return (-1); + + if (sym1->value == sym2->value) + return (0); + + return (1); } - /************************************************************************** * Function: FreeModules * @@ -268,44 +257,38 @@ static int symsort(p1, p2) * * Return: void **************************************************************************/ - -static void FreeModules() - +static void FreeModules(void) { - auto int nmods, - nsyms; - - auto struct Module *mp; - + struct Module *mp; + int nmods; + int nsyms; /* Check to see if the module symbol tables need to be cleared. */ have_modules = 0; - if ( num_modules == 0 ) + if (num_modules == 0) return; - if ( sym_array_modules == NULL ) + if (sym_array_modules == NULL) return; - for (nmods = 0; nmods < num_modules; ++nmods) - { + for (nmods = 0; nmods < num_modules; ++nmods) { mp = &sym_array_modules[nmods]; - if ( mp->num_syms == 0 ) + if (mp->num_syms == 0) continue; - - for (nsyms= 0; nsyms < mp->num_syms; ++nsyms) + + for (nsyms = 0; nsyms < mp->num_syms; ++nsyms) free(mp->sym_array[nsyms].name); free(mp->sym_array); - if ( mp->name != NULL ) + if (mp->name != NULL) free(mp->name); } free(sym_array_modules); - sym_array_modules = (struct Module *) 0; + sym_array_modules = (struct Module *)0; num_modules = 0; return; } - /************************************************************************** * Function: AddModule * @@ -319,33 +302,21 @@ static void FreeModules() * Return: struct Module * **************************************************************************/ -struct Module *AddModule(module) - - const char *module; - +struct Module *AddModule(const char *module) { struct Module *mp; - if ( num_modules == 0 ) - { + if (num_modules == 0) { sym_array_modules = (struct Module *)malloc(sizeof(struct Module)); - - if ( sym_array_modules == NULL ) - { + if (sym_array_modules == NULL) { Syslog(LOG_WARNING, "Cannot allocate Module array.\n"); return NULL; } mp = sym_array_modules; - } - else - { + } else { /* Allocate space for the module. */ - mp = (struct Module *) \ - realloc(sym_array_modules, \ - (num_modules+1) * sizeof(struct Module)); - - if ( mp == NULL ) - { + mp = realloc(sym_array_modules, (num_modules + 1) * sizeof(struct Module)); + if (mp == NULL) { Syslog(LOG_WARNING, "Cannot allocate Module array.\n"); return NULL; } @@ -358,7 +329,7 @@ struct Module *AddModule(module) mp->sym_array = NULL; mp->num_syms = 0; - if ( module != NULL ) + if (module != NULL) mp->name = strdup(module); else mp->name = NULL; @@ -366,7 +337,6 @@ struct Module *AddModule(module) return mp; } - /************************************************************************** * Function: AddSymbol * @@ -387,78 +357,68 @@ struct Module *AddModule(module) * A boolean value is assumed. True if the addition is * successful. False if not. **************************************************************************/ - -static int AddSymbol(line) - - const char *line; - +static int AddSymbol(const char *line) { - char *module; - unsigned long address; - char *p; static char *lastmodule = NULL; struct Module *mp; + unsigned long address; + char *module; + char *p; module = index(line, '['); - - if ( module != NULL ) - { + if (module != NULL) { p = index(module, ']'); - if ( p != NULL ) + if (p != NULL) *p = '\0'; p = module++; - while ( isspace(*(--p)) ); + while (isspace(*(--p))) + ; *(++p) = '\0'; } p = index(line, ' '); - - if ( p == NULL ) - return(0); - + if (p == NULL) + return (0); *p = '\0'; - address = strtoul(line, (char **) 0, 16); + address = strtoul(line, (char **)0, 16); p += 3; - if ( num_modules == 0 || - ( lastmodule == NULL && module != NULL ) || - ( module == NULL && lastmodule != NULL) || - ( module != NULL && strcmp(module, lastmodule))) - { + if (num_modules == 0 || + (lastmodule == NULL && module != NULL) || + (module == NULL && lastmodule != NULL) || + (module != NULL && strcmp(module, lastmodule))) { mp = AddModule(module); - if ( mp == NULL ) - return(0); - } - else - mp = &sym_array_modules[num_modules-1]; + if (mp == NULL) + return (0); + } else + mp = &sym_array_modules[num_modules - 1]; lastmodule = mp->name; /* Allocate space for the symbol table entry. */ - mp->sym_array = (struct sym_table *) realloc(mp->sym_array, \ - (mp->num_syms+1) * sizeof(struct sym_table)); + mp->sym_array = (struct sym_table *)realloc(mp->sym_array, + (mp->num_syms + 1) * sizeof(struct sym_table)); - if ( mp->sym_array == (struct sym_table *) 0 ) - return(0); + if (mp->sym_array == (struct sym_table *)0) + return (0); mp->sym_array[mp->num_syms].name = strdup(p); - if ( mp->sym_array[mp->num_syms].name == (char *) 0 ) - return(0); - + if (mp->sym_array[mp->num_syms].name == (char *)0) + return (0); + /* Stuff interesting information into the module. */ mp->sym_array[mp->num_syms].value = address; ++mp->num_syms; - return(1); + return (1); } - /************************************************************************** * Function: LookupModuleSymbol * @@ -478,73 +438,58 @@ static int AddSymbol(line) * If a match is found the pointer to the symbolic name most * closely matching the address is returned. **************************************************************************/ - -extern char * LookupModuleSymbol(value, sym) - - unsigned long value; - - struct symbol *sym; - +char *LookupModuleSymbol(unsigned long value, struct symbol *sym) { - auto int nmod, - nsym; - - auto struct sym_table *last; - - auto struct Module *mp; - static char ret[100]; - + struct sym_table *last; + struct Module *mp; + int nmod; + int nsym; sym->size = 0; sym->offset = 0; - if ( num_modules == 0 ) - return((char *) 0); - - for (nmod = 0; nmod < num_modules; ++nmod) - { + if (num_modules == 0) + return NULL; + + for (nmod = 0; nmod < num_modules; ++nmod) { mp = &sym_array_modules[nmod]; /* * Run through the list of symbols in this module and * see if the address can be resolved. */ - for(nsym = 1, last = &mp->sym_array[0]; - nsym < mp->num_syms; - ++nsym) - { - if ( mp->sym_array[nsym].value > value ) - { - if ( sym->size == 0 || - (value - last->value) < sym->offset || - ( (sym->offset == (value - last->value)) && - (mp->sym_array[nsym].value-last->value) < sym->size ) ) - { - sym->offset = value - last->value; - sym->size = mp->sym_array[nsym].value - \ - last->value; - ret[sizeof(ret)-1] = '\0'; - if ( mp->name == NULL ) - snprintf(ret, sizeof(ret)-1, - "%s", last->name); - else - snprintf(ret, sizeof(ret)-1, - "%s:%s", mp->name, last->name); - } - break; + for (nsym = 1, last = &mp->sym_array[0]; + nsym < mp->num_syms; + ++nsym) { + if (mp->sym_array[nsym].value > value) { + if (sym->size == 0 || + (value - last->value) < sym->offset || + ((sym->offset == (value - last->value)) && + (mp->sym_array[nsym].value - last->value) < sym->size)) { + sym->offset = value - last->value; + sym->size = mp->sym_array[nsym].value - + last->value; + ret[sizeof(ret) - 1] = '\0'; + if (mp->name == NULL) + snprintf(ret, sizeof(ret) - 1, + "%s", last->name); + else + snprintf(ret, sizeof(ret) - 1, + "%s:%s", mp->name, last->name); + } + break; } last = &mp->sym_array[nsym]; } } - if ( sym->size > 0 ) - return(ret); + if (sym->size > 0) + return (ret); /* It has been a hopeless exercise. */ - return((char *) 0); + return NULL; } - /* * Setting the -DTEST define enables the following code fragment to * be compiled. This produces a small standalone program which will @@ -554,52 +499,38 @@ extern char * LookupModuleSymbol(value, sym) #include - -extern int main(int, char **); - - -int main(argc, argv) - - int argc; - - char *argv[]; - +int main(int argc, char *argv[]) { - auto int lp, syms; + int lp, syms; - - if ( !InitMsyms() ) - { + if (!InitMsyms()) { fprintf(stderr, "Cannot load module symbols.\n"); - return(1); + return (1); } printf("Number of modules: %d\n\n", num_modules); - for(lp= 0; lp < num_modules; ++lp) - { - printf("Module #%d = %s, Number of symbols = %d\n", lp + 1, \ + for (lp = 0; lp < num_modules; ++lp) { + printf("Module #%d = %s, Number of symbols = %d\n", lp + 1, sym_array_modules[lp].name == NULL - ?"kernel space" - :sym_array_modules[lp].name, \ + ? "kernel space" + : sym_array_modules[lp].name, sym_array_modules[lp].num_syms); - for (syms= 0; syms < sym_array_modules[lp].num_syms; ++syms) - { + for (syms = 0; syms < sym_array_modules[lp].num_syms; ++syms) { printf("\tSymbol #%d\n", syms + 1); - printf("\tName: %s\n", \ + printf("\tName: %s\n", sym_array_modules[lp].sym_array[syms].name); - printf("\tAddress: %lx\n\n", \ + printf("\tAddress: %lx\n\n", sym_array_modules[lp].sym_array[syms].value); } } FreeModules(); - return(0); + return (0); } -extern void Syslog(int priority, char *fmt, ...) - +void Syslog(int priority, char *fmt, ...) { va_list ap; @@ -615,9 +546,8 @@ extern void Syslog(int priority, char *fmt, ...) #endif /* TEST */ /** - * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 + * Local Variables: + * indent-tabs-mode: t + * c-file-style: "linux" * End: */ diff --git a/src/ksyms.h b/src/ksyms.h index 4e70ba0..de05ac5 100644 --- a/src/ksyms.h +++ b/src/ksyms.h @@ -1,29 +1,28 @@ /* - ksym.h - Definitions for symbol table utilities. - Copyright (c) 1995, 1996 Dr. G.W. Wettstein - Copyright (c) 1996 Enjellic Systems Development - - This file is part of the sysklogd package, a kernel and system log daemon. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ + * ksym.h - Definitions for symbol table utilities. + * Copyright (c) 1995, 1996 Dr. G.W. Wettstein + * Copyright (c) 1996 Enjellic Systems Development + * + * This file is part of the sysklogd package, a kernel and system log daemon. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ /* Variables, structures and type definitions static to this module. */ -struct symbol -{ +struct symbol { char *name; int size; int offset; @@ -31,5 +30,5 @@ struct symbol /* Function prototypes. */ -extern char * LookupSymbol(unsigned long, struct symbol *); -extern char * LookupModuleSymbol(unsigned long int, struct symbol *); +extern char *LookupSymbol(unsigned long, struct symbol *); +extern char *LookupModuleSymbol(unsigned long int, struct symbol *); diff --git a/src/module.h b/src/module.h index 046d7a2..6269529 100644 --- a/src/module.h +++ b/src/module.h @@ -1,24 +1,24 @@ /* - module.h - Miscellaneous module definitions - Copyright (c) 1996 Richard Henderson - Copyright (c) 2004-7 Martin Schulze - - This file is part of the sysklogd package. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ + * module.h - Miscellaneous module definitions + * Copyright (c) 1996 Richard Henderson + * Copyright (c) 2004-7 Martin Schulze + * + * This file is part of the sysklogd package. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ /* ChangeLog: * @@ -35,17 +35,15 @@ * ksym_mod.c over here. */ -struct sym_table -{ - unsigned long value; - char *name; +struct sym_table { + unsigned long value; + char *name; }; -struct Module -{ +struct Module { struct sym_table *sym_array; - int num_syms; + int num_syms; - char *name; + char *name; }; diff --git a/src/oops.c b/src/oops.c index ba3a68b..2669b57 100644 --- a/src/oops.c +++ b/src/oops.c @@ -29,15 +29,15 @@ cat /proc/oops Display current log level and last oops time */ -#include -#include #include -#include +#include +#include #include +#include #include -#define MODNAME "oops" -#define PROCNAME "oops" +#define MODNAME "oops" +#define PROCNAME "oops" MODULE_AUTHOR("Martin Schulze "); MODULE_DESCRIPTION("Oops module from klogd"); @@ -46,48 +46,49 @@ MODULE_LICENSE("GPL"); static DEFINE_MUTEX(oops_lock); struct oops_t { - unsigned long lastoops; - int loglevel; + unsigned long lastoops; + int loglevel; }; static struct oops_t oops_data; static int procflag = 0; struct code { - char *name; - int level; + char *name; + int level; }; struct code priorities[] = { - {"emerg", 0}, - {"panic", 0}, /* DEPRECATED */ - {"alert", 1}, - {"crit", 2}, - {"err", 3}, - {"error", 3}, /* DEPRECATED */ - {"warning", 4}, - {"warn", 4}, /* DEPRECATED */ - {"notice", 5}, - {"info", 6}, - {"debug", 7}, - {NULL, -1} + { "emerg", 0 }, + { "panic", 0 }, /* DEPRECATED */ + { "alert", 1 }, + { "crit", 2 }, + { "err", 3 }, + { "error", 3 }, /* DEPRECATED */ + { "warning", 4 }, + { "warn", 4 }, /* DEPRECATED */ + { "notice", 5 }, + { "info", 6 }, + { "debug", 7 }, + { NULL, -1 } }; -void oops_decode_level (char *line) +void oops_decode_level(char *line) { - char *p; - struct code *prio; + struct code *prio; + char *p; - if (strncmp(line, "level:", 6)) - return; + if (strncmp(line, "level:", 6)) + return; - for (p = (char *)(line) + 6;*p == ' ' || *p == '\t';p++); + for (p = (char *)(line) + 6; *p == ' ' || *p == '\t'; p++) + ; - for (prio = priorities; prio->name; prio++) - if (!strcmp(p, prio->name)) { - oops_data.loglevel = prio->level; - return; - } + for (prio = priorities; prio->name; prio++) + if (!strcmp(p, prio->name)) { + oops_data.loglevel = prio->level; + return; + } } /* @@ -95,156 +96,160 @@ void oops_decode_level (char *line) */ static void oops(void) { - auto unsigned long *p = (unsigned long *) 828282828; + unsigned long *p = (unsigned long *)828282828; *p = 5; - return; } -static int oops_proc_open (struct inode *inode, struct file *file) +static int oops_proc_open(struct inode *inode, struct file *file) { #ifdef DEBUG - printk (KERN_DEBUG "oops_proc_open().\n"); + printk(KERN_DEBUG "oops_proc_open().\n"); #endif - return 0; + return 0; } static ssize_t -oops_proc_read (struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) +oops_proc_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) { - char s[70]; - int size; - - struct code *prio; - char *level = NULL; + struct code *prio; + char *level = NULL; + char s[70]; + int size; #ifdef DEBUG - printk (KERN_DEBUG "oops_proc_read(%d).\n",nbytes); + printk(KERN_DEBUG "oops_proc_read(%d).\n", nbytes); #endif - if (procflag) { - procflag = 0; - return 0; - } + if (procflag) { + procflag = 0; + return 0; + } - for (prio = priorities; - prio->name && prio->level != oops_data.loglevel; - prio++); - level = prio->name; + for (prio = priorities; + prio->name && prio->level != oops_data.loglevel; + prio++) + ; + level = prio->name; - if (oops_data.lastoops == 0) - size = sprintf (s, "Log level: %s\nLast oops: none\n", level); - else { - unsigned long now = get_seconds(); - unsigned long delta = now - oops_data.lastoops; - size = sprintf (s, "Log level: %s\nLast oops: %lu (%lu second%s ago)\n", - level, oops_data.lastoops, - delta, delta == 1 ? "" : "s"); - } + if (oops_data.lastoops == 0) + size = sprintf(s, "Log level: %s\nLast oops: none\n", level); + else { + unsigned long now = get_seconds(); + unsigned long delta = now - oops_data.lastoops; + size = sprintf(s, "Log level: %s\nLast oops: %lu (%lu second%s ago)\n", + level, oops_data.lastoops, + delta, delta == 1 ? "" : "s"); + } - if (size < nbytes) - nbytes = size; + if (size < nbytes) + nbytes = size; - if (copy_to_user(buf, s, nbytes)) - return -EFAULT; + if (copy_to_user(buf, s, nbytes)) + return -EFAULT; - *ppos += nbytes; + *ppos += nbytes; - procflag++; + procflag++; - return nbytes; + return nbytes; } static int oops_proc_release(struct inode *inode, struct file *filp) { #ifdef DEBUG - printk (KERN_DEBUG "oops_proc_release().\n"); + printk(KERN_DEBUG "oops_proc_release().\n"); #endif - return 0; + return 0; } static ssize_t oops_proc_write(struct file *file, const char __user *buf, size_t nbytes, loff_t *ppos) { - char input[100]; - int len; + char input[100]; + int len; #ifdef DEBUG - printk (KERN_DEBUG "oops_proc_write(%d).\n", nbytes); + printk(KERN_DEBUG "oops_proc_write(%d).\n", nbytes); #endif - len = nbytes >= sizeof(input) ? sizeof(input)-1 : nbytes; + len = nbytes >= sizeof(input) ? sizeof(input) - 1 : nbytes; - if (copy_from_user(input, buf, len)) - return -EFAULT; + if (copy_from_user(input, buf, len)) + return -EFAULT; - input[len] = '\0'; - if (input[len-1] == '\n') - input[len-1] = '\0'; + input[len] = '\0'; + if (input[len - 1] == '\n') + input[len - 1] = '\0'; - if (!strncmp(input, "level:", 6)) - oops_decode_level(input); - else if (!strcmp(input, "oops")) { - oops_data.lastoops = get_seconds(); - oops(); - } else - printk ("<%d>%s\n", oops_data.loglevel, input); + if (!strncmp(input, "level:", 6)) + oops_decode_level(input); + else if (!strcmp(input, "oops")) { + oops_data.lastoops = get_seconds(); + oops(); + } else + printk("<%d>%s\n", oops_data.loglevel, input); - return nbytes; + return nbytes; } static const struct file_operations oops_proc_operations = { - .read = oops_proc_read, - .release = oops_proc_release, - .write = oops_proc_write, - .open = oops_proc_open, + .read = oops_proc_read, + .release = oops_proc_release, + .write = oops_proc_write, + .open = oops_proc_open, }; -void oops_proc_add (void) +void oops_proc_add(void) { - struct proc_dir_entry *entry; + struct proc_dir_entry *entry; - mutex_lock (&oops_lock); + mutex_lock(&oops_lock); - entry = create_proc_entry (PROCNAME, 0, NULL); + entry = create_proc_entry(PROCNAME, 0, NULL); - if (entry) { - entry->proc_fops = &oops_proc_operations; - } + if (entry) { + entry->proc_fops = &oops_proc_operations; + } - mutex_unlock (&oops_lock); + mutex_unlock(&oops_lock); } -void oops_proc_remove (void) +void oops_proc_remove(void) { - mutex_lock (&oops_lock); + mutex_lock(&oops_lock); - remove_proc_entry(PROCNAME, NULL); + remove_proc_entry(PROCNAME, NULL); - mutex_unlock(&oops_lock); + mutex_unlock(&oops_lock); } -int oops_init (void) +int oops_init(void) { - printk (KERN_INFO "Loading module " MODNAME ".\n"); + printk(KERN_INFO "Loading module " MODNAME ".\n"); - oops_data.lastoops = 0; - oops_data.loglevel = 5; + oops_data.lastoops = 0; + oops_data.loglevel = 5; - oops_proc_add(); + oops_proc_add(); - return 0; + return 0; } -void oops_cleanup (void) +void oops_cleanup(void) { - oops_proc_remove(); + oops_proc_remove(); - printk (KERN_INFO "Removing module " MODNAME ".\n"); + printk(KERN_INFO "Removing module " MODNAME ".\n"); } - module_init(oops_init); module_exit(oops_cleanup); +/** + * Local Variables: + * indent-tabs-mode: t + * c-file-style: "linux" + * End: + */ diff --git a/src/pidfile.c b/src/pidfile.c index 5b09625..339daad 100644 --- a/src/pidfile.c +++ b/src/pidfile.c @@ -1,37 +1,37 @@ /* - pidfile.c - interact with pidfiles - Copyright (c) 1995 Martin Schulze - - This file is part of the sysklogd package, a kernel and system log daemon. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA -*/ + * pidfile.c - interact with pidfiles + * Copyright (c) 1995 Martin Schulze + * + * This file is part of the sysklogd package, a kernel and system log daemon. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA + */ /* * Sat Aug 19 13:24:33 MET DST 1995: Martin Schulze * First version (v0.2) released */ -#include -#include -#include -#include -#include #include -#include #include +#include +#include +#include +#include +#include +#include /* read_pid * @@ -39,16 +39,19 @@ * 0 is returned if either there's no pidfile, it's empty * or no pid can be read. */ -int read_pid (char *pidfile) +int read_pid(char *pidfile) { - FILE *f; - int pid; + FILE *fp; + int pid; - if (!(f=fopen(pidfile,"r"))) - return 0; - fscanf(f,"%d", &pid); - fclose(f); - return pid; + fp = fopen(pidfile, "r"); + if (!fp) + return 0; + + fscanf(fp, "%d", &pid); + fclose(fp); + + return pid; } /* check_pid @@ -57,24 +60,24 @@ int read_pid (char *pidfile) * table (using /proc) to determine if the process already exists. If * so 1 is returned, otherwise 0. */ -int check_pid (char *pidfile) +int check_pid(char *pidfile) { - int pid = read_pid(pidfile); + int pid = read_pid(pidfile); - /* Amazing ! _I_ am already holding the pid file... */ - if ((!pid) || (pid == getpid ())) - return 0; + /* Amazing ! _I_ am already holding the pid file... */ + if ((!pid) || (pid == getpid())) + return 0; - /* - * The 'standard' method of doing this is to try and do a 'fake' kill - * of the process. If an ESRCH error is returned the process cannot - * be found -- GW - */ - /* But... errno is usually changed only on error.. */ - if (kill(pid, 0) && errno == ESRCH) - return(0); + /* + * The 'standard' method of doing this is to try and do a 'fake' kill + * of the process. If an ESRCH error is returned the process cannot + * be found -- GW + */ + /* But... errno is usually changed only on error.. */ + if (kill(pid, 0) && errno == ESRCH) + return (0); - return pid; + return pid; } /* write_pid @@ -82,41 +85,40 @@ int check_pid (char *pidfile) * Writes the pid to the specified file. If that fails 0 is * returned, otherwise the pid. */ -int write_pid (char *pidfile) +int write_pid(char *pidfile) { - FILE *f; - int fd; - int pid; + FILE *fp; + int fd; + int pid; - if ( ((fd = open(pidfile, O_RDWR|O_CREAT|O_TRUNC, 0644)) == -1) - || ((f = fdopen(fd, "r+")) == NULL) ) { - fprintf(stderr, "Can't open or create %s.\n", pidfile); - return 0; - } + if (((fd = open(pidfile, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1) || ((fp = fdopen(fd, "r+")) == NULL)) { + fprintf(stderr, "Can't open or create %s.\n", pidfile); + return 0; + } - if (flock(fd, LOCK_EX|LOCK_NB) == -1) { - fscanf(f, "%d", &pid); - fclose(f); - printf("Can't lock, lock is held by pid %d.\n", pid); - return 0; - } + if (flock(fd, LOCK_EX | LOCK_NB) == -1) { + fscanf(fp, "%d", &pid); + fclose(fp); + printf("Can't lock, lock is held by pid %d.\n", pid); + return 0; + } - pid = getpid(); - if (!fprintf(f,"%d\n", pid)) { - printf("Can't write pid , %s.\n", strerror(errno)); - close(fd); - return 0; - } - fflush(f); + pid = getpid(); + if (!fprintf(fp, "%d\n", pid)) { + printf("Can't write pid , %s.\n", strerror(errno)); + close(fd); + return 0; + } + fflush(fp); - if (flock(fd, LOCK_UN) == -1) { - printf("Can't unlock pidfile %s, %s.\n", pidfile, strerror(errno)); - close(fd); - return 0; - } - close(fd); + if (flock(fd, LOCK_UN) == -1) { + printf("Can't unlock pidfile %s, %s.\n", pidfile, strerror(errno)); + close(fd); + return 0; + } + close(fd); - return pid; + return pid; } /* touch_pid @@ -124,9 +126,9 @@ int write_pid (char *pidfile) * Touches the specified pidfile f.ex. when receiving a SIGHUP * The result from utimensat() is returned */ -int touch_pid (char *pidfile) +int touch_pid(char *pidfile) { - return utimensat(0, pidfile, NULL, 0); + return utimensat(0, pidfile, NULL, 0); } /* remove_pid @@ -134,8 +136,14 @@ int touch_pid (char *pidfile) * Remove the the specified file. The result from unlink(2) * is returned */ -int remove_pid (char *pidfile) +int remove_pid(char *pidfile) { - return unlink (pidfile); + return unlink(pidfile); } - + +/** + * Local Variables: + * indent-tabs-mode: t + * c-file-style: "linux" + * End: + */ diff --git a/src/pidfile.h b/src/pidfile.h index 8f1e490..d67fc01 100644 --- a/src/pidfile.h +++ b/src/pidfile.h @@ -1,23 +1,23 @@ /* - pidfile.h - interact with pidfiles - Copyright (c) 1995 Martin Schulze - - This file is part of the sysklogd package, a kernel and system log daemon. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. -*/ + * pidfile.h - interact with pidfiles + * Copyright (c) 1995 Martin Schulze + * + * This file is part of the sysklogd package, a kernel and system log daemon. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + */ /* read_pid * diff --git a/src/syslog.c b/src/syslog.c index 99b968d..d391a22 100644 --- a/src/syslog.c +++ b/src/syslog.c @@ -52,32 +52,31 @@ static char sccsid[] = "@(#)syslog.c 5.28 (Berkeley) 6/27/90"; * reconnect klogd to the logger after it went away. */ -#include -#include +#include +#include +#include +#include +#include +#include +#include #include +#include #include +#include #include #include -#include -#include #include #include -#include -#include -#include -#include -#include -#define _PATH_LOGNAME "/dev/log" +#define _PATH_LOGNAME "/dev/log" -static int LogFile = -1; /* fd for log */ -static int connected; /* have done connect */ -static int LogStat = 0; /* status bits, set by openlog() */ -static const char *LogTag = "syslog"; /* string to tag the entry with */ -static int LogFacility = LOG_USER; /* default facility code */ +static int LogFile = -1; /* fd for log */ +static int connected; /* have done connect */ +static int LogStat = 0; /* status bits, set by openlog() */ +static const char *LogTag = "syslog"; /* string to tag the entry with */ +static int LogFacility = LOG_USER; /* default facility code */ -void -syslog(int pri, const char *fmt, ...) +void syslog(int pri, const char *fmt, ...) { va_list ap; @@ -86,23 +85,19 @@ syslog(int pri, const char *fmt, ...) va_end(ap); } -void -vsyslog(pri, fmt, ap) - int pri; - const char *fmt; - va_list ap; +void vsyslog(int pri, const char *fmt, va_list ap) { - register int cnt; - register char *p; + int cnt; + char * p; time_t now; - int fd, saved_errno; - int result; - char tbuf[2048], fmt_cpy[1024], *stdp = (char *) 0; + int fd, saved_errno; + int result; + char tbuf[2048], fmt_cpy[1024], *stdp = NULL; saved_errno = errno; /* see if we should just throw out this message */ - if (!LOG_MASK(LOG_PRI(pri)) || (pri &~ (LOG_PRIMASK|LOG_FACMASK))) + if (!LOG_MASK(LOG_PRI(pri)) || (pri & ~(LOG_PRIMASK | LOG_FACMASK))) return; if (LogFile < 0 || !connected) openlog(LogTag, LogStat | LOG_NDELAY, LogFacility); @@ -114,16 +109,19 @@ vsyslog(pri, fmt, ap) /* build the message */ (void)time(&now); (void)sprintf(tbuf, "<%d>%.15s ", pri, ctime(&now) + 4); - for (p = tbuf; *p; ++p); + for (p = tbuf; *p; ++p) + ; if (LogStat & LOG_PERROR) stdp = p; if (LogTag) { (void)strcpy(p, LogTag); - for (; *p; ++p); + for (; *p; ++p) + ; } if (LogStat & LOG_PID) { (void)sprintf(p, "[%d]", getpid()); - for (; *p; ++p); + for (; *p; ++p) + ; } if (LogTag) { *p++ = ':'; @@ -132,18 +130,18 @@ vsyslog(pri, fmt, ap) /* substitute error message for %m */ { - register char ch, *t1, *t2; + char ch, *t1, *t2; char *strerror(); for (t1 = fmt_cpy; - (ch = *fmt) != '\0' && t1iov_base = stdp; v->iov_len = cnt - (stdp - tbuf); @@ -168,21 +166,20 @@ vsyslog(pri, fmt, ap) /* output the message to the local logger */ result = write(LogFile, tbuf, cnt + 1); - if (result == -1 - && (errno == ECONNRESET || errno == ENOTCONN || errno == ECONNREFUSED)) { + if (result == -1 && (errno == ECONNRESET || errno == ENOTCONN || errno == ECONNREFUSED)) { closelog(); openlog(LogTag, LogStat | LOG_NDELAY, LogFacility); result = write(LogFile, tbuf, cnt + 1); } - if (result >= 0 || !(LogStat&LOG_CONS)) + if (result >= 0 || !(LogStat & LOG_CONS)) return; /* * output the message to the console; don't worry about * blocking, if console blocks everything will. */ - if ((fd = open(_PATH_CONSOLE, O_WRONLY|O_NOCTTY, 0)) < 0) + if ((fd = open(_PATH_CONSOLE, O_WRONLY | O_NOCTTY, 0)) < 0) return; (void)strcat(tbuf, "\r\n"); cnt += 2; @@ -192,24 +189,21 @@ vsyslog(pri, fmt, ap) } #ifndef TESTING -static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */ +static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */ #endif /* * OPENLOG -- open system log */ -void -openlog(ident, logstat, logfac) - const char *ident; - int logstat, logfac; +void openlog(const char *ident, int logstat, int logfac) { if (ident != NULL) LogTag = ident; LogStat = logstat; #ifdef ALLOW_KERNEL_LOGGING - if ((logfac &~ LOG_FACMASK) == 0) + if ((logfac & ~LOG_FACMASK) == 0) #else - if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0) + if (logfac != 0 && (logfac & ~LOG_FACMASK) == 0) #endif LogFacility = logfac; @@ -217,17 +211,16 @@ openlog(ident, logstat, logfac) if (LogFile == -1) { SyslogAddr.sa_family = AF_UNIX; strncpy(SyslogAddr.sa_data, _PATH_LOGNAME, - sizeof(SyslogAddr.sa_data)); + sizeof(SyslogAddr.sa_data)); if (LogStat & LOG_NDELAY) { LogFile = socket(AF_UNIX, SOCK_DGRAM, 0); -/* fcntl(LogFile, F_SETFD, 1); */ + /* fcntl(LogFile, F_SETFD, 1); */ } } if (LogFile != -1 && !connected && - connect(LogFile, &SyslogAddr, sizeof(SyslogAddr.sa_family)+ - strlen(SyslogAddr.sa_data)) != -1) + connect(LogFile, &SyslogAddr, sizeof(SyslogAddr.sa_family) + strlen(SyslogAddr.sa_data)) != -1) #else - LogFile = fileno(stdout); + LogFile = fileno(stdout); #endif connected = 1; } @@ -235,23 +228,20 @@ openlog(ident, logstat, logfac) /* * CLOSELOG -- close the system log */ -void -closelog() +void closelog() { #ifndef TESTING - (void) close(LogFile); + (void)close(LogFile); #endif LogFile = -1; connected = 0; } -static int LogMask = 0xff; /* mask of priorities to be logged */ +static int LogMask = 0xff; /* mask of priorities to be logged */ /* * SETLOGMASK -- set the log mask level */ -int -setlogmask(pmask) - int pmask; +int setlogmask(int pmask) { int omask; @@ -260,3 +250,10 @@ setlogmask(pmask) LogMask = pmask; return (omask); } + +/** + * Local Variables: + * indent-tabs-mode: t + * c-file-style: "linux" + * End: + */ diff --git a/src/syslog_tst.c b/src/syslog_tst.c index 56e2d81..6004bd8 100644 --- a/src/syslog_tst.c +++ b/src/syslog_tst.c @@ -17,47 +17,38 @@ #include #include +#include #include #include -#include extern int main(int, char **); - int main(int argc, char *argv[]) { - auto char *nl, - bufr[512]; - auto int logged = 0; - + char *nl, + char bufr[512]; + int logged = 0; + openlog("DOTEST", LOG_PID, LOG_DAEMON); - if (argc > 1) - { - if ( (*argv[1] == '-') && (*(argv[1]+1) == '\0') ) - { + if (argc > 1) { + if ((*argv[1] == '-') && (*(argv[1] + 1) == '\0')) { while (!feof(stdin)) - if ( fgets(bufr, sizeof(bufr), stdin) != \ - (char *) 0 ) - { - if ( (nl = strrchr(bufr, '\n')) != \ - (char *) 0) + if (fgets(bufr, sizeof(bufr), stdin) != + (char *)0) { + if ((nl = strrchr(bufr, '\n')) != + (char *)0) *nl = '\0'; - syslog(LOG_INFO, "%s", bufr); + syslog(LOG_INFO, "%s", bufr); logged += strlen(bufr); - if ( logged > 1024 ) - { + if (logged > 1024) { sleep(1); logged = 0; } - } - } - else + } else while (argc-- > 1) - syslog(LOG_INFO, "%s", argv++[1]); - } - else - { + syslog(LOG_INFO, "%s", argv++ [1]); + } else { syslog(LOG_EMERG, "EMERG log."); syslog(LOG_ALERT, "Alert log."); syslog(LOG_CRIT, "Critical log."); @@ -67,8 +58,15 @@ int main(int argc, char *argv[]) syslog(LOG_INFO, "Info log."); syslog(LOG_DEBUG, "Debug log."); closelog(); - return(0); + return (0); } - return(0); + return (0); } + +/** + * Local Variables: + * indent-tabs-mode: t + * c-file-style: "linux" + * End: + */ diff --git a/src/syslogd.c b/src/syslogd.c index 6357022..9912719 100644 --- a/src/syslogd.c +++ b/src/syslogd.c @@ -17,7 +17,7 @@ #if !defined(lint) && !defined(NO_SCCS) char copyright2[] = -"@(#) Copyright (c) 1983, 1988 Regents of the University of California.\n\ + "@(#) Copyright (c) 1983, 1988 Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ @@ -511,49 +511,48 @@ static char sccsid[] = "@(#)syslogd.c 5.27 (Berkeley) 10/10/88"; * on 64bit architectures, patch by David Couture. */ +#define MAXLINE 1024 /* maximum line length */ +#define MAXSVLINE 240 /* maximum saved line length */ +#define DEFUPRI (LOG_USER | LOG_NOTICE) +#define DEFSPRI (LOG_KERN | LOG_CRIT) +#define TIMERINTVL 30 /* interval for checking flush, mark */ +#define RCVBUF_MINSIZE (80 * 1024) /* minimum size of dgram rcv buffer */ -#define MAXLINE 1024 /* maximum line length */ -#define MAXSVLINE 240 /* maximum saved line length */ -#define DEFUPRI (LOG_USER|LOG_NOTICE) -#define DEFSPRI (LOG_KERN|LOG_CRIT) -#define TIMERINTVL 30 /* interval for checking flush, mark */ -#define RCVBUF_MINSIZE (80 * 1024) /* minimum size of dgram rcv buffer */ +#define CONT_LINE 1 /* Allow continuation lines */ -#define CONT_LINE 1 /* Allow continuation lines */ - -#include -#include -#include -#include -#include #include -#include #include #include +#include +#include +#include +#include #include +#include +#include #define SYSLOG_NAMES -#include -#include #include -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include +#include -#include -#include -#include -#include #include +#include +#include +#include #include +#include #ifndef TESTING #include "pidfile.h" #endif @@ -575,8 +574,8 @@ static char sccsid[] = "@(#)syslogd.c 5.27 (Berkeley) 10/10/88"; #endif #endif -#ifndef _PATH_LOGCONF -#define _PATH_LOGCONF "/etc/syslog.conf" +#ifndef _PATH_LOGCONF +#define _PATH_LOGCONF "/etc/syslog.conf" #endif #if defined(SYSLOGD_PIDNAME) @@ -597,73 +596,75 @@ static char sccsid[] = "@(#)syslogd.c 5.27 (Berkeley) 10/10/88"; #endif #ifndef _PATH_DEV -#define _PATH_DEV "/dev/" +#define _PATH_DEV "/dev/" #endif #ifndef _PATH_CONSOLE -#define _PATH_CONSOLE "/dev/console" +#define _PATH_CONSOLE "/dev/console" #endif #ifndef _PATH_TTY -#define _PATH_TTY "/dev/tty" +#define _PATH_TTY "/dev/tty" #endif #ifndef _PATH_LOG -#define _PATH_LOG "/dev/log" +#define _PATH_LOG "/dev/log" #endif -char *ConfFile = _PATH_LOGCONF; -char *PidFile = _PATH_LOGPID; -char ctty[] = _PATH_CONSOLE; +char *ConfFile = _PATH_LOGCONF; +char *PidFile = _PATH_LOGPID; +char ctty[] = _PATH_CONSOLE; -char **parts; +char **parts; static int debugging_on = 0; static int nlogs = -1; static int restart = 0; -#define MAXFUNIX 20 +#define MAXFUNIX 20 -int nfunix = 1; +int nfunix = 1; char *funixn[MAXFUNIX] = { _PATH_LOG }; -int funix[MAXFUNIX] = { -1, }; +int funix[MAXFUNIX] = { + -1, +}; #ifdef UT_NAMESIZE -# define UNAMESZ UT_NAMESIZE /* length of a login name */ +#define UNAMESZ UT_NAMESIZE /* length of a login name */ #else -# define UNAMESZ 8 /* length of a login name */ +#define UNAMESZ 8 /* length of a login name */ #endif -#define MAXUNAMES 20 /* maximum number of user names */ -#define MAXFNAME 200 /* max file pathname length */ +#define MAXUNAMES 20 /* maximum number of user names */ +#define MAXFNAME 200 /* max file pathname length */ -#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */ -#define TABLE_NOPRI 0 /* Value to indicate no priority in f_pmask */ -#define TABLE_ALLPRI 0xFF /* Value to indicate all priorities in f_pmask */ -#define LOG_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0) /* mark "facility" */ +#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */ +#define TABLE_NOPRI 0 /* Value to indicate no priority in f_pmask */ +#define TABLE_ALLPRI 0xFF /* Value to indicate all priorities in f_pmask */ +#define LOG_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0) /* mark "facility" */ -#define MAX_PRI 191 /* Maximum Priority per RFC 3164 */ +#define MAX_PRI 191 /* Maximum Priority per RFC 3164 */ /* * Flags to logmsg(). */ -#define IGN_CONS 0x001 /* don't print on console */ -#define SYNC_FILE 0x002 /* do fsync on file after printing */ -#define ADDDATE 0x004 /* add a date to the message */ -#define MARK 0x008 /* this message is a mark */ +#define IGN_CONS 0x001 /* don't print on console */ +#define SYNC_FILE 0x002 /* do fsync on file after printing */ +#define ADDDATE 0x004 /* add a date to the message */ +#define MARK 0x008 /* this message is a mark */ /* * This table contains plain text for h_errno errors used by the * net subsystem. */ const char *sys_h_errlist[] = { - "No problem", /* NETDB_SUCCESS */ - "Authoritative answer: host not found", /* HOST_NOT_FOUND */ - "Non-authoritative answer: host not found, or serverfail", /* TRY_AGAIN */ - "Non recoverable errors", /* NO_RECOVERY */ - "Valid name, no data record of requested type", /* NO_DATA */ - "no address, look for MX record" /* NO_ADDRESS */ - }; + "No problem", /* NETDB_SUCCESS */ + "Authoritative answer: host not found", /* HOST_NOT_FOUND */ + "Non-authoritative answer: host not found, or serverfail", /* TRY_AGAIN */ + "Non recoverable errors", /* NO_RECOVERY */ + "Valid name, no data record of requested type", /* NO_DATA */ + "no address, look for MX record" /* NO_ADDRESS */ +}; /* * This structure represents the files that will have log @@ -672,29 +673,29 @@ const char *sys_h_errlist[] = { struct filed { #ifndef SYSV - struct filed *f_next; /* next in linked list */ + struct filed *f_next; /* next in linked list */ #endif - short f_type; /* entry type, see below */ - short f_file; /* file descriptor */ - time_t f_time; /* time this was last written */ - char *f_host; /* host from which to recd. */ - u_char f_pmask[LOG_NFACILITIES+1]; /* priority mask */ + short f_type; /* entry type, see below */ + short f_file; /* file descriptor */ + time_t f_time; /* time this was last written */ + char * f_host; /* host from which to recd. */ + u_char f_pmask[LOG_NFACILITIES + 1]; /* priority mask */ union { - char f_uname[MAXUNAMES][UNAMESZ+1]; + char f_uname[MAXUNAMES][UNAMESZ + 1]; struct { - char f_hname[MAXHOSTNAMELEN+1]; - struct addrinfo *f_addr; - } f_forw; /* forwarding address */ - char f_fname[MAXFNAME]; + char f_hname[MAXHOSTNAMELEN + 1]; + struct addrinfo *f_addr; + } f_forw; /* forwarding address */ + char f_fname[MAXFNAME]; } f_un; - char f_prevline[MAXSVLINE]; /* last message logged */ - char f_lasttime[16]; /* time of last occurrence */ - char f_prevhost[MAXHOSTNAMELEN+1]; /* host from which recd. */ - int f_prevpri; /* pri of f_prevline */ - int f_prevlen; /* length of f_prevline */ - int f_prevcount; /* repetition cnt of prevline */ - size_t f_repeatcount; /* number of "repeated" msgs */ - int f_flags; /* store some additional flags */ + char f_prevline[MAXSVLINE]; /* last message logged */ + char f_lasttime[16]; /* time of last occurrence */ + char f_prevhost[MAXHOSTNAMELEN + 1]; /* host from which recd. */ + int f_prevpri; /* pri of f_prevline */ + int f_prevlen; /* length of f_prevline */ + int f_prevcount; /* repetition cnt of prevline */ + size_t f_repeatcount; /* number of "repeated" msgs */ + int f_flags; /* store some additional flags */ }; /* @@ -702,146 +703,147 @@ struct filed { * in seconds after previous message is logged. After each flush, * we move to the next interval until we reach the largest. */ -int repeatinterval[] = { 30, 60 }; /* # of secs before flush */ -#define MAXREPEAT ((sizeof(repeatinterval) / sizeof(repeatinterval[0])) - 1) -#define REPEATTIME(f) ((f)->f_time + repeatinterval[(f)->f_repeatcount]) -#define BACKOFF(f) { if (++(f)->f_repeatcount > MAXREPEAT) \ - (f)->f_repeatcount = MAXREPEAT; \ - } +int repeatinterval[] = { 30, 60 }; /* # of secs before flush */ +#define MAXREPEAT ((sizeof(repeatinterval) / sizeof(repeatinterval[0])) - 1) +#define REPEATTIME(f) ((f)->f_time + repeatinterval[(f)->f_repeatcount]) +#define BACKOFF(f) \ + { \ + if (++(f)->f_repeatcount > MAXREPEAT) \ + (f)->f_repeatcount = MAXREPEAT; \ + } #ifdef SYSLOG_INET #ifndef INET_SUSPEND_TIME -#define INET_SUSPEND_TIME 180 /* equal to 3 minutes */ +#define INET_SUSPEND_TIME 180 /* equal to 3 minutes */ #endif -#define INET_RETRY_MAX 10 /* maximum of retries for getaddrinfo() */ +#define INET_RETRY_MAX 10 /* maximum of retries for getaddrinfo() */ #endif -#define LIST_DELIMITER ':' /* delimiter between two hosts */ +#define LIST_DELIMITER ':' /* delimiter between two hosts */ /* values for f_type */ -#define F_UNUSED 0 /* unused entry */ -#define F_FILE 1 /* regular file */ -#define F_TTY 2 /* terminal */ -#define F_CONSOLE 3 /* console terminal */ -#define F_FORW 4 /* remote machine */ -#define F_USERS 5 /* list of users */ -#define F_WALL 6 /* everyone logged on */ -#define F_FORW_SUSP 7 /* suspended host forwarding */ -#define F_FORW_UNKN 8 /* unknown host forwarding */ -#define F_PIPE 9 /* named pipe */ -char *TypeNames[] = { - "UNUSED", "FILE", "TTY", "CONSOLE", - "FORW", "USERS", "WALL", "FORW(SUSPENDED)", +#define F_UNUSED 0 /* unused entry */ +#define F_FILE 1 /* regular file */ +#define F_TTY 2 /* terminal */ +#define F_CONSOLE 3 /* console terminal */ +#define F_FORW 4 /* remote machine */ +#define F_USERS 5 /* list of users */ +#define F_WALL 6 /* everyone logged on */ +#define F_FORW_SUSP 7 /* suspended host forwarding */ +#define F_FORW_UNKN 8 /* unknown host forwarding */ +#define F_PIPE 9 /* named pipe */ +char *TypeNames[] = { + "UNUSED", "FILE", "TTY", "CONSOLE", + "FORW", "USERS", "WALL", "FORW(SUSPENDED)", "FORW(UNKNOWN)", "PIPE" }; -struct filed *Files = (struct filed *) 0; -struct filed consfile; +struct filed *Files = NULL; +struct filed consfile; struct code { - char *c_name; - int c_val; + char *c_name; + int c_val; }; -struct code PriNames[] = { - {"alert", LOG_ALERT}, - {"crit", LOG_CRIT}, - {"debug", LOG_DEBUG}, - {"emerg", LOG_EMERG}, - {"err", LOG_ERR}, - {"error", LOG_ERR}, /* DEPRECATED */ - {"info", LOG_INFO}, - {"none", INTERNAL_NOPRI}, /* INTERNAL */ - {"notice", LOG_NOTICE}, - {"panic", LOG_EMERG}, /* DEPRECATED */ - {"warn", LOG_WARNING}, /* DEPRECATED */ - {"warning", LOG_WARNING}, - {"*", TABLE_ALLPRI}, - {NULL, -1} +struct code PriNames[] = { + { "alert", LOG_ALERT }, + { "crit", LOG_CRIT }, + { "debug", LOG_DEBUG }, + { "emerg", LOG_EMERG }, + { "err", LOG_ERR }, + { "error", LOG_ERR }, /* DEPRECATED */ + { "info", LOG_INFO }, + { "none", INTERNAL_NOPRI }, /* INTERNAL */ + { "notice", LOG_NOTICE }, + { "panic", LOG_EMERG }, /* DEPRECATED */ + { "warn", LOG_WARNING }, /* DEPRECATED */ + { "warning", LOG_WARNING }, + { "*", TABLE_ALLPRI }, + { NULL, -1 } }; -struct code FacNames[] = { - {"auth", LOG_AUTH}, - {"authpriv", LOG_AUTHPRIV}, - {"cron", LOG_CRON}, - {"daemon", LOG_DAEMON}, - {"kern", LOG_KERN}, - {"lpr", LOG_LPR}, - {"mail", LOG_MAIL}, - {"mark", LOG_MARK}, /* INTERNAL */ - {"news", LOG_NEWS}, - {"security", LOG_AUTH}, /* DEPRECATED */ - {"syslog", LOG_SYSLOG}, - {"user", LOG_USER}, - {"uucp", LOG_UUCP}, +struct code FacNames[] = { + { "auth", LOG_AUTH }, + { "authpriv", LOG_AUTHPRIV }, + { "cron", LOG_CRON }, + { "daemon", LOG_DAEMON }, + { "kern", LOG_KERN }, + { "lpr", LOG_LPR }, + { "mail", LOG_MAIL }, + { "mark", LOG_MARK }, /* INTERNAL */ + { "news", LOG_NEWS }, + { "security", LOG_AUTH }, /* DEPRECATED */ + { "syslog", LOG_SYSLOG }, + { "user", LOG_USER }, + { "uucp", LOG_UUCP }, #if defined(LOG_FTP) - {"ftp", LOG_FTP}, + { "ftp", LOG_FTP }, #endif - {"local0", LOG_LOCAL0}, - {"local1", LOG_LOCAL1}, - {"local2", LOG_LOCAL2}, - {"local3", LOG_LOCAL3}, - {"local4", LOG_LOCAL4}, - {"local5", LOG_LOCAL5}, - {"local6", LOG_LOCAL6}, - {"local7", LOG_LOCAL7}, - {NULL, -1}, + { "local0", LOG_LOCAL0 }, + { "local1", LOG_LOCAL1 }, + { "local2", LOG_LOCAL2 }, + { "local3", LOG_LOCAL3 }, + { "local4", LOG_LOCAL4 }, + { "local5", LOG_LOCAL5 }, + { "local6", LOG_LOCAL6 }, + { "local7", LOG_LOCAL7 }, + { NULL, -1 }, }; -int Debug; /* debug flag */ -char LocalHostName[MAXHOSTNAMELEN+1]; /* our hostname */ -char *LocalDomain; /* our local domain name */ -char *emptystring = ""; -int InetInuse = 0; /* non-zero if INET sockets are being used */ -int *finet = NULL; /* Internet datagram sockets */ -int Initialized = 0; /* set when we have initialized ourselves */ -int MarkInterval = 20 * 60; /* interval between marks in seconds */ +int Debug; /* debug flag */ +char LocalHostName[MAXHOSTNAMELEN + 1]; /* our hostname */ +char *LocalDomain; /* our local domain name */ +char *emptystring = ""; +int InetInuse = 0; /* non-zero if INET sockets are being used */ +int *finet = NULL; /* Internet datagram sockets */ +int Initialized = 0; /* set when we have initialized ourselves */ +int MarkInterval = 20 * 60; /* interval between marks in seconds */ #ifdef INET6 -int family = PF_UNSPEC; /* protocol family (IPv4, IPv6 or both) */ +int family = PF_UNSPEC; /* protocol family (IPv4, IPv6 or both) */ #else -int family = PF_INET; /* protocol family (IPv4 only) */ +int family = PF_INET; /* protocol family (IPv4 only) */ #endif -int send_to_all = 0; /* send message to all IPv4/IPv6 addresses */ -int MarkSeq = 0; /* mark sequence number */ -int LastAlarm = 0; /* last value passed to alarm() (seconds) */ -int DupesPending = 0; /* Number of unflushed duplicate messages */ -int NoFork = 0; /* don't fork - don't run in daemon mode */ -int AcceptRemote = 0; /* receive messages that come via UDP */ -char **StripDomains = NULL; /* these domains may be stripped before writing logs */ -char **LocalHosts = NULL; /* these hosts are logged with their hostname */ -int NoHops = 1; /* Can we bounce syslog messages through an - intermediate host. */ -int RotateSz = 0; /* Max file size (bytes) before rotating, disabled by default */ -int RotateCnt = 5; /* Max number (count) of log files to keep, set with -c */ -extern int errno; +int send_to_all = 0; /* send message to all IPv4/IPv6 addresses */ +int MarkSeq = 0; /* mark sequence number */ +int LastAlarm = 0; /* last value passed to alarm() (seconds) */ +int DupesPending = 0; /* Number of unflushed duplicate messages */ +int NoFork = 0; /* don't fork - don't run in daemon mode */ +int AcceptRemote = 0; /* receive messages that come via UDP */ +char **StripDomains = NULL; /* these domains may be stripped before writing logs */ +char **LocalHosts = NULL; /* these hosts are logged with their hostname */ +int NoHops = 1; /* Can we bounce syslog messages through an intermediate host. */ +int RotateSz = 0; /* Max file size (bytes) before rotating, disabled by default */ +int RotateCnt = 5; /* Max number (count) of log files to keep, set with -c */ +extern int errno; /* Function prototypes. */ -int main(int argc, char **argv); -char **crunch_list(char *list); -int usage(int code); -void untty(void); -void printchopped(const char *hname, char *msg, size_t len, int fd); -void printline(const char *hname, char *msg); -void printsys(char *msg); -void logmsg(int pri, char *msg, const char *from, int flags); -void fprintlog(register struct filed *f, char *from, int flags, char *msg); -void endtty(); -void wallmsg(register struct filed *f, struct iovec *iov); -void reapchild(); +int main(int argc, char **argv); +char **crunch_list(char *list); +int usage(int code); +void untty(void); +void printchopped(const char *hname, char *msg, size_t len, int fd); +void printline(const char *hname, char *msg); +void printsys(char *msg); +void logmsg(int pri, char *msg, const char *from, int flags); +void fprintlog(struct filed *f, char *from, int flags, char *msg); +void endtty(); +void wallmsg(struct filed *f, struct iovec *iov); +void reapchild(); const char *cvtaddr(struct sockaddr_storage *f, int len); const char *cvthname(struct sockaddr_storage *f, int len); -void domark(); -void debug_switch(); -void logerror(const char *type); -void die(int sig); +void domark(); +void debug_switch(); +void logerror(const char *type); +void die(int sig); #ifndef TESTING void doexit(int sig); #endif -void init(); -void cfline(char *line, register struct filed *f); -int decode(char *name, struct code *codetab); +void init(); +void cfline(char *line, struct filed *f); +int decode(char *name, struct code *codetab); static void logit(char *, ...); static void allocate_log(void); -void sighup_handler(); +void sighup_handler(int); #ifdef SYSLOG_UNIXAF static int create_unix_socket(const char *path); @@ -850,11 +852,9 @@ static int create_unix_socket(const char *path); static int *create_inet_sockets(); #endif -int main(argc, argv) - int argc; - char **argv; +int main(int argc, char *argv[]) { - register int i; + int i; #ifndef TESTING ssize_t msglen; #endif @@ -882,109 +882,126 @@ int main(argc, argv) fd_set readfds; #ifndef TESTING - int fd; -#ifdef SYSLOG_INET + int fd; +#ifdef SYSLOG_INET struct sockaddr_storage frominet; #endif pid_t ppid = getpid(); #endif int ch; - char line[MAXLINE +1]; + char line[MAXLINE + 1]; extern int optind; extern char *optarg; int maxfds; #ifndef TESTING - chdir ("/"); + chdir("/"); #endif for (i = 1; i < MAXFUNIX; i++) { funixn[i] = ""; - funix[i] = -1; + funix[i] = -1; } - while ((ch = getopt(argc, argv, "46Aa:b:c:dhf:l:m:np:rs:v?")) != EOF) - switch((char)ch) { + while ((ch = getopt(argc, argv, "46Aa:b:c:dhf:l:m:np:rs:v?")) != EOF) { + switch ((char)ch) { case '4': family = PF_INET; break; + #ifdef INET6 case '6': family = PF_INET6; break; #endif + case 'A': send_to_all++; break; + case 'a': if (nfunix < MAXFUNIX) funixn[nfunix++] = optarg; else fprintf(stderr, "Out of descriptors, ignoring %s\n", optarg); break; - case 'b': /* Max file size (bytes) before rotating log file. */ + + case 'b': /* Max file size (bytes) before rotating log file. */ RotateSz = atoi(optarg); break; - case 'c': /* Number (count) of log files to keep. */ + + case 'c': /* Number (count) of log files to keep. */ RotateCnt = atoi(optarg); break; - case 'd': /* debug */ + + case 'd': /* debug */ Debug = 1; break; - case 'f': /* configuration file */ + + case 'f': /* configuration file */ ConfFile = optarg; break; + case 'h': NoHops = 0; break; + case 'l': if (LocalHosts) { - fprintf (stderr, "Only one -l argument allowed," \ - "the first one is taken.\n"); + fprintf(stderr, "Only one -l argument allowed," + "the first one is taken.\n"); break; } LocalHosts = crunch_list(optarg); break; - case 'm': /* mark interval */ + + case 'm': /* mark interval */ MarkInterval = atoi(optarg) * 60; break; - case 'n': /* don't fork */ + + case 'n': /* don't fork */ NoFork = 1; break; - case 'p': /* path to regular log socket */ + + case 'p': /* path to regular log socket */ funixn[0] = optarg; break; - case 'r': /* accept remote messages */ + + case 'r': /* accept remote messages */ AcceptRemote = 1; break; + case 's': if (StripDomains) { - fprintf (stderr, "Only one -s argument allowed," \ - "the first one is taken.\n"); + fprintf(stderr, "Only one -s argument allowed," + "the first one is taken.\n"); break; } StripDomains = crunch_list(optarg); break; + case 'v': printf("syslogd v%s\n", VERSION); - exit (0); + exit(0); + case '?': usage(0); break; + default: usage(1); break; } + } + if ((argc -= optind)) usage(1); #ifndef TESTING - if ( !(Debug || NoFork) ) - { + if (!(Debug || NoFork)) { logit("Checking pidfile.\n"); - if (!check_pid(PidFile)) - { - signal (SIGTERM, doexit); + if (!check_pid(PidFile)) { + signal(SIGTERM, doexit); if (fork()) { /* * Parent process @@ -1000,19 +1017,16 @@ int main(argc, argv) */ exit(1); } - signal (SIGTERM, SIG_DFL); + signal(SIGTERM, SIG_DFL); num_fds = getdtablesize(); - for (i= 0; i < num_fds; i++) - (void) close(i); + for (i = 0; i < num_fds; i++) + (void)close(i); untty(); - } - else - { + } else { fputs("syslogd: Already running.\n", stderr); exit(1); } - } - else + } else #endif debugging_on = 1; #ifndef SYSV @@ -1022,43 +1036,38 @@ int main(argc, argv) #ifndef TESTING /* tuck my process id away */ - if ( !Debug ) - { + if (!Debug) { logit("Writing pidfile.\n"); - if (!check_pid(PidFile)) - { - if (!write_pid(PidFile)) - { + if (!check_pid(PidFile)) { + if (!write_pid(PidFile)) { logit("Can't write pid.\n"); if (getpid() != ppid) - kill (ppid, SIGTERM); + kill(ppid, SIGTERM); exit(1); } - } - else - { + } else { logit("Pidfile (and pid) already exist.\n"); if (getpid() != ppid) - kill (ppid, SIGTERM); + kill(ppid, SIGTERM); exit(1); } } /* if ( !Debug ) */ #endif consfile.f_type = F_CONSOLE; - (void) strcpy(consfile.f_un.f_fname, ctty); + (void)strcpy(consfile.f_un.f_fname, ctty); /* Initialization is done by init() */ - (void) strcpy(LocalHostName, emptystring); + (void)strcpy(LocalHostName, emptystring); LocalDomain = emptystring; - (void) signal(SIGTERM, die); - (void) signal(SIGINT, Debug ? die : SIG_IGN); - (void) signal(SIGQUIT, Debug ? die : SIG_IGN); - (void) signal(SIGCHLD, reapchild); - (void) signal(SIGALRM, domark); - (void) signal(SIGUSR1, Debug ? debug_switch : SIG_IGN); - (void) signal(SIGXFSZ, SIG_IGN); + (void)signal(SIGTERM, die); + (void)signal(SIGINT, Debug ? die : SIG_IGN); + (void)signal(SIGQUIT, Debug ? die : SIG_IGN); + (void)signal(SIGCHLD, reapchild); + (void)signal(SIGALRM, domark); + (void)signal(SIGUSR1, Debug ? debug_switch : SIG_IGN); + (void)signal(SIGXFSZ, SIG_IGN); LastAlarm = MarkInterval; alarm(LastAlarm); @@ -1066,24 +1075,22 @@ int main(argc, argv) /* Create a partial message table for all file descriptors. */ num_fds = getdtablesize(); logit("Allocated parts table for %d file descriptors.\n", num_fds); - if ( (parts = (char **) malloc(num_fds * sizeof(char *))) == \ - (char **) 0 ) - { + if ((parts = (char **)malloc(num_fds * sizeof(char *))) == + (char **)0) { logerror("Cannot allocate memory for message parts table."); #ifndef TESTING if (getpid() != ppid) - kill (ppid, SIGTERM); + kill(ppid, SIGTERM); #endif die(0); } - for(i= 0; i < num_fds; ++i) - parts[i] = (char *) 0; + for (i = 0; i < num_fds; ++i) + parts[i] = (char *)0; logit("Starting.\n"); init(); #ifndef TESTING - if ( Debug ) - { + if (Debug) { logit("Debugging disabled, SIGUSR1 to turn on debugging.\n"); debugging_on = 0; } @@ -1091,7 +1098,7 @@ int main(argc, argv) * Send a signal to the parent to it can terminate. */ if (getpid() != ppid) - kill (ppid, SIGTERM); + kill(ppid, SIGTERM); #endif /* Main loop begins here. */ @@ -1110,7 +1117,8 @@ int main(argc, argv) for (i = 0; i < nfunix; i++) { if (funix[i] != -1) { FD_SET(funix[i], &readfds); - if (funix[i]>maxfds) maxfds=funix[i]; + if (funix[i] > maxfds) + maxfds = funix[i]; } } #endif @@ -1121,11 +1129,12 @@ int main(argc, argv) * Add the Internet Domain Socket to the list of read * descriptors. */ - if ( InetInuse && AcceptRemote ) { + if (InetInuse && AcceptRemote) { for (i = 0; i < *finet; i++) { - if (finet[i+1] != -1) - FD_SET(finet[i+1], &readfds); - if (finet[i+1]>maxfds) maxfds=finet[i+1]; + if (finet[i + 1] != -1) + FD_SET(finet[i + 1], &readfds); + if (finet[i + 1] > maxfds) + maxfds = finet[i + 1]; } logit("Listening on syslog UDP port.\n"); } @@ -1133,23 +1142,22 @@ int main(argc, argv) #endif #ifdef TESTING FD_SET(fileno(stdin), &readfds); - if (fileno(stdin) > maxfds) maxfds = fileno(stdin); + if (fileno(stdin) > maxfds) + maxfds = fileno(stdin); logit("Listening on stdin. Press Ctrl-C to interrupt.\n"); #endif - if ( debugging_on ) - { + if (debugging_on) { logit("Calling select, active file descriptors (max %d): ", maxfds); - for (nfds= 0; nfds <= maxfds; ++nfds) - if ( FD_ISSET(nfds, &readfds) ) + for (nfds = 0; nfds <= maxfds; ++nfds) + if (FD_ISSET(nfds, &readfds)) logit("%d ", nfds); logit("\n"); } - nfds = select(maxfds+1, (fd_set *) &readfds, (fd_set *) NULL, - (fd_set *) NULL, (struct timeval *) NULL); - if ( restart ) - { + nfds = select(maxfds + 1, (fd_set *)&readfds, (fd_set *)NULL, + (fd_set *)NULL, (struct timeval *)NULL); + if (restart) { restart = 0; logit("\nReceived SIGHUP, reloading syslogd.\n"); init(); @@ -1173,12 +1181,12 @@ int main(argc, argv) continue; } - if ( debugging_on ) - { - logit("\nSuccessful select, descriptor count = %d, " \ - "Activity on: ", nfds); - for (nfds= 0; nfds <= maxfds; ++nfds) - if ( FD_ISSET(nfds, &readfds) ) + if (debugging_on) { + logit("\nSuccessful select, descriptor count = %d, " + "Activity on: ", + nfds); + for (nfds = 0; nfds <= maxfds; ++nfds) + if (FD_ISSET(nfds, &readfds)) logit("%d ", nfds); logit("\n"); } @@ -1186,33 +1194,33 @@ int main(argc, argv) #ifndef TESTING #ifdef SYSLOG_UNIXAF for (i = 0; i < nfunix; i++) { - if ((fd = funix[i]) != -1 && FD_ISSET(fd, &readfds)) { - memset(line, 0, sizeof(line)); - msglen = recv(fd, line, MAXLINE - 2, 0); - logit("Message from UNIX socket: #%d\n", fd); - if (msglen > 0) - printchopped(LocalHostName, line, msglen + 2, fd); - else if (msglen < 0 && errno != EINTR) { - logit("UNIX socket error: %d = %s.\n", \ - errno, strerror(errno)); - logerror("recvfrom UNIX"); + if ((fd = funix[i]) != -1 && FD_ISSET(fd, &readfds)) { + memset(line, 0, sizeof(line)); + msglen = recv(fd, line, MAXLINE - 2, 0); + logit("Message from UNIX socket: #%d\n", fd); + if (msglen > 0) + printchopped(LocalHostName, line, msglen + 2, fd); + else if (msglen < 0 && errno != EINTR) { + logit("UNIX socket error: %d = %s.\n", + errno, strerror(errno)); + logerror("recvfrom UNIX"); + } } - } } #endif #ifdef SYSLOG_INET if (InetInuse && AcceptRemote && finet) { for (i = 0; i < *finet; i++) { - if (finet[i+1] != -1 && FD_ISSET(finet[i+1], &readfds)) { + if (finet[i + 1] != -1 && FD_ISSET(finet[i + 1], &readfds)) { len = sizeof(frominet); memset(line, 0, sizeof(line)); - msglen = recvfrom(finet[i+1], line, MAXLINE - 2, 0, \ - (struct sockaddr *) &frominet, &len); + msglen = recvfrom(finet[i + 1], line, MAXLINE - 2, 0, + (struct sockaddr *)&frominet, &len); if (Debug) { const char *addr = cvtaddr(&frominet, len); logit("Message from inetd socket: #%d, host: %s\n", - i+1, addr); + i + 1, addr); } if (msglen > 0) { /* Note that if cvthname() returns NULL then @@ -1220,10 +1228,10 @@ int main(argc, argv) const char *from = cvthname(&frominet, len); if (from) printchopped(from, line, - msglen + 2, finet[i+1]); + msglen + 2, finet[i + 1]); } else if (msglen < 0 && errno != EINTR && errno != EAGAIN) { - logit("INET socket error: %d = %s.\n", \ - errno, strerror(errno)); + logit("INET socket error: %d = %s.\n", + errno, strerror(errno)); logerror("recvfrom inet"); /* should be harmless now that we set * BSDCOMPAT on the socket */ @@ -1234,21 +1242,21 @@ int main(argc, argv) } #endif #else - if ( FD_ISSET(fileno(stdin), &readfds) ) { - logit("Message from stdin.\n"); - memset(line, '\0', sizeof(line)); - line[0] = '.'; - parts[fileno(stdin)] = (char *) 0; - i = read(fileno(stdin), line, MAXLINE); - if (i > 0) { - printchopped(LocalHostName, line, i+1, fileno(stdin)); - } else if (i < 0) { - if (errno != EINTR) { - logerror("stdin"); - } - } - FD_CLR(fileno(stdin), &readfds); - } + if (FD_ISSET(fileno(stdin), &readfds)) { + logit("Message from stdin.\n"); + memset(line, '\0', sizeof(line)); + line[0] = '.'; + parts[fileno(stdin)] = (char *)0; + i = read(fileno(stdin), line, MAXLINE); + if (i > 0) { + printchopped(LocalHostName, line, i + 1, fileno(stdin)); + } else if (i < 0) { + if (errno != EINTR) { + logerror("stdin"); + } + } + FD_CLR(fileno(stdin), &readfds); + } #endif } @@ -1257,30 +1265,31 @@ int main(argc, argv) int usage(int code) { fprintf(stdout, - "Usage:\n" - " syslogd [-46Adnrvh?] [-a SOCK] [-b SIZE] [-c COUNT] [-f FILE] [-l HOST]\n" - " [-m SEC] [-p PATH] [-s LIST]\n" - "\n" - "Options:\n" - " -? Show this help text\n" - " -4 Force IPv4 only\n" - " -6 Force IPv6 only\n" - " -a SOCK Additional socket (max 19) to listen to, used with chroots\n" - " -A Send to all addresses in DNS A, or AAAA record\n" - " -b SIZE Log file rotation, rotate at SIZE bytes, default: disabled\n" - " -c COUNT Number of rotated log files kept\n" - " -d Enable debug mode\n" - " -f FILE Alternate .conf file, default: /etc/syslog.conf\n" - " -h Forward messages from other hosts also to remote syslog host(s)\n" - " -l HOST Host name to log without its FQDN, use ':' for multiple hosts\n" - " -m INTV Interval between MARK messages in log, 0 to disable, default: 20\n" - " -n Run in foreground, required when run from a modern init/supervisor\n" - " -p PATH Alternate path to UNIX domain socket, default: /dev/log\n" - " -r Act as remote syslog sink for other hosts\n" - " -s NAME Strip domain name before logging, use ':' for multiple domains\n" - " -v Show program version and exit\n" - "\n" - "Bug report address: %s\n", PACKAGE_BUGREPORT); + "Usage:\n" + " syslogd [-46Adnrvh?] [-a SOCK] [-b SIZE] [-c COUNT] [-f FILE] [-l HOST]\n" + " [-m SEC] [-p PATH] [-s LIST]\n" + "\n" + "Options:\n" + " -? Show this help text\n" + " -4 Force IPv4 only\n" + " -6 Force IPv6 only\n" + " -a SOCK Additional socket (max 19) to listen to, used with chroots\n" + " -A Send to all addresses in DNS A, or AAAA record\n" + " -b SIZE Log file rotation, rotate at SIZE bytes, default: disabled\n" + " -c COUNT Number of rotated log files kept\n" + " -d Enable debug mode\n" + " -f FILE Alternate .conf file, default: /etc/syslog.conf\n" + " -h Forward messages from other hosts also to remote syslog host(s)\n" + " -l HOST Host name to log without its FQDN, use ':' for multiple hosts\n" + " -m INTV Interval between MARK messages in log, 0 to disable, default: 20\n" + " -n Run in foreground, required when run from a modern init/supervisor\n" + " -p PATH Alternate path to UNIX domain socket, default: /dev/log\n" + " -r Act as remote syslog sink for other hosts\n" + " -s NAME Strip domain name before logging, use ':' for multiple domains\n" + " -v Show program version and exit\n" + "\n" + "Bug report address: %s\n", + PACKAGE_BUGREPORT); exit(code); } @@ -1293,11 +1302,12 @@ static void increase_rcvbuf(int fd) socklen_t len, slen; slen = sizeof(len); - if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &len, &slen) == 0) { - if (len < RCVBUF_MINSIZE) { - len = RCVBUF_MINSIZE; - setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &len, sizeof(len)); - } + if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &len, &slen)) + return; + + if (len < RCVBUF_MINSIZE) { + len = RCVBUF_MINSIZE; + setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &len, sizeof(len)); } } @@ -1305,22 +1315,21 @@ static void increase_rcvbuf(int fd) static int create_unix_socket(const char *path) { struct sockaddr_un sunx; + char line[MAXLINE + 1]; int fd; - char line[MAXLINE +1]; if (path[0] == '\0') return -1; - (void) unlink(path); + (void)unlink(path); memset(&sunx, 0, sizeof(sunx)); sunx.sun_family = AF_UNIX; - (void) strncpy(sunx.sun_path, path, sizeof(sunx.sun_path)); + (void)strncpy(sunx.sun_path, path, sizeof(sunx.sun_path)); fd = socket(AF_UNIX, SOCK_DGRAM, 0); - if (fd < 0 || bind(fd, (struct sockaddr *) &sunx, - sizeof(sunx.sun_family)+strlen(sunx.sun_path)) < 0 || + if (fd < 0 || bind(fd, (struct sockaddr *)&sunx, sizeof(sunx.sun_family) + strlen(sunx.sun_path)) < 0 || chmod(path, 0666) < 0) { - (void) snprintf(line, sizeof(line), "cannot create %s", path); + (void)snprintf(line, sizeof(line), "cannot create %s", path); logerror(line); logit("cannot create %s (%d).\n", path, errno); close(fd); @@ -1337,7 +1346,7 @@ static int create_unix_socket(const char *path) #endif #ifdef SYSLOG_INET -static int *create_inet_sockets() +static int *create_inet_sockets(void) { struct addrinfo hints, *res, *r; int error, maxs, *s, *socks; @@ -1356,14 +1365,15 @@ static int *create_inet_sockets() } /* Count max number of sockets we may open */ - for (maxs = 0, r = res; r; r = r->ai_next, maxs++); - socks = malloc((maxs+1) * sizeof(int)); + for (maxs = 0, r = res; r; r = r->ai_next, maxs++) + ; + socks = malloc((maxs + 1) * sizeof(int)); if (!socks) { logerror("couldn't allocate memory for sockets"); die(0); } - *socks = 0; /* num of sockets counter at start of array */ + *socks = 0; /* num of sockets counter at start of array */ s = socks + 1; for (r = res; r; r = r->ai_next) { *s = socket(r->ai_family, r->ai_socktype, r->ai_protocol); @@ -1373,14 +1383,14 @@ static int *create_inet_sockets() } if (r->ai_family == AF_INET6) { if (setsockopt(*s, IPPROTO_IPV6, IPV6_V6ONLY, - (char *) &on, sizeof(on)) < 0) { + (char *)&on, sizeof(on)) < 0) { logerror("setsockopt (IPV6_ONLY), suspending IPv6"); close(*s); continue; } } if (setsockopt(*s, SOL_SOCKET, SO_REUSEADDR, - (char *) &on, sizeof(on)) < 0 ) { + (char *)&on, sizeof(on)) < 0) { logerror("setsockopt(REUSEADDR), suspending inet"); close(*s); continue; @@ -1425,32 +1435,31 @@ static int *create_inet_sockets() } #endif -char ** -crunch_list(list) - char *list; +char **crunch_list(list) char *list; { - int i, m, n; - char *p, *q; char **result = NULL; + char *p, *q; + int i, m, n; p = list; - + /* strip off trailing delimiters */ - while (*p && p[strlen(p)-1] == LIST_DELIMITER) - p[strlen(p)-1] = '\0'; + while (*p && p[strlen(p) - 1] == LIST_DELIMITER) + p[strlen(p) - 1] = '\0'; /* cut off leading delimiters */ while (p[0] == LIST_DELIMITER) - p++; - + p++; + /* count delimiters to calculate the number of elements */ for (n = i = 0; p[i]; i++) - if (p[i] == LIST_DELIMITER) n++; - + if (p[i] == LIST_DELIMITER) + n++; + if ((result = (char **)malloc(sizeof(char *) * (n + 2))) == NULL) { - printf ("Sorry, can't get enough memory, exiting.\n"); + printf("Sorry, can't get enough memory, exiting.\n"); exit(1); } - + /* * We now can assume that the first and last * characters are different from any delimiters, @@ -1458,18 +1467,19 @@ crunch_list(list) */ m = 0; while ((q = strchr(p, LIST_DELIMITER)) && m < n) { - result[m] = (char *) malloc((q - p + 1) * sizeof(char)); + result[m] = (char *)malloc((q - p + 1) * sizeof(char)); if (result[m] == NULL) { - printf ("Sorry, can't get enough memory, exiting.\n"); + printf("Sorry, can't get enough memory, exiting.\n"); exit(1); } memcpy(result[m], p, q - p); result[m][q - p] = '\0'; - p = q; p++; + p = q; + p++; m++; } if ((result[m] = strdup(p)) == NULL) { - printf ("Sorry, can't get enough memory, exiting.\n"); + printf("Sorry, can't get enough memory, exiting.\n"); exit(1); } result[++m] = NULL; @@ -1482,87 +1492,72 @@ crunch_list(list) return result; } - -void untty() +void untty(void) #ifdef SYSV { - if ( !Debug ) { + if (!Debug) { setsid(); } return; } - #else { int i; - if ( !Debug ) { + if (!Debug) { i = open(_PATH_TTY, O_RDWR); if (i >= 0) { - (void) ioctl(i, (int) TIOCNOTTY, (char *)0); - (void) close(i); + (void)ioctl(i, (int)TIOCNOTTY, (char *)0); + (void)close(i); } } } #endif - /* * Parse the line to make sure that the msg is not a composite of more * than one message. */ - -void printchopped(hname, msg, len, fd) - const char *hname; - char *msg; - size_t len; - int fd; +void printchopped(const char *hname, char *msg, size_t len, int fd) { - auto int ptlngth; - - auto char *start = msg, - *p, - *end, - tmpline[MAXLINE + 1]; + char tmpline[MAXLINE + 1]; + char *start = msg; + char *p, *end; + int ptlngth; logit("Message length: %d, File descriptor: %d.\n", len, fd); tmpline[0] = '\0'; - if ( parts[fd] != (char *) 0 ) - { + if (parts[fd] != (char *)0) { logit("Including part from messages.\n"); strcpy(tmpline, parts[fd]); free(parts[fd]); - parts[fd] = (char *) 0; - if ( (strlen(msg) + strlen(tmpline)) > MAXLINE ) - { + parts[fd] = (char *)0; + if ((strlen(msg) + strlen(tmpline)) > MAXLINE) { logerror("Cannot glue message parts together"); printline(hname, tmpline); start = msg; - } - else - { + } else { logit("Previous: %s\n", tmpline); logit("Next: %s\n", msg); - strcat(tmpline, msg); /* length checked above */ + strcat(tmpline, msg); /* length checked above */ printline(hname, tmpline); - if ( (strlen(msg) + 1) == len ) + if ((strlen(msg) + 1) == len) return; else start = strchr(msg, '\0') + 1; } } - if ( msg[len-1] != '\0' ) - { + if (msg[len - 1] != '\0') { msg[len] = '\0'; - for(p= msg+len-1; *p != '\0' && p > msg; ) + for (p = msg + len - 1; *p != '\0' && p > msg;) --p; - if(*p == '\0') p++; + if (*p == '\0') + p++; ptlngth = strlen(p); - if ( (parts[fd] = malloc(ptlngth + 1)) == (char *) 0 ) + if ((parts[fd] = malloc(ptlngth + 1)) == (char *)0) logerror("Cannot allocate memory for message part."); - else - { + else { strcpy(parts[fd], p); logit("Saving partial msg: %s\n", parts[fd]); memset(p, '\0', ptlngth); @@ -1573,38 +1568,33 @@ void printchopped(hname, msg, len, fd) end = strchr(start + 1, '\0'); printline(hname, start); start = end + 1; - } while ( *start != '\0' ); + } while (*start != '\0'); return; } - - /* * Take a raw input line, decode the message, and print the message * on the appropriate log files. */ - -void printline(hname, msg) - const char *hname; - char *msg; +void printline(const char *hname, char *msg) { - register char *p, *q; - register unsigned char c; + unsigned char c; + unsigned int pri; /* Valid Priority values are 0-191 */ + char *p, *q; char line[MAXLINE + 1]; - unsigned int pri; // Valid Priority values are 0-191 - int prilen=0; // Track Priority value string len + int prilen = 0; /* Track Priority value string len */ int msglen; /* test for special codes */ - msglen=strlen(msg); + msglen = strlen(msg); pri = DEFUPRI; p = msg; if (*p == '<') { pri = 0; while (--msglen > 0 && isdigit((unsigned char)*++p) && - pri <= MAX_PRI) { + pri <= MAX_PRI) { pri = 10 * pri + (*p - '0'); prilen++; } @@ -1616,12 +1606,12 @@ void printline(hname, msg) } } - if ((pri &~ (LOG_FACMASK|LOG_PRIMASK)) || (pri > MAX_PRI)) { + if ((pri & ~(LOG_FACMASK | LOG_PRIMASK)) || (pri > MAX_PRI)) { pri = DEFUPRI; p = msg; } - memset (line, 0, sizeof(line)); + memset(line, 0, sizeof(line)); q = line; while ((c = *p++) && q < &line[sizeof(line) - 4]) { if (c == '\n' || c == 127) @@ -1638,24 +1628,18 @@ void printline(hname, msg) return; } - - /* * Take a raw input line from /dev/klog, split and format similar to syslog(). */ - -void printsys(msg) - char *msg; +void printsys(char *msg) { - register char *p, *q; - register int c; char line[MAXLINE + 1]; - int pri, flags; - char *lp; + char *lp, *p, *q; + int c, pri, flags; - (void) snprintf(line, sizeof(line), "vmunix: "); + (void)snprintf(line, sizeof(line), "vmunix: "); lp = line + strlen(line); - for (p = msg; *p != '\0'; ) { + for (p = msg; *p != '\0';) { flags = ADDDATE; pri = DEFSPRI; if (*p == '<') { @@ -1668,11 +1652,11 @@ void printsys(msg) /* kernel printf's come out on console */ flags |= IGN_CONS; } - if (pri &~ (LOG_FACMASK|LOG_PRIMASK)) + if (pri & ~(LOG_FACMASK | LOG_PRIMASK)) pri = DEFSPRI; q = lp; while (*p != '\0' && (c = *p++) != '\n' && - q < &line[MAXLINE]) + q < &line[MAXLINE]) *q++ = c; *q = '\0'; logmsg(pri, line, LocalHostName, flags); @@ -1683,37 +1667,30 @@ void printsys(msg) /* * Decode a priority into textual information like auth.emerg. */ -char *textpri(pri) - int pri; +char *textpri(int pri) { static char res[20]; CODE *c_pri, *c_fac; - for (c_fac = facilitynames; c_fac->c_name && !(c_fac->c_val == LOG_FAC(pri)<<3); c_fac++); - for (c_pri = prioritynames; c_pri->c_name && !(c_pri->c_val == LOG_PRI(pri)); c_pri++); + for (c_fac = facilitynames; c_fac->c_name && !(c_fac->c_val == LOG_FAC(pri) << 3); c_fac++) + ; + for (c_pri = prioritynames; c_pri->c_name && !(c_pri->c_val == LOG_PRI(pri)); c_pri++) + ; - snprintf (res, sizeof(res), "%s.%s<%d>", c_fac->c_name, c_pri->c_name, pri); + snprintf(res, sizeof(res), "%s.%s<%d>", c_fac->c_name, c_pri->c_name, pri); return res; } -time_t now; +time_t now; /* * Log a message to the appropriate log files, users, etc. based on * the priority. */ - -void logmsg(pri, msg, from, flags) - int pri; - char *msg; - const char *from; - int flags; +void logmsg(int pri, char *msg, const char *from, int flags) { - register struct filed *f; - int fac, prilev, lognum; - int msglen; - char *timestamp; + struct filed *f; #ifdef __gnu_linux__ sigset_t mask; #else @@ -1721,6 +1698,8 @@ void logmsg(pri, msg, from, flags) sigset_t omask; #endif #endif + char *timestamp; + int fac, prilev, lognum, msglen; logit("logmsg: %s, flags %x, from %s, msg %s\n", textpri(pri), flags, from, msg); @@ -1731,7 +1710,7 @@ void logmsg(pri, msg, from, flags) sigprocmask(SIG_BLOCK, &mask, NULL); #else #ifndef SYSV - omask = sigblock(sigmask(SIGHUP)|sigmask(SIGALRM)); + omask = sigblock(sigmask(SIGHUP) | sigmask(SIGALRM)); #endif #endif @@ -1748,12 +1727,12 @@ void logmsg(pri, msg, from, flags) */ msglen = strlen(msg); if (!(msglen < 16 || msg[3] != ' ' || msg[6] != ' ' || - msg[9] != ':' || msg[12] != ':' || msg[15] != ' ')) { + msg[9] != ':' || msg[12] != ':' || msg[15] != ' ')) { msg += 16; msglen -= 16; } - (void) time(&now); + (void)time(&now); timestamp = ctime(&now) + 4; /* extract facility and priority level */ @@ -1763,19 +1742,19 @@ void logmsg(pri, msg, from, flags) /* log the message to the particular outputs */ if (!Initialized) { f = &consfile; - f->f_file = open(ctty, O_WRONLY|O_NOCTTY); + f->f_file = open(ctty, O_WRONLY | O_NOCTTY); if (f->f_file >= 0) { untty(); fprintlog(f, (char *)from, flags, msg); - (void) close(f->f_file); + (void)close(f->f_file); f->f_file = -1; } #ifdef __gnu_linux__ sigprocmask(SIG_UNBLOCK, &mask, NULL); #else #ifndef SYSV - (void) sigsetmask(omask); + (void)sigsetmask(omask); #endif #endif return; @@ -1788,9 +1767,9 @@ void logmsg(pri, msg, from, flags) #endif /* skip messages that are incorrect priority */ - if ( (f->f_pmask[fac] == TABLE_NOPRI) || \ - ((f->f_pmask[fac] & (1<f_pmask[fac] == TABLE_NOPRI) || + ((f->f_pmask[fac] & (1 << prilev)) == 0)) + continue; if (f->f_type == F_CONSOLE && (flags & IGN_CONS)) continue; @@ -1805,11 +1784,11 @@ void logmsg(pri, msg, from, flags) if ((flags & MARK) == 0 && msglen == f->f_prevlen && !strcmp(msg, f->f_prevline) && !strcmp(from, f->f_prevhost)) { - (void) strncpy(f->f_lasttime, timestamp, 15); + (void)strncpy(f->f_lasttime, timestamp, 15); f->f_prevcount++; logit("msg repeated %d times, %ld sec of %d.\n", - f->f_prevcount, now - f->f_time, - repeatinterval[f->f_repeatcount]); + f->f_prevcount, now - f->f_time, + repeatinterval[f->f_repeatcount]); if (f->f_prevcount == 1 && DupesPending++ == 0) { int seconds; @@ -1821,7 +1800,7 @@ void logmsg(pri, msg, from, flags) if (LastAlarm > TIMERINTVL) LastAlarm = TIMERINTVL; alarm(LastAlarm); - } + } /* * If domark would have logged this by now, @@ -1848,12 +1827,12 @@ void logmsg(pri, msg, from, flags) } f->f_prevpri = pri; f->f_repeatcount = 0; - (void) strncpy(f->f_lasttime, timestamp, 15); - (void) strncpy(f->f_prevhost, from, - sizeof(f->f_prevhost)); + (void)strncpy(f->f_lasttime, timestamp, 15); + (void)strncpy(f->f_prevhost, from, + sizeof(f->f_prevhost)); if (msglen < MAXSVLINE) { f->f_prevlen = msglen; - (void) strcpy(f->f_prevline, msg); + (void)strcpy(f->f_prevline, msg); fprintlog(f, (char *)from, flags, (char *)NULL); } else { f->f_prevline[0] = 0; @@ -1866,7 +1845,7 @@ void logmsg(pri, msg, from, flags) sigprocmask(SIG_UNBLOCK, &mask, NULL); #else #ifndef SYSV - (void) sigsetmask(omask); + (void)sigsetmask(omask); #endif #endif } @@ -1874,55 +1853,50 @@ void logmsg(pri, msg, from, flags) } /* balance parentheses for emacs */ #endif -void logrotate(f) - register struct filed *f; +void logrotate(struct filed *f) { - struct stat statf; + struct stat statf; if (!RotateSz) return; - fstat(f->f_file, &statf); - /* bug (mostly harmless): can wrap around if file > 4gb */ - if (S_ISREG(statf.st_mode) && statf.st_size > RotateSz) { - if (RotateCnt) { /* always 0..99 */ - int i = strlen(f->f_un.f_fname) + 3 + 1; - char oldFile[i]; - char newFile[i]; + fstat(f->f_file, &statf); + /* bug (mostly harmless): can wrap around if file > 4gb */ + if (S_ISREG(statf.st_mode) && statf.st_size > RotateSz) { + if (RotateCnt) { /* always 0..99 */ + int i = strlen(f->f_un.f_fname) + 3 + 1; + char oldFile[i]; + char newFile[i]; - i = RotateCnt - 1; - /* rename: f.8 -> f.9; f.7 -> f.8; ... */ - while (1) { - sprintf(newFile, "%s.%d", f->f_un.f_fname, i); - if (i == 0) break; - sprintf(oldFile, "%s.%d", f->f_un.f_fname, --i); - /* ignore errors - file might be missing */ - rename(oldFile, newFile); - } - /* newFile == "f.0" now */ - rename(f->f_un.f_fname, newFile); - close(f->f_file); - f->f_file = open(f->f_un.f_fname, O_WRONLY|O_APPEND|O_CREAT|O_NONBLOCK|O_NOCTTY, 0644); - } - ftruncate(f->f_file, 0); - } + i = RotateCnt - 1; + /* rename: f.8 -> f.9; f.7 -> f.8; ... */ + while (1) { + sprintf(newFile, "%s.%d", f->f_un.f_fname, i); + if (i == 0) + break; + sprintf(oldFile, "%s.%d", f->f_un.f_fname, --i); + /* ignore errors - file might be missing */ + rename(oldFile, newFile); + } + /* newFile == "f.0" now */ + rename(f->f_un.f_fname, newFile); + close(f->f_file); + f->f_file = open(f->f_un.f_fname, O_WRONLY | O_APPEND | O_CREAT | O_NONBLOCK | O_NOCTTY, 0644); + } + ftruncate(f->f_file, 0); + } } -void fprintlog(f, from, flags, msg) - register struct filed *f; - char *from; - int flags; - char *msg; +void fprintlog(struct filed *f, char *from, int flags, char *msg) { struct iovec iov[6]; - register struct iovec *v = iov; + struct iovec *v = iov; char repbuf[80]; #ifdef SYSLOG_INET - register int l; - char line[MAXLINE + 1]; - time_t fwd_suspend; struct addrinfo hints, *ai; - int err; + time_t fwd_suspend; + char line[MAXLINE + 1]; + int l, err; #endif logit("Called fprintlog, "); @@ -1943,8 +1917,8 @@ void fprintlog(f, from, flags, msg) v->iov_base = msg; v->iov_len = strlen(msg); } else if (f->f_prevcount > 1) { - (void) snprintf(repbuf, sizeof(repbuf), "last message repeated %d times", - f->f_prevcount); + (void)snprintf(repbuf, sizeof(repbuf), "last message repeated %d times", + f->f_prevcount); v->iov_base = repbuf; v->iov_len = strlen(repbuf); } else { @@ -1963,21 +1937,21 @@ void fprintlog(f, from, flags, msg) #ifdef SYSLOG_INET case F_FORW_SUSP: - fwd_suspend = time((time_t *) 0) - f->f_time; - if ( fwd_suspend >= INET_SUSPEND_TIME ) { - logit("\nForwarding suspension over, " \ - "retrying FORW "); + fwd_suspend = time((time_t *)0) - f->f_time; + if (fwd_suspend >= INET_SUSPEND_TIME) { + logit("\nForwarding suspension over, " + "retrying FORW "); f->f_type = F_FORW; goto f_forw; - } - else { + } else { logit(" %s\n", f->f_un.f_forw.f_hname); - logit("Forwarding suspension not over, time " \ - "left: %d.\n", INET_SUSPEND_TIME - \ - fwd_suspend); + logit("Forwarding suspension not over, time " + "left: %d.\n", + INET_SUSPEND_TIME - + fwd_suspend); } break; - + /* * The trick is to wait some time, then retry to get the * address. If that fails retry x times and then give up. @@ -1988,8 +1962,8 @@ void fprintlog(f, from, flags, msg) */ case F_FORW_UNKN: logit(" %s\n", f->f_un.f_forw.f_hname); - fwd_suspend = time((time_t *) 0) - f->f_time; - if ( fwd_suspend >= INET_SUSPEND_TIME ) { + fwd_suspend = time((time_t *)0) - f->f_time; + if (fwd_suspend >= INET_SUSPEND_TIME) { logit("Forwarding suspension to unknown over, retrying\n"); memset(&hints, 0, sizeof(hints)); hints.ai_family = family; @@ -1997,24 +1971,22 @@ void fprintlog(f, from, flags, msg) if ((err = getaddrinfo(f->f_un.f_forw.f_hname, "syslog", &hints, &ai))) { logit("Failure: %s\n", gai_strerror(err)); logit("Retries: %d\n", f->f_prevcount); - if ( --f->f_prevcount < 0 ) { + if (--f->f_prevcount < 0) { logit("Giving up.\n"); f->f_type = F_UNUSED; - } - else + } else logit("Left retries: %d\n", f->f_prevcount); - } - else { - logit("%s found, resuming.\n", f->f_un.f_forw.f_hname); + } else { + logit("%s found, resuming.\n", f->f_un.f_forw.f_hname); f->f_un.f_forw.f_addr = ai; f->f_prevcount = 0; f->f_type = F_FORW; goto f_forw; } - } - else - logit("Forwarding suspension not over, time " \ - "left: %d\n", INET_SUSPEND_TIME - fwd_suspend); + } else + logit("Forwarding suspension not over, time " + "left: %d\n", + INET_SUSPEND_TIME - fwd_suspend); break; case F_FORW: @@ -2025,13 +1997,13 @@ void fprintlog(f, from, flags, msg) */ f_forw: logit(" %s\n", f->f_un.f_forw.f_hname); - if ( strcmp(from, LocalHostName) && NoHops ) + if (strcmp(from, LocalHostName) && NoHops) logit("Not sending message to remote.\n"); else if (finet) { int i; f->f_time = now; - (void) snprintf(line, sizeof(line), "<%d>%s", f->f_prevpri, \ - (char *) iov[4].iov_base); + (void)snprintf(line, sizeof(line), "<%d>%s", f->f_prevpri, + (char *)iov[4].iov_base); l = strlen(line); if (l > MAXLINE) l = MAXLINE; @@ -2039,8 +2011,8 @@ void fprintlog(f, from, flags, msg) for (ai = f->f_un.f_forw.f_addr; ai; ai = ai->ai_next) { for (i = 0; i < *finet; i++) { int lsent; - lsent = sendto(finet[i+1], line, l, 0, - ai->ai_addr, ai->ai_addrlen); + lsent = sendto(finet[i + 1], line, l, 0, + ai->ai_addr, ai->ai_addrlen); if (lsent == l) { err = -1; break; @@ -2051,8 +2023,8 @@ void fprintlog(f, from, flags, msg) break; } if (err != -1) { - logit("INET sendto error: %d = %s.\n", - err, strerror(err)); + logit("INET sendto error: %d = %s.\n", + err, strerror(err)); f->f_type = F_FORW_SUSP; errno = err; logerror("sendto"); @@ -2066,7 +2038,7 @@ void fprintlog(f, from, flags, msg) #ifdef UNIXPC if (1) { #else - if (flags & IGN_CONS) { + if (flags & IGN_CONS) { #endif logit(" (ignored).\n"); break; @@ -2114,18 +2086,18 @@ void fprintlog(f, from, flags, msg) if (f->f_type == F_CONSOLE && e == EAGAIN) break; - (void) close(f->f_file); + (void)close(f->f_file); /* * Check for EBADF on TTY's due to vhangup() XXX * Linux uses EIO instead (mrn 12 May 96) */ if ((f->f_type == F_TTY || f->f_type == F_CONSOLE) #ifdef linux - && e == EIO) { + && e == EIO) { #else - && e == EBADF) { + && e == EBADF) { #endif - f->f_file = open(f->f_un.f_fname, O_WRONLY|O_APPEND|O_NOCTTY); + f->f_file = open(f->f_un.f_fname, O_WRONLY | O_APPEND | O_NOCTTY); if (f->f_file < 0) { f->f_type = F_UNUSED; logerror(f->f_un.f_fname); @@ -2139,7 +2111,7 @@ void fprintlog(f, from, flags, msg) logerror(f->f_un.f_fname); } } else if (f->f_type == F_FILE && (f->f_flags & SYNC_FILE)) - (void) fsync(f->f_file); + (void)fsync(f->f_file); break; case F_USERS: @@ -2153,15 +2125,16 @@ void fprintlog(f, from, flags, msg) } /* switch */ if (f->f_type != F_FORW_UNKN) f->f_prevcount = 0; - return; + return; } #if FALSE -}} /* balance parentheses for emacs */ +} +} /* balance parentheses for emacs */ #endif jmp_buf ttybuf; -void endtty() +void endtty(int signo) { longjmp(ttybuf, 1); } @@ -2172,20 +2145,16 @@ void endtty() * Write the specified message to either the entire * world, or a list of approved users. */ - -void wallmsg(f, iov) - register struct filed *f; - struct iovec *iov; +void wallmsg(struct filed *f, struct iovec *iov) { - char p[sizeof (_PATH_DEV) + UNAMESZ]; - register int i; - int ttyf, len; static int reenter = 0; - struct utmp ut; struct utmp *uptr; + struct utmp ut; + char p[sizeof(_PATH_DEV) + UNAMESZ]; char greetings[200]; + int ttyf, len, i; - (void) &len; + (void)&len; if (reenter++) return; @@ -2193,21 +2162,20 @@ void wallmsg(f, iov) /* open the user login file */ setutent(); - /* * Might as well fork instead of using nonblocking I/O * and doing notty(). */ if (fork() == 0) { - (void) signal(SIGTERM, SIG_DFL); - (void) alarm(0); + (void)signal(SIGTERM, SIG_DFL); + (void)alarm(0); #ifndef SYSV - (void) signal(SIGTTOU, SIG_IGN); - (void) sigsetmask(0); + (void)signal(SIGTTOU, SIG_IGN); + (void)sigsetmask(0); #endif - (void) snprintf(greetings, sizeof(greetings), - "\r\n\7Message from syslogd@%s at %.24s ...\r\n", - (char *) iov[2].iov_base, ctime(&now)); + (void)snprintf(greetings, sizeof(greetings), + "\r\n\7Message from syslogd@%s at %.24s ...\r\n", + (char *)iov[2].iov_base, ctime(&now)); len = strlen(greetings); /* scan the user login file */ @@ -2217,9 +2185,9 @@ void wallmsg(f, iov) if (ut.ut_name[0] == '\0') continue; if (ut.ut_type != USER_PROCESS) - continue; - if (!(strcmp (ut.ut_name,"LOGIN"))) /* paranoia */ - continue; + continue; + if (!(strcmp(ut.ut_name, "LOGIN"))) /* paranoia */ + continue; /* should we send the message to this user? */ if (f->f_type == F_USERS) { @@ -2229,7 +2197,7 @@ void wallmsg(f, iov) break; } if (strncmp(f->f_un.f_uname[i], - ut.ut_name, UNAMESZ) == 0) + ut.ut_name, UNAMESZ) == 0) break; } if (i >= MAXUNAMES) @@ -2246,21 +2214,21 @@ void wallmsg(f, iov) iov[1].iov_len = 0; } if (setjmp(ttybuf) == 0) { - (void) signal(SIGALRM, endtty); - (void) alarm(15); + (void)signal(SIGALRM, endtty); + (void)alarm(15); /* open the terminal */ - ttyf = open(p, O_WRONLY|O_NOCTTY); + ttyf = open(p, O_WRONLY | O_NOCTTY); if (ttyf >= 0) { struct stat statb; if (fstat(ttyf, &statb) == 0 && (statb.st_mode & S_IWRITE)) - (void) writev(ttyf, iov, 6); + (void)writev(ttyf, iov, 6); close(ttyf); ttyf = -1; } } - (void) alarm(0); + (void)alarm(0); } exit(0); } @@ -2269,30 +2237,30 @@ void wallmsg(f, iov) reenter = 0; } -void reapchild() +void reapchild(int signo) { int saved_errno = errno; #if defined(SYSV) && !defined(linux) - (void) signal(SIGCHLD, reapchild); /* reset signal handler -ASP */ - wait ((int *)0); + (void)signal(SIGCHLD, reapchild); /* reset signal handler -ASP */ + wait((int *)0); #else int status; - while (wait3(&status, WNOHANG, (struct rusage *) NULL) > 0) + while (wait3(&status, WNOHANG, (struct rusage *)NULL) > 0) ; #endif #ifdef linux - (void) signal(SIGCHLD, reapchild); /* reset signal handler -ASP */ + (void)signal(SIGCHLD, reapchild); /* reset signal handler -ASP */ #endif errno = saved_errno; } -const char *cvtaddr (struct sockaddr_storage *f, int len) +const char *cvtaddr(struct sockaddr_storage *f, int len) { static char ip[NI_MAXHOST]; - if (getnameinfo((struct sockaddr *) f, len, - ip, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)) + if (getnameinfo((struct sockaddr *)f, len, + ip, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)) return "???"; return ip; } @@ -2309,15 +2277,14 @@ const char *cvtaddr (struct sockaddr_storage *f, int len) const char *cvthname(struct sockaddr_storage *f, int len) { static char hname[NI_MAXHOST]; - int error; - register char *p; - int count; + char *p; + int error, count; - if ((error = getnameinfo((struct sockaddr *) f, len, - hname, NI_MAXHOST, NULL, 0, NI_NAMEREQD))) { + if ((error = getnameinfo((struct sockaddr *)f, len, + hname, NI_MAXHOST, NULL, 0, NI_NAMEREQD))) { logit("Host name for your address (%s) unknown: %s\n", gai_strerror(error)); - if ((error = getnameinfo((struct sockaddr *) f, len, - hname, NI_MAXHOST, NULL, 0, NI_NUMERICHOST))) { + if ((error = getnameinfo((struct sockaddr *)f, len, + hname, NI_MAXHOST, NULL, 0, NI_NUMERICHOST))) { logit("Malformed from address: %s\n", gai_strerror(error)); return "???"; } @@ -2326,9 +2293,10 @@ const char *cvthname(struct sockaddr_storage *f, int len) /* * Convert to lower case, just like LocalDomain above */ - for (p = hname; *p ; p++) + for (p = hname; *p; p++) { if (isupper(*p)) *p = tolower(*p); + } /* * Notice that the string still contains the fqdn, but your @@ -2340,7 +2308,7 @@ const char *cvthname(struct sockaddr_storage *f, int len) return (hname); } else { if (StripDomains) { - count=0; + count = 0; while (StripDomains[count]) { if (strcmp(p + 1, StripDomains[count]) == 0) { *p = '\0'; @@ -2350,7 +2318,7 @@ const char *cvthname(struct sockaddr_storage *f, int len) } } if (LocalHosts) { - count=0; + count = 0; while (LocalHosts[count]) { if (!strcmp(hname, LocalHosts[count])) { *p = '\0'; @@ -2365,9 +2333,9 @@ const char *cvthname(struct sockaddr_storage *f, int len) return (hname); } -void domark() +void domark(int signo) { - register struct filed *f; + struct filed *f; #ifdef SYSV int lognum; #endif @@ -2376,7 +2344,7 @@ void domark() now = time(0); MarkSeq += LastAlarm; if (MarkSeq >= MarkInterval) { - logmsg(LOG_MARK|LOG_INFO, "-- MARK --", LocalHostName, ADDDATE|MARK); + logmsg(LOG_MARK | LOG_INFO, "-- MARK --", LocalHostName, ADDDATE | MARK); MarkSeq -= MarkInterval; } } @@ -2389,31 +2357,29 @@ void domark() #endif if (f->f_prevcount && now >= REPEATTIME(f)) { logit("flush %s: repeated %d times, %d sec.\n", - TypeNames[f->f_type], f->f_prevcount, - repeatinterval[f->f_repeatcount]); + TypeNames[f->f_type], f->f_prevcount, + repeatinterval[f->f_repeatcount]); fprintlog(f, LocalHostName, 0, (char *)NULL); BACKOFF(f); DupesPending--; } } - (void) signal(SIGALRM, domark); + (void)signal(SIGALRM, domark); LastAlarm = MarkInterval - MarkSeq; if (DupesPending && LastAlarm > TIMERINTVL) LastAlarm = TIMERINTVL; - (void) alarm(LastAlarm); + (void)alarm(LastAlarm); } -void debug_switch() - +void debug_switch(int signo) { logit("Switching debugging_on to %s\n", (debugging_on == 0) ? "true" : "false"); debugging_on = (debugging_on == 0) ? 1 : 0; signal(SIGUSR1, debug_switch); } - /* * Print syslogd errors some place. */ @@ -2424,26 +2390,23 @@ void logerror(const char *type) logit("Called logerr, msg: %s\n", type); if (errno == 0) - (void) snprintf(buf, sizeof(buf), "syslogd: %s", type); + (void)snprintf(buf, sizeof(buf), "syslogd: %s", type); else - (void) snprintf(buf, sizeof(buf), "syslogd: %s: %s", type, strerror(errno)); + (void)snprintf(buf, sizeof(buf), "syslogd: %s: %s", type, strerror(errno)); errno = 0; - logmsg(LOG_SYSLOG|LOG_ERR, buf, LocalHostName, ADDDATE); + logmsg(LOG_SYSLOG | LOG_ERR, buf, LocalHostName, ADDDATE); return; } -void die(sig) - - int sig; - +void die(int signo) { - register struct filed *f; + struct filed *f; char buf[100]; int lognum; int i; int was_initialized = Initialized; - Initialized = 0; /* Don't log SIGCHLDs in case we + Initialized = 0; /* Don't log SIGCHLDs in case we receive one during exiting */ for (lognum = 0; lognum <= nlogs; lognum++) { @@ -2454,30 +2417,30 @@ void die(sig) } Initialized = was_initialized; - if (sig) { - logit("syslogd: exiting on signal %d\n", sig); - (void) snprintf(buf, sizeof(buf), "exiting on signal %d", sig); + if (signo) { + logit("syslogd: exiting on signal %d\n", signo); + (void)snprintf(buf, sizeof(buf), "exiting on signal %d", signo); errno = 0; - logmsg(LOG_SYSLOG|LOG_INFO, buf, LocalHostName, ADDDATE); + logmsg(LOG_SYSLOG | LOG_INFO, buf, LocalHostName, ADDDATE); } /* Close the UNIX sockets. */ - for (i = 0; i < nfunix; i++) + for (i = 0; i < nfunix; i++) if (funix[i] != -1) close(funix[i]); /* Close the inet sockets. */ if (InetInuse && finet) { for (i = 0; i < *finet; i++) - close(finet[i+1]); + close(finet[i + 1]); free(finet); } /* Clean-up files. */ - for (i = 0; i < nfunix; i++) + for (i = 0; i < nfunix; i++) if (funixn[i] && funix[i] != -1) (void)unlink(funixn[i]); #ifndef TESTING - (void) remove_pid(PidFile); + (void)remove_pid(PidFile); #endif exit(0); } @@ -2486,47 +2449,44 @@ void die(sig) * Signal handler to terminate the parent process. */ #ifndef TESTING -void doexit(sig) - int sig; +void doexit(int signo) { - exit (0); + exit(0); } #endif /* * INIT -- Initialize syslogd from configuration table */ - -void init() +void init(void) { - register int i, lognum; - register FILE *cf; - register struct filed *f; #ifndef TESTING #ifndef SYSV - register struct filed **nextp = (struct filed **) 0; + struct filed **nextp = (struct filed **)0; #endif #endif - register char *p; - register unsigned int Forwarding = 0; + struct hostent *hent; + struct filed *f; + unsigned int Forwarding = 0; + FILE *cf; #ifdef CONT_LINE - char cbuf[BUFSIZ]; + char cbuf[BUFSIZ]; char *cline; #else char cline[BUFSIZ]; #endif - struct hostent *hent; + char *p; + int i, lognum; /* * Close all open log files and free log descriptor array. */ logit("Called init.\n"); Initialized = 0; - if ( nlogs > -1 ) - { + if (nlogs > -1) { logit("Initializing log structures.\n"); - for (lognum = 0; lognum <= nlogs; lognum++ ) { + for (lognum = 0; lognum <= nlogs; lognum++) { f = &Files[lognum]; /* flush any pending output */ @@ -2538,7 +2498,7 @@ void init() case F_PIPE: case F_TTY: case F_CONSOLE: - (void) close(f->f_file); + (void)close(f->f_file); break; case F_FORW: case F_FORW_SUSP: @@ -2552,10 +2512,9 @@ void init() * structure would grow infinitively. -Joey */ nlogs = -1; - free((void *) Files); - Files = (struct filed *) 0; + free((void *)Files); + Files = (struct filed *)0; } - #ifdef SYSV lognum = 0; @@ -2563,15 +2522,13 @@ void init() f = NULL; #endif - /* Get hostname */ - (void) gethostname(LocalHostName, sizeof(LocalHostName)); + /* Get hostname */ + (void)gethostname(LocalHostName, sizeof(LocalHostName)); LocalDomain = emptystring; - if ( (p = strchr(LocalHostName, '.')) ) { + if ((p = strchr(LocalHostName, '.'))) { *p++ = '\0'; LocalDomain = p; - } - else if ( AcceptRemote ) - { + } else if (AcceptRemote) { /* * It's not clearly defined whether gethostname() * should return the simple hostname or the fqdn. A @@ -2584,11 +2541,10 @@ void init() * return NULL. */ hent = gethostbyname(LocalHostName); - if ( hent ) + if (hent) snprintf(LocalHostName, sizeof(LocalHostName), "%s", hent->h_name); - - if ( (p = strchr(LocalHostName, '.')) ) - { + + if ((p = strchr(LocalHostName, '.'))) { *p++ = '\0'; LocalDomain = p; } @@ -2597,7 +2553,7 @@ void init() /* * Convert to lower case to recognize the correct domain laterly */ - for (p = (char *)LocalDomain; *p ; p++) + for (p = (char *)LocalDomain; *p; p++) if (isupper(*p)) *p = tolower(*p); @@ -2610,14 +2566,14 @@ void init() #ifndef TESTING cfline("*.err\t" _PATH_CONSOLE, f); #else - snprintf(cbuf,sizeof(cbuf), "*.*\t%s", ttyname(0)); + snprintf(cbuf, sizeof(cbuf), "*.*\t%s", ttyname(0)); cfline(cbuf, f); #endif #else - *nextp = (struct filed *)calloc(1, sizeof(*f)); + *nextp = calloc(1, sizeof(*f)); cfline("*.ERR\t" _PATH_CONSOLE, *nextp); - (*nextp)->f_next = (struct filed *)calloc(1, sizeof(*f)) /* ASP */ - cfline("*.PANIC\t*", (*nextp)->f_next); + (*nextp)->f_next = calloc(1, sizeof(*f)) /* ASP */ + cfline("*.PANIC\t*", (*nextp)->f_next); #endif Initialized = 1; return; @@ -2636,13 +2592,15 @@ void init() * check for end-of-section, comments, strip off trailing * spaces and newline character. */ - for (p = cline; isspace(*p); ++p); + for (p = cline; isspace(*p); ++p) + ; if (*p == '\0' || *p == '#') continue; #if CONT_LINE - memmove(cline, p, strlen(p)+1); + memmove(cline, p, strlen(p) + 1); #endif - for (p = strchr(cline, '\0'); isspace(*--p);); + for (p = strchr(cline, '\0'); isspace(*--p);) + ; #if CONT_LINE if (*p == '\\') { if ((p - cbuf) > BUFSIZ - 30) { @@ -2653,7 +2611,7 @@ void init() cline = p; continue; } - } else + } else cline = cbuf; #endif *++p = '\0'; @@ -2675,7 +2633,7 @@ void init() } /* close the configuration file */ - (void) fclose(cf); + (void)fclose(cf); #ifdef SYSLOG_UNIXAF for (i = 0; i < nfunix; i++) { @@ -2698,12 +2656,11 @@ void init() logit("Opened syslog UDP port.\n"); } } - } - else { + } else { if (finet) { for (i = 0; i < *finet; i++) - if (finet[i+1] != -1) - close(finet[i+1]); + if (finet[i + 1] != -1) + close(finet[i + 1]); free(finet); finet = NULL; } @@ -2713,12 +2670,12 @@ void init() Initialized = 1; - if ( Debug ) { + if (Debug) { #ifdef SYSV for (lognum = 0; lognum <= nlogs; lognum++) { f = &Files[lognum]; if (f->f_type != F_UNUSED) { - printf ("%2d: ", lognum); + printf("%2d: ", lognum); #else for (f = Files; f; f = f->f_next) { if (f->f_type != F_UNUSED) { @@ -2755,50 +2712,43 @@ void init() } } - if ( AcceptRemote ) - logmsg(LOG_SYSLOG|LOG_INFO, "syslogd v" VERSION - ": restart (remote reception)." , LocalHostName, - ADDDATE); + if (AcceptRemote) + logmsg(LOG_SYSLOG | LOG_INFO, "syslogd v" VERSION ": restart (remote reception).", LocalHostName, + ADDDATE); else - logmsg(LOG_SYSLOG|LOG_INFO, "syslogd v" VERSION - ": restart." , LocalHostName, ADDDATE); + logmsg(LOG_SYSLOG | LOG_INFO, "syslogd v" VERSION ": restart.", LocalHostName, ADDDATE); - (void) signal(SIGHUP, sighup_handler); + (void)signal(SIGHUP, sighup_handler); logit("syslogd: restarted.\n"); } #if FALSE -}}} /* balance parentheses for emacs */ +} +} +} /* balance parentheses for emacs */ #endif /* * Crack a configuration file line */ - -void cfline(line, f) - char *line; - register struct filed *f; +void cfline(char *line, struct filed *f) { - register char *p; - register char *q; - register int i, i2; - char *bp; - int pri; - int singlpri = 0; - int ignorepri = 0; - int syncfile; #ifdef SYSLOG_INET struct addrinfo hints, *ai; #endif char buf[MAXLINE]; char xbuf[200]; + char *p, *q, *bp; + int ignorepri = 0; + int singlpri = 0; + int syncfile, pri, i, i2; logit("cfline(%s)\n", line); - errno = 0; /* keep strerror() stuff out of logerror messages */ + errno = 0; /* keep strerror() stuff out of logerror messages */ /* clear out file entry */ #ifndef SYSV - memset((char *) f, 0, sizeof(*f)); + memset((char *)f, 0, sizeof(*f)); #endif for (i = 0; i <= LOG_NFACILITIES; i++) { f->f_pmask[i] = TABLE_NOPRI; @@ -2809,11 +2759,11 @@ void cfline(line, f) for (p = line; *p && *p != '\t' && *p != ' ';) { /* find the end of this facility name list */ - for (q = p; *q && *q != '\t' && *q++ != '.'; ) + for (q = p; *q && *q != '\t' && *q++ != '.';) continue; /* collect priority name */ - for (bp = buf; *q && !strchr("\t ,;", *q); ) + for (bp = buf; *q && !strchr("\t ,;", *q);) *bp++ = *q++; *bp = '\0'; @@ -2822,66 +2772,58 @@ void cfline(line, f) q++; /* decode priority name */ - if ( *buf == '!' ) { + if (*buf == '!') { ignorepri = 1; - for (bp=buf; *(bp+1); bp++) - *bp=*(bp+1); - *bp='\0'; - } - else { + for (bp = buf; *(bp + 1); bp++) + *bp = *(bp + 1); + *bp = '\0'; + } else { ignorepri = 0; } - if ( *buf == '=' ) - { + if (*buf == '=') { singlpri = 1; pri = decode(&buf[1], PriNames); - } - else { - singlpri = 0; + } else { + singlpri = 0; pri = decode(buf, PriNames); } if (pri < 0) { - (void) snprintf(xbuf, sizeof(xbuf), "unknown priority name \"%s\"", buf); + (void)snprintf(xbuf, sizeof(xbuf), "unknown priority name \"%s\"", buf); logerror(xbuf); return; } /* scan facilities */ while (*p && !strchr("\t .;", *p)) { - for (bp = buf; *p && !strchr("\t ,;.", *p); ) + for (bp = buf; *p && !strchr("\t ,;.", *p);) *bp++ = *p++; *bp = '\0'; if (*buf == '*') { for (i = 0; i <= LOG_NFACILITIES; i++) { - if ( pri == INTERNAL_NOPRI ) { - if ( ignorepri ) + if (pri == INTERNAL_NOPRI) { + if (ignorepri) f->f_pmask[i] = TABLE_ALLPRI; else f->f_pmask[i] = TABLE_NOPRI; - } - else if ( singlpri ) { - if ( ignorepri ) - f->f_pmask[i] &= ~(1<f_pmask[i] &= ~(1 << pri); else - f->f_pmask[i] |= (1<f_pmask[i] |= (1 << pri); + } else { + if (pri == TABLE_ALLPRI) { + if (ignorepri) f->f_pmask[i] = TABLE_NOPRI; else f->f_pmask[i] = TABLE_ALLPRI; - } - else - { - if ( ignorepri ) - for (i2= 0; i2 <= pri; ++i2) - f->f_pmask[i] &= ~(1<f_pmask[i] &= ~(1 << i2); else - for (i2= 0; i2 <= pri; ++i2) - f->f_pmask[i] |= (1<f_pmask[i] |= (1 << i2); } } } @@ -2889,34 +2831,34 @@ void cfline(line, f) i = decode(buf, FacNames); if (i < 0) { - (void) snprintf(xbuf, sizeof(xbuf), "unknown facility name \"%s\"", buf); + (void)snprintf(xbuf, sizeof(xbuf), "unknown facility name \"%s\"", buf); logerror(xbuf); return; } - if ( pri == INTERNAL_NOPRI ) { - if ( ignorepri ) + if (pri == INTERNAL_NOPRI) { + if (ignorepri) f->f_pmask[i >> 3] = TABLE_ALLPRI; else f->f_pmask[i >> 3] = TABLE_NOPRI; - } else if ( singlpri ) { - if ( ignorepri ) - f->f_pmask[i >> 3] &= ~(1<f_pmask[i >> 3] &= ~(1 << pri); else - f->f_pmask[i >> 3] |= (1<f_pmask[i >> 3] |= (1 << pri); } else { - if ( pri == TABLE_ALLPRI ) { - if ( ignorepri ) + if (pri == TABLE_ALLPRI) { + if (ignorepri) f->f_pmask[i >> 3] = TABLE_NOPRI; else f->f_pmask[i >> 3] = TABLE_ALLPRI; } else { - if ( ignorepri ) - for (i2= 0; i2 <= pri; ++i2) - f->f_pmask[i >> 3] &= ~(1<f_pmask[i >> 3] &= ~(1 << i2); else - for (i2= 0; i2 <= pri; ++i2) - f->f_pmask[i >> 3] |= (1<f_pmask[i >> 3] |= (1 << i2); } } } @@ -2931,20 +2873,18 @@ void cfline(line, f) while (*p == '\t' || *p == ' ') p++; - if (*p == '-') - { + if (*p == '-') { syncfile = 0; p++; } else syncfile = 1; logit("leading char in action: %c\n", *p); - switch (*p) - { + switch (*p) { case '@': #ifdef SYSLOG_INET - (void) strcpy(f->f_un.f_forw.f_hname, ++p); - logit("forwarding host: %s\n", p); /*ASP*/ + (void)strcpy(f->f_un.f_forw.f_hname, ++p); + logit("forwarding host: %s\n", p); /*ASP*/ memset(&hints, 0, sizeof(hints)); hints.ai_family = family; hints.ai_socktype = SOCK_DGRAM; @@ -2957,7 +2897,7 @@ void cfline(line, f) */ f->f_type = F_FORW_UNKN; f->f_prevcount = INET_RETRY_MAX; - f->f_time = time ( (time_t *)0 ); + f->f_time = time((time_t *)0); f->f_un.f_forw.f_addr = NULL; } else { f->f_type = F_FORW; @@ -2966,22 +2906,22 @@ void cfline(line, f) #endif break; - case '|': + case '|': case '/': - (void) strcpy(f->f_un.f_fname, p); - logit("filename: %s\n", p); /*ASP*/ + (void)strcpy(f->f_un.f_fname, p); + logit("filename: %s\n", p); /*ASP*/ if (syncfile) f->f_flags |= SYNC_FILE; - if ( *p == '|' ) { - f->f_file = open(++p, O_RDWR|O_NONBLOCK|O_NOCTTY); + if (*p == '|') { + f->f_file = open(++p, O_RDWR | O_NONBLOCK | O_NOCTTY); f->f_type = F_PIPE; } else { - f->f_file = open(p, O_WRONLY|O_APPEND|O_CREAT|O_NONBLOCK|O_NOCTTY, - 0644); + f->f_file = open(p, O_WRONLY | O_APPEND | O_CREAT | O_NONBLOCK | O_NOCTTY, + 0644); f->f_type = F_FILE; } - - if ( f->f_file < 0 ){ + + if (f->f_file < 0) { f->f_file = -1; logit("Error opening log file: %s\n", p); logerror(p); @@ -3001,11 +2941,11 @@ void cfline(line, f) break; default: - logit("users: %s\n", p); /* ASP */ + logit("users: %s\n", p); /* ASP */ for (i = 0; i < MAXUNAMES && *p; i++) { - for (q = p; *q && *q != ','; ) + for (q = p; *q && *q != ',';) q++; - (void) strncpy(f->f_un.f_uname[i], p, UNAMESZ); + (void)strncpy(f->f_un.f_uname[i], p, UNAMESZ); if ((q - p) > UNAMESZ) f->f_un.f_uname[i][UNAMESZ] = '\0'; else @@ -3017,35 +2957,28 @@ void cfline(line, f) f->f_type = F_USERS; break; } - return; } - /* * Decode a symbolic name to a numeric value */ - -int decode(name, codetab) - char *name; - struct code *codetab; +int decode(char *name, struct code *codetab) { - register struct code *c; - register char *p; - char buf[80]; + struct code *c; + char * p; + char buf[80]; logit("symbolic name: %s", name); - if (isdigit(*name)) - { + if (isdigit(*name)) { logit("\n"); return (atoi(name)); } - (void) strncpy(buf, name, 79); + (void)strncpy(buf, name, 79); for (p = buf; *p; p++) if (isupper(*p)) *p = tolower(*p); for (c = codetab; c->c_name; c++) - if (!strcmp(buf, c->c_name)) - { + if (!strcmp(buf, c->c_name)) { logit(" ==> %d\n", c->c_val); return (c->c_val); } @@ -3053,86 +2986,71 @@ int decode(name, codetab) } static void logit(char *fmt, ...) - { va_list ap; - if ( !(Debug && debugging_on) ) + if (!(Debug && debugging_on)) return; - + va_start(ap, fmt); vfprintf(stdout, fmt, ap); va_end(ap); fflush(stdout); - return; } - /* * The following function is responsible for allocating/reallocating the * array which holds the structures which define the logging outputs. */ -static void allocate_log() - +static void allocate_log(void) { logit("Called allocate_log, nlogs = %d.\n", nlogs); - + /* * Decide whether the array needs to be initialized or needs to * grow. */ - if ( nlogs == -1 ) - { - Files = (struct filed *) malloc(sizeof(struct filed)); - if ( Files == (void *) 0 ) - { + if (nlogs == -1) { + Files = malloc(sizeof(struct filed)); + if (Files == NULL) { logit("Cannot initialize log structure."); logerror("Cannot initialize log structure."); return; } - } - else - { + } else { /* Re-allocate the array. */ - Files = (struct filed *) realloc(Files, (nlogs+2) * \ - sizeof(struct filed)); - if ( Files == (struct filed *) 0 ) - { + Files = realloc(Files, (nlogs + 2) * sizeof(struct filed)); + if (Files == NULL) { logit("Cannot grow log structure."); logerror("Cannot grow log structure."); return; } } - + /* * Initialize the array element, bump the number of elements in the * the array and return. */ ++nlogs; memset(&Files[nlogs], '\0', sizeof(struct filed)); - return; } - /* * The following function is resposible for handling a SIGHUP signal. Since * we are now doing mallocs/free as part of init we had better not being * doing this during a signal handler. Instead this function simply sets * a flag variable which will tell the main loop to go through a restart. */ -void sighup_handler() - +void sighup_handler(int signo) { restart = 1; signal(SIGHUP, sighup_handler); - return; } /** - * Local variables: - * c-indent-level: 8 - * c-basic-offset: 8 - * tab-width: 8 + * Local Variables: + * indent-tabs-mode: t + * c-file-style: "linux" * End: */