Bug 28935

Summary: syslogd -u doesn't treat * as "all levels"
Product: Base System Reporter: SANETO Takanori <sanewo>
Component: binAssignee: dwmalone
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.3-STABLE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description SANETO Takanori 2001-07-13 09:50:01 UTC
When invoked with -u, syslogd logs nothing to all.log with following
syslog.conf entry:

*.*	/var/log/all.log

 In syslogd.c, '*' is converted to priority level LOG_PRIMASK+1.
 Without -u, default comparison is '>=' and LOG_PRIMASK+1 is larger
than any actual priority level, comparison always succeeds (as
intended).
 With -u, comparison is '==' and no actual priority level is equal to
LOG_PRIMASK+1, comparison always fails.

Fix: A quick hack patch is as follows:
How-To-Repeat: 
Invoke syslogd with -u and see all.log doesn't grow.
Comment 1 dwmalone freebsd_committer freebsd_triage 2001-07-13 10:54:49 UTC
Responsible Changed
From-To: freebsd-bugs->dwmalone

I'll have a look at this one.
Comment 2 dwmalone 2002-08-11 17:31:58 UTC
This is a possible patch for:

	http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/28935

which points out that "*" means completly the wrong thing if you
run syslogd -u. It would seem to make more sense to consider "*"
as having an explicit set of comparison flags "<=>".

This also patch adds a "!" comparison flag which should be compatable
with the same flag in the Linux version of syslogd. I'm not sure I
find the linux semtics that intuative, but there is little point in
being incompatable.

	David.


Index: syslog.conf.5
===================================================================
RCS file: /cvs/FreeBSD-CVS/src/usr.sbin/syslogd/syslog.conf.5,v
retrieving revision 1.26
diff -u -r1.26 syslog.conf.5
--- syslog.conf.5	16 May 2002 02:28:39 -0000	1.26
+++ syslog.conf.5	11 Aug 2002 16:20:16 -0000
@@ -85,7 +85,7 @@
 a period
 .Pq Dq \&. ,
 an optional set of comparison flags
-.Pq Bq <=> ,
+.Pq Bo ! Bc Bq <=> ,
 and a
 .Em level ,
 with no intervening white-space.
@@ -123,6 +123,15 @@
 level equal or greater than
 .Em level
 will be logged.
+Comparison flags beginning with
+.Do ! Dc
+will have their logical sense inverted.
+Thus
+.Dq !=info
+means all levels except info and
+.Dq !notice
+has the same meaning as
+.Dq <notice .
 .Pp
 The
 .Em level
Index: syslogd.c
===================================================================
RCS file: /cvs/FreeBSD-CVS/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.104
diff -u -r1.104 syslogd.c
--- syslogd.c	25 Jul 2002 15:45:41 -0000	1.104
+++ syslogd.c	11 Aug 2002 16:05:16 -0000
@@ -1591,6 +1591,7 @@
 	for (p = line; *p && *p != '\t' && *p != ' ';) {
 		int pri_done;
 		int pri_cmp;
+		int pri_invert;
 
 		/* find the end of this facility name list */
 		for (q = p; *q && *q != '\t' && *q != ' ' && *q++ != '.'; )
@@ -1599,6 +1600,11 @@
 		/* get the priority comparison */
 		pri_cmp = 0;
 		pri_done = 0;
+		pri_invert = 0;
+		if (*q == '!') {
+			pri_invert = 1;
+			q++;
+		}
 		while (!pri_done) {
 			switch (*q) {
 			case '<':
@@ -1618,11 +1624,6 @@
 				break;
 			}
 		}
-		if (!pri_cmp)
-			pri_cmp = (UniquePriority)
-				  ? (PRI_EQ)
-				  : (PRI_EQ | PRI_GT)
-				  ;
 
 		/* collect priority name */
 		for (bp = buf; *q && !strchr("\t,; ", *q); )
@@ -1636,6 +1637,7 @@
 		/* decode priority name */
 		if (*buf == '*') {
 			pri = LOG_PRIMASK + 1;
+			pri_cmp = PRI_LT | PRI_EQ | PRI_GT;
 		} else {
 			pri = decode(buf, prioritynames);
 			if (pri < 0) {
@@ -1645,6 +1647,13 @@
 				return;
 			}
 		}
+		if (!pri_cmp)
+			pri_cmp = (UniquePriority)
+				  ? (PRI_EQ)
+				  : (PRI_EQ | PRI_GT)
+				  ;
+		if (pri_invert)
+			pri_cmp ^= PRI_LT | PRI_EQ | PRI_GT;
 
 		/* scan facilities */
 		while (*p && !strchr("\t.; ", *p)) {
Comment 3 dwmalone freebsd_committer freebsd_triage 2002-12-01 21:44:05 UTC
State Changed
From-To: open->closed

Now fixed in -current and -stable.