From 946eac9366509b6c6dd690b9b601e8d63b7ddcc8 Mon Sep 17 00:00:00 2001 From: thomas Date: Thu, 13 Feb 2003 00:08:56 +0000 Subject: Allow multiple hosts or programs to be named in program or host specifications, eg: !foo,bar *.* /var/log/only_foo_or_bar.log !-foo,bar *.* /var/log/all_except_foo_or_bar.log Reviewed by: roberto Not objected to by: arch@ --- usr.sbin/syslogd/syslog.conf.5 | 12 ++++++++++++ usr.sbin/syslogd/syslogd.c | 33 +++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 6 deletions(-) (limited to 'usr.sbin/syslogd') diff --git a/usr.sbin/syslogd/syslog.conf.5 b/usr.sbin/syslogd/syslog.conf.5 index 328e3a6..f13f1bf 100644 --- a/usr.sbin/syslogd/syslog.conf.5 +++ b/usr.sbin/syslogd/syslog.conf.5 @@ -196,6 +196,15 @@ or .Ql !-prog specification will match any message but the ones from that program. +Multiple programs may be listed, separated by commas: +.Ql !prog1,prog2 +matches messages from either program, while +.Ql !-prog1,prog2 +matches all messages but those from +.Ql prog1 +or +.Ql prog2 . +.Pp A .Em hostname specification of the form @@ -215,6 +224,9 @@ from any host but the one specified. If the hostname is given as .Ql @ , the local hostname will be used. +As for program specifications, multiple comma-seprarated +values may be specified for hostname specifications. +.Pp A .Em program or diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index f8fb385..92d1605 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -764,17 +764,38 @@ static time_t now; */ static int skip_message(const char *name, const char *spec) { + const char *s; + char prev, next; + int exclude = 0; + /* Behaviour on explicit match */ + if (spec == NULL) return 0; - - switch (spec[0]) { - case '+': - return (strcmp(name, spec + 1) != 0); + switch (*spec) { case '-': - return (strcmp(name, spec + 1) == 0); + exclude = 1; + /*FALLTHROUGH*/ + case '+': + spec++; + break; default: - return (strcmp(name, spec) != 0); + break; } + s = strstr (spec, name); + + if (s != NULL) { + prev = (s == spec ? ',' : *(s - 1)); + next = *(s + strlen (name)); + + if (prev == ',' && (next == '\0' || next == ',')) + /* Explicit match: skip iff the spec is an + exclusive one. */ + return exclude; + } + + /* No explicit match for this name: skip the message iff + the spec is an inclusive one. */ + return !exclude; } /* -- cgit v1.1