diff options
author | thomas <thomas@FreeBSD.org> | 2002-11-07 19:53:29 +0000 |
---|---|---|
committer | thomas <thomas@FreeBSD.org> | 2002-11-07 19:53:29 +0000 |
commit | 3a6aeba622d2d593f7592b562dfdc89bfaa9683b (patch) | |
tree | ae1b9b5ee5e24ea36146179e45d7d8d13e2f6b6a /usr.sbin | |
parent | 6e5122867aef193848b1c3d1f9a664a3051781f8 (diff) | |
download | FreeBSD-src-3a6aeba622d2d593f7592b562dfdc89bfaa9683b.zip FreeBSD-src-3a6aeba622d2d593f7592b562dfdc89bfaa9683b.tar.gz |
Factor out the code that determines whether a message must be skipped
as a consequence of a host or program name specification into a common
function, skip_pmessage.
Reviewed by: roberto
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/syslogd/syslogd.c | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index 26629a4..f8fb385 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -306,6 +306,7 @@ static void logerror(const char *); static void logmsg(int, const char *, const char *, int); static void log_deadchild(pid_t, int, const char *); static void markit(void); +static int skip_message(const char *, const char *); static void printline(const char *, char *); static void printsys(char *); static int p_open(const char *, pid_t *); @@ -757,6 +758,26 @@ printsys(char *p) static time_t now; /* + * Match a program or host name against a specification. + * Return a non-0 value if the message must be ignored + * based on the specification. + */ +static int +skip_message(const char *name, const char *spec) { + if (spec == NULL) + return 0; + + switch (spec[0]) { + case '+': + return (strcmp(name, spec + 1) != 0); + case '-': + return (strcmp(name, spec + 1) == 0); + default: + return (strcmp(name, spec) != 0); + } +} + +/* * Log a message to the appropriate log files, users, etc. based on * the priority. */ @@ -840,36 +861,16 @@ logmsg(int pri, const char *msg, const char *from, int flags) ) || f->f_pmask[fac] == INTERNAL_NOPRI) continue; + /* skip messages with the incorrect hostname */ - if (f->f_host) - switch (f->f_host[0]) { - case '+': - if (strcmp(from, f->f_host + 1) != 0) - continue; - break; - case '-': - if (strcmp(from, f->f_host + 1) == 0) - continue; - break; - } + if (skip_message(from, f->f_host)) + continue; /* skip messages with the incorrect program name */ - if (f->f_program) - switch (f->f_program[0]) { - case '+': - if (strcmp(prog, f->f_program + 1) != 0) - continue; - break; - case '-': - if (strcmp(prog, f->f_program + 1) == 0) - continue; - break; - default: - if (strcmp(prog, f->f_program) != 0) - continue; - break; - } + if (skip_message(prog, f->f_program)) + continue; + /* skip message to console if it has already been printed */ if (f->f_type == F_CONSOLE && (flags & IGN_CONS)) continue; |