diff options
author | Rainer Gerhards <rgerhards@adiscon> | 2008-04-09 09:06:40 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon> | 2008-04-09 09:06:40 +0200 |
commit | 0b447f310ac057ba59f0238f5bd663c993a823c2 (patch) | |
tree | c1497d72a2f36dfbbabeaa4385de002b18232561 | |
parent | b0a4df43e4434a1eeb3f23c2c5a4b0cdd2fbddda (diff) | |
download | rsyslog-0b447f310ac057ba59f0238f5bd663c993a823c2.tar.gz rsyslog-0b447f310ac057ba59f0238f5bd663c993a823c2.tar.xz rsyslog-0b447f310ac057ba59f0238f5bd663c993a823c2.zip |
implemented klog driver for BSD
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | plugins/imklog/bsd.c | 107 | ||||
-rw-r--r-- | plugins/imklog/imklog.c | 7 | ||||
-rw-r--r-- | plugins/imklog/imklog.h | 2 | ||||
-rw-r--r-- | plugins/imklog/linux.c | 3 |
6 files changed, 70 insertions, 52 deletions
@@ -1,5 +1,6 @@ --------------------------------------------------------------------------- Version 3.17.1 (rgerhards), 2008-04-?? +- implemented klogd functionality for BSD --------------------------------------------------------------------------- Version 3.17.0 (rgerhards), 2008-04-08 - added native ability to send mail messages diff --git a/configure.ac b/configure.ac index 68158c46..5290edb4 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.61) -AC_INIT([rsyslog],[3.17.1],[rsyslog@lists.adiscon.com]) +AC_INIT([rsyslog],[3.17.1-bsd],[rsyslog@lists.adiscon.com]) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([syslogd.c]) AC_CONFIG_HEADERS([config.h]) diff --git a/plugins/imklog/bsd.c b/plugins/imklog/bsd.c index 25391980..c1595669 100644 --- a/plugins/imklog/bsd.c +++ b/plugins/imklog/bsd.c @@ -64,21 +64,47 @@ * the GPLv3+ as specified above. */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> -/* open the kernel log -- rger */ -static void openKLog(void) +#include "rsyslog.h" +#include "imklog.h" + +/* globals */ +static int fklog = -1; /* /dev/klog */ + +#ifndef _PATH_KLOG +# define _PATH_KLOG "/dev/klog" +#endif + +/* open the kernel log - will be called inside the willRun() imklog + * entry point. -- rgerhards, 20080-04-09 + */ +rsRetVal +klogWillRun(void) { - if ((fklog = open(_PATH_KLOG, O_RDONLY, 0)) >= 0) - if (fcntl(fklog, F_SETFL, O_NONBLOCK) < 0) - fklog = -1; - if (fklog < 0) - dprintf("can't open %s (%d)\n", _PATH_KLOG, errno); + DEFiRet; + + fklog = open(_PATH_KLOG, O_RDONLY, 0); + if (fklog < 0) { + dbgprintf("can't open %s (%d)\n", _PATH_KLOG, errno); + iRet = RS_RET_ERR; // TODO: better error code + } + + RETiRet; } -static int fklog = -1; /* /dev/klog */ -/* - * Read /dev/klog while data are available, split into lines. +/* Read /dev/klog while data are available, split into lines. + * Contrary to standard BSD syslogd, we do a blocking read. We can + * afford this as imklog is running on its own threads. So if we have + * a single file, it really doesn't matter if we wait inside a 1-file + * select or the read() directly. */ static void readklog(void) @@ -88,12 +114,15 @@ readklog(void) len = 0; for (;;) { + dbgprintf("----------imklog waiting for kernel log line\n"); i = read(fklog, line + len, MAXLINE - 1 - len); if (i > 0) { line[i + len] = '\0'; } else { if (i < 0 && errno != EINTR && errno != EAGAIN) { - logerror("klog"); + Syslog(LOG_ERR, + "imklog error %d reading kernel log - shutting down imklog", + errno); fklog = -1; } break; @@ -101,51 +130,41 @@ readklog(void) for (p = line; (q = strchr(p, '\n')) != NULL; p = q + 1) { *q = '\0'; - printsys(p); + Syslog(LOG_INFO, "%s", p); } len = strlen(p); if (len >= MAXLINE - 1) { - printsys(p); + Syslog(LOG_INFO, "%s", p); len = 0; } if (len > 0) memmove(line, p, len + 1); } if (len > 0) - printsys(line); + Syslog(LOG_INFO, "%s", line); } -/* - * Take a raw input line from /dev/klog, format similar to syslog(). + +/* to be called in the module's AfterRun entry point + * rgerhards, 2008-04-09 */ -static void -printsys(char *msg) +rsRetVal klogAfterRun(void) { - char *p, *q; - long n; - int flags, isprintf, pri; - - flags = ISKERNEL | SYNC_FILE | ADDDATE; /* fsync after write */ - p = msg; - pri = DEFSPRI; - isprintf = 1; - if (*p == '<') { - errno = 0; - n = strtol(p + 1, &q, 10); - if (*q == '>' && n >= 0 && n < INT_MAX && errno == 0) { - p = q + 1; - pri = n; - isprintf = 0; - } - } - /* - * Kernel printf's and LOG_CONSOLE messages have been displayed - * on the console already. - */ - if (isprintf || (pri & LOG_FACMASK) == LOG_CONSOLE) - flags |= IGN_CONS; - if (pri &~ (LOG_FACMASK|LOG_PRIMASK)) - pri = DEFSPRI; - logmsg(pri, p, LocalHostName, flags); + DEFiRet; + if(fklog != -1) + close(fklog); + RETiRet; } + + +/* to be called in the module's WillRun entry point, this is the main + * "message pull" mechanism. + * rgerhards, 2008-04-09 + */ +rsRetVal klogLogKMsg(void) +{ + DEFiRet; + readklog(); + RETiRet; +} diff --git a/plugins/imklog/imklog.c b/plugins/imklog/imklog.c index 972e93db..7f5c3cec 100644 --- a/plugins/imklog/imklog.c +++ b/plugins/imklog/imklog.c @@ -142,13 +142,12 @@ rsRetVal Syslog(int priority, char *fmt, ...) va_list ap; char *argl; - /* Output using syslog. */ + /* Output using syslog */ 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; diff --git a/plugins/imklog/imklog.h b/plugins/imklog/imklog.h index 0ac25d6c..2fea879f 100644 --- a/plugins/imklog/imklog.h +++ b/plugins/imklog/imklog.h @@ -59,7 +59,7 @@ extern int InitMsyms(void); extern void DeinitMsyms(void); extern char * ExpandKadds(char *, char *); extern void SetParanoiaLevel(int); -extern void vsyslog(int pri, const char *fmt, va_list ap); +//TODO: remove? extern void vsyslog(int pri, const char *fmt, va_list ap); rsRetVal Syslog(int priority, char *fmt, ...) __attribute__((format(printf,2, 3))); #endif /* #ifndef IMKLOG_H_INCLUDED */ diff --git a/plugins/imklog/linux.c b/plugins/imklog/linux.c index ce2ef4eb..dc669b15 100644 --- a/plugins/imklog/linux.c +++ b/plugins/imklog/linux.c @@ -154,8 +154,7 @@ static enum LOGSRC GetKernelLogSrc(void) return(none); } - Syslog(LOG_INFO, "imklog %s, log source = %s started.", \ - VERSION, _PATH_KLOG); + Syslog(LOG_INFO, "imklog %s, log source = %s started.", VERSION, _PATH_KLOG); return(proc); } |