NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: lib/57172: LOG_MAKEPRI macro in sys/syslog.h defined incorrectly
The following reply was made to PR lib/57172; it has been noted by GNATS.
From: RVP <rvp%SDF.ORG@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc:
Subject: Re: lib/57172: LOG_MAKEPRI macro in sys/syslog.h defined
incorrectly
Date: Fri, 2 Aug 2024 22:41:31 +0000 (UTC)
I tripped over this same thing recently and made the patch below. It:
a) Gets rid of LOG_MAKEPRI(). The only user in-tree is syslogd(8).
b) Simplify INTERNAL_MARK.
c) Adds a `-k' flag to not translate remote kern.* -> user.* (from
FreeBSD).
(src/lib/libc/gen/xsyslog.c forces this on all locally-generated
kern.* messages. Maybe it shouldn't since syslogd does it anyway.)
d) Fix syslogd:
- SIGN_NUM_PRIVALS not defined anywhere.
- Use the standard idiom to make `priority'.
-RVP
---START patch---
diff -urN a/src/crypto/external/bsd/heimdal/dist/lib/roken/syslog.hin b/src/crypto/external/bsd/heimdal/dist/lib/roken/syslog.hin
--- a/src/crypto/external/bsd/heimdal/dist/lib/roken/syslog.hin 2011-04-13 18:15:43.000000000 +0000
+++ b/src/crypto/external/bsd/heimdal/dist/lib/roken/syslog.hin 2024-07-28 21:53:12.784379077 +0000
@@ -86,12 +86,11 @@
#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */
/* extract priority */
#define LOG_PRI(p) ((p) & LOG_PRIMASK)
-#define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri))
#ifdef SYSLOG_NAMES
#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */
/* mark "facility" */
-#define INTERNAL_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0)
+#define INTERNAL_MARK (LOG_NFACILITIES << 3)
typedef struct _code {
char *c_name;
int c_val;
diff -urN a/src/sys/sys/syslog.h b/src/sys/sys/syslog.h
--- a/src/sys/sys/syslog.h 2024-07-12 03:31:26.109855531 +0000
+++ b/src/sys/sys/syslog.h 2024-07-28 21:55:25.744625715 +0000
@@ -62,12 +62,11 @@
#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */
/* extract priority */
#define LOG_PRI(p) ((p) & LOG_PRIMASK)
-#define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri))
#ifdef SYSLOG_NAMES
#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */
/* mark "facility" */
-#define INTERNAL_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0)
+#define INTERNAL_MARK (LOG_NFACILITIES << 3)
typedef struct _code {
const char *c_name;
int c_val;
diff -urN a/src/usr.sbin/syslogd/syslogd.8 b/src/usr.sbin/syslogd/syslogd.8
--- a/src/usr.sbin/syslogd/syslogd.8 2022-11-08 01:43:09.000000000 +0000
+++ b/src/usr.sbin/syslogd/syslogd.8 2024-07-28 23:12:21.623389569 +0000
@@ -37,7 +37,7 @@
.Nd log systems messages
.Sh SYNOPSIS
.Nm
-.Op Fl nrSsTUvX
+.Op Fl knrSsTUvX
.Op Fl B Ar buffer_length
.Op Fl b Ar bind_address
.Op Fl d Op Oo Cm \&~ Oc Ns Ar what
@@ -91,6 +91,15 @@
Set GID to
.Ar group
after the sockets and log files have been opened.
+.It Fl k
+Disable the translation of (remote) messages received with facility
+.Dq kern
+to facility
+.Dq user .
+Usually the
+.Dq kern
+facility is reserved for messages read directly from
+.Pa /dev/klog .
.It Fl m Ar mark_interval
Select the number of minutes between ``mark'' messages;
the default is 20 minutes.
diff -urN a/src/usr.sbin/syslogd/syslogd.c b/src/usr.sbin/syslogd/syslogd.c
--- a/src/usr.sbin/syslogd/syslogd.c 2023-10-11 23:22:13.000000000 +0000
+++ b/src/usr.sbin/syslogd/syslogd.c 2024-07-28 22:54:20.649653887 +0000
@@ -205,6 +205,7 @@
* this, it will only break some syslog-sign
* configurations (e.g. with SG="0").
*/
+bool KernXlat = true; /* translate kern.* -> user.* */
char appname[] = "syslogd";/* the APPNAME for own messages */
char *include_pid; /* include PID in own messages */
char include_pid_buf[11];
@@ -319,7 +320,7 @@
/* should we set LC_TIME="C" to ensure correct timestamps&parsing? */
(void)setlocale(LC_ALL, "");
- while ((ch = getopt(argc, argv, "b:B:d::nsSf:m:o:p:P:ru:g:t:TUvX")) != -1)
+ while ((ch = getopt(argc, argv, "b:B:d::knsSf:m:o:p:P:ru:g:t:TUvX")) != -1)
switch(ch) {
case 'b':
bindhostname = optarg;
@@ -360,6 +361,9 @@
if (*group == '\0')
usage();
break;
+ case 'k': /* pass-thru (remote) kern.* */
+ KernXlat = true;
+ break;
case 'm': /* mark interval */
MarkInterval = atoi(optarg) * 60;
break;
@@ -557,7 +561,7 @@
#if (IETF_NUM_PRIVALUES != (LOG_NFACILITIES<<3))
logerror("Warning: system defines %d priority values, but "
"syslog-protocol/syslog-sign specify %d values",
- LOG_NFACILITIES, SIGN_NUM_PRIVALS);
+ LOG_NFACILITIES, IETF_NUM_PRIVALUES >> 3);
#endif
/*
@@ -1549,12 +1553,12 @@
pri = DEFUPRI;
/*
- * Don't allow users to log kernel messages.
+ * Don't (usually) allow users to log kernel messages.
* NOTE: Since LOG_KERN == 0, this will also match
* messages with no facility specified.
*/
- if ((pri & LOG_FACMASK) == LOG_KERN)
- pri = LOG_MAKEPRI(LOG_USER, LOG_PRI(pri));
+ if ((pri & LOG_FACMASK) == LOG_KERN && KernXlat)
+ pri = LOG_USER | LOG_PRI(pri);
if (bsdsyslog) {
buffer = printline_bsdsyslog(hname, p, flags, pri);
---END patch---
Home |
Main Index |
Thread Index |
Old Index