Date: Tue, 14 Jul 1998 03:03:12 -0400 (EDT) From: Harlan Stenn <Harlan.Stenn@pfcs.com> To: FreeBSD-gnats-submit@FreeBSD.ORG Subject: bin/7278: Improvements to syslogd Message-ID: <199807140703.DAA02420@brown.pfcs.com>
index | next in thread | raw e-mail
>Number: 7278
>Category: bin
>Synopsis: Improvements to syslogd
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Tue Jul 14 00:10:01 PDT 1998
>Last-Modified:
>Originator: Harlan Stenn
>Organization:
>Release: FreeBSD 2.2.6-STABLE i386
>Environment:
-STABLE and/or -CURRENT
>Description:
The following patches add better logging and control to syslogd
>How-To-Repeat:
Examination.
>Fix:
--- usr.bin/wall/ttymsg.c- Fri May 27 08:33:27 1994
+++ usr.bin/wall/ttymsg.c Thu May 21 04:18:38 1998
@@ -64,7 +64,7 @@
static char device[MAXNAMLEN] = _PATH_DEV;
static char errbuf[1024];
register int cnt, fd, left, wret;
- struct iovec localiov[6];
+ struct iovec localiov[7];
int forked = 0;
if (iovcnt > sizeof(localiov) / sizeof(localiov[0]))
--- usr.sbin/syslogd/syslogd.c- Tue Jun 2 00:55:46 1998
+++ usr.sbin/syslogd/syslogd.c Sun Jul 12 01:11:55 1998
@@ -67,6 +67,8 @@
* more extensive changes by Eric Allman (again)
* Extension to log by program name as well as facility and priority
* by Peter da Silva.
+ * -u and -v by Harlan Stenn.
+ * Priority comparison code by Harlan Stenn.
*/
#define MAXLINE 1024 /* maximum line length */
@@ -143,6 +145,10 @@
short f_file; /* file descriptor */
time_t f_time; /* time this was last written */
u_char f_pmask[LOG_NFACILITIES+1]; /* priority mask */
+ u_char f_pcmp[LOG_NFACILITIES+1]; /* compare priority */
+#define PRI_LT 0x1
+#define PRI_EQ 0x2
+#define PRI_GT 0x4
char *f_program; /* program this applies to */
union {
char f_uname[MAXUNAMES][UT_NAMESIZE+1];
@@ -255,6 +261,10 @@
struct allowedpeer *AllowedPeers;
int NumAllowed = 0; /* # of AllowedPeer entries */
+int UniquePriority = 0; /* Only log specified priority? */
+int LogFacPri = 0; /* Put facility and priority in log message: */
+ /* 0=no, 1=numeric, 2=names */
+
int allowaddr __P((char *));
void cfline __P((char *, struct filed *, char *));
char *cvthname __P((struct sockaddr_in *));
@@ -290,7 +300,7 @@
struct timeval tv, *tvp;
pid_t ppid;
- while ((ch = getopt(argc, argv, "a:dsf:m:p:")) != -1)
+ while ((ch = getopt(argc, argv, "a:dsf:m:p:uv")) != -1)
switch(ch) {
case 'd': /* debug */
Debug++;
@@ -311,6 +321,12 @@
case 's': /* no network mode */
SecureMode++;
break;
+ case 'u': /* only log specified priority */
+ UniquePriority++;
+ break;
+ case 'v': /* log facility and priority */
+ LogFacPri++;
+ break;
case '?':
default:
usage();
@@ -473,7 +489,7 @@
{
fprintf(stderr, "%s\n%s\n",
- "usage: syslogd [-ds] [-a allowed_peer] [-f config_file]",
+ "usage: syslogd [-dsuv] [-a allowed_peer] [-f config_file]",
" [-m mark_interval] [-p log_socket]");
exit(1);
}
@@ -639,8 +655,11 @@
}
for (f = Files; f; f = f->f_next) {
/* skip messages that are incorrect priority */
- if (f->f_pmask[fac] < prilev ||
- f->f_pmask[fac] == INTERNAL_NOPRI)
+ if (!(((f->f_pcmp[fac] & PRI_EQ) && (f->f_pmask[fac] == prilev))
+ ||((f->f_pcmp[fac] & PRI_LT) && (f->f_pmask[fac] < prilev))
+ ||((f->f_pcmp[fac] & PRI_GT) && (f->f_pmask[fac] > prilev))
+ )
+ || f->f_pmask[fac] == INTERNAL_NOPRI)
continue;
/* skip messages with the incorrect program name */
if(f->f_program)
@@ -704,7 +723,7 @@
int flags;
char *msg;
{
- struct iovec iov[6];
+ struct iovec iov[7];
struct iovec *v;
int l;
char line[MAXLINE + 1], repbuf[80], greetings[200];
@@ -728,6 +747,49 @@
v->iov_len = 1;
v++;
}
+
+ if (LogFacPri) {
+ static char fp_buf[30]; /* Hollow laugh */
+ int fac = f->f_prevpri & LOG_FACMASK;
+ int pri = LOG_PRI(f->f_prevpri);
+ char *f_s = 0;
+ char f_n[5]; /* Hollow laugh */
+ char *p_s = 0;
+ char p_n[5]; /* Hollow laugh */
+
+ if (LogFacPri > 1) {
+ CODE *c;
+
+ for (c = facilitynames; c; c++) {
+ if (c->c_val == fac) {
+ f_s = c->c_name;
+ break;
+ }
+ }
+ for (c = prioritynames; c; c++) {
+ if (c->c_val == pri) {
+ p_s = c->c_name;
+ break;
+ }
+ }
+ }
+ if (!f_s) {
+ snprintf(f_n, sizeof f_n, "%d", LOG_FAC(fac));
+ f_s = f_n;
+ }
+ if (!p_s) {
+ snprintf(p_n, sizeof p_n, "%d", pri);
+ p_s = p_n;
+ }
+ snprintf(fp_buf, sizeof fp_buf, "<%s.%s> ", f_s, p_s);
+ v->iov_base = fp_buf;
+ v->iov_len = strlen(fp_buf);
+ } else {
+ v->iov_base="";
+ v->iov_len = 0;
+ }
+ v++;
+
v->iov_base = f->f_prevhost;
v->iov_len = strlen(v->iov_base);
v++;
@@ -778,7 +840,7 @@
dprintf(" %s\n", f->f_un.f_fname);
v->iov_base = "\n";
v->iov_len = 1;
- if (writev(f->f_file, iov, 6) < 0) {
+ if (writev(f->f_file, iov, 7) < 0) {
int e = errno;
(void)close(f->f_file);
f->f_type = F_UNUSED;
@@ -800,7 +862,7 @@
break;
}
}
- if (writev(f->f_file, iov, 6) < 0) {
+ if (writev(f->f_file, iov, 7) < 0) {
int e = errno;
(void)close(f->f_file);
if (f->f_un.f_pipe.f_pid > 0)
@@ -824,7 +886,7 @@
v->iov_len = 2;
errno = 0; /* ttymsg() only sometimes returns an errno */
- if ((msgret = ttymsg(iov, 6, f->f_un.f_fname, 10))) {
+ if ((msgret = ttymsg(iov, 7, f->f_un.f_fname, 10))) {
f->f_type = F_UNUSED;
logerror(msgret);
}
@@ -873,7 +935,7 @@
strncpy(line, ut.ut_line, sizeof(ut.ut_line));
line[sizeof(ut.ut_line)] = '\0';
if (f->f_type == F_WALL) {
- if ((p = ttymsg(iov, 6, line, TTYMSGTIME)) != NULL) {
+ if ((p = ttymsg(iov, 7, line, TTYMSGTIME)) != NULL) {
errno = 0; /* already in msg */
logerror(p);
}
@@ -885,7 +947,7 @@
break;
if (!strncmp(f->f_un.f_uname[i], ut.ut_name,
UT_NAMESIZE)) {
- if ((p = ttymsg(iov, 6, line, TTYMSGTIME))
+ if ((p = ttymsg(iov, 7, line, TTYMSGTIME))
!= NULL) {
errno = 0; /* already in msg */
logerror(p);
@@ -1257,11 +1319,41 @@
/* scan through the list of selectors */
for (p = line; *p && *p != '\t';) {
+ int pri_done;
+ int pri_cmp;
/* find the end of this facility name list */
for (q = p; *q && *q != '\t' && *q++ != '.'; )
continue;
+ /* get the priority comparison */
+ pri_cmp = 0;
+ pri_done = 0;
+ while (!pri_done) {
+ switch (*q) {
+ case '<':
+ pri_cmp |= PRI_LT;
+ q++;
+ break;
+ case '=':
+ pri_cmp |= PRI_EQ;
+ q++;
+ break;
+ case '>':
+ pri_cmp |= PRI_GT;
+ q++;
+ break;
+ default:
+ pri_done++;
+ break;
+ }
+ }
+ if (!pri_cmp)
+ pri_cmp = (UniquePriority)
+ ? (PRI_EQ)
+ : (PRI_EQ | PRI_GT)
+ ;
+
/* collect priority name */
for (bp = buf; *q && !strchr("\t,;", *q); )
*bp++ = *q++;
@@ -1289,9 +1381,12 @@
for (bp = buf; *p && !strchr("\t,;.", *p); )
*bp++ = *p++;
*bp = '\0';
+
if (*buf == '*')
- for (i = 0; i < LOG_NFACILITIES; i++)
+ for (i = 0; i < LOG_NFACILITIES; i++) {
f->f_pmask[i] = pri;
+ f->f_pcmp[i] = pri_cmp;
+ }
else {
i = decode(buf, facilitynames);
if (i < 0) {
@@ -1302,6 +1397,7 @@
return;
}
f->f_pmask[i >> 3] = pri;
+ f->f_pcmp[i >> 3] = pri_cmp;
}
while (*p == ',' || *p == ' ')
p++;
--- usr.sbin/syslogd/syslog.conf.5- Fri Mar 13 05:24:11 1998
+++ usr.sbin/syslogd/syslog.conf.5 Tue Jun 2 02:01:30 1998
@@ -71,6 +71,8 @@
.Em facility ,
a period
.Pq Dq \&. ,
+an optional set of comparison flags
+.Pq Bq <=> ,
and a
.Em level ,
with no intervening white-space.
@@ -95,6 +97,21 @@
library routines.
.Pp
The
+.Em comparison flags
+may be used to specify exactly what is logged.
+The default set of comparison flags are
+.Dq =>
+(or, if you prefer,
+.Do >=
+.Dc ),
+which means that messages from the specified
+.Em facility
+list of a priority
+level equal or greater than
+.Em level
+will be logged.
+.Pp
+The
.Em level
describes the severity of the message, and is a keyword from the
following ordered list (higher to lower): emerg, alert, crit, err,
@@ -269,6 +286,9 @@
# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none /var/log/messages
+
+# Log daemon messages at debug level only
+daemon.=debug /var/log/daemon.debug
# The authpriv file has restricted access.
authpriv.* /var/log/secure
--- usr.sbin/syslogd/syslogd.8- Sun Jul 12 01:29:19 1998
+++ usr.sbin/syslogd/syslogd.8 Sun Jul 12 01:18:36 1998
@@ -40,7 +40,7 @@
.Nd log systems messages
.Sh SYNOPSIS
.Nm
-.Op Fl ds
+.Op Fl dsuv
.Op Fl a Ar allowed_peer
.Op Fl f Ar config_file
.Op Fl m Ar mark_interval
@@ -120,6 +120,18 @@
.Pa /var/run/log .
.It Fl s
Operate in secure mode. Do not listen for log message from remote machines.
+.It Fl u
+Unique priority logging. Only log messages at the specified priority.
+Without this option, messages at the stated priority or higher are logged.
+This option changes the default comparison from
+.Dq =>
+to
+.Dq = .
+.It Fl v
+Verbose logging. If specified once, the numeric facility and priority are
+logged with each locally-written message. If specified more than once,
+the names of the facility and priority are logged with each locally-written
+message.
.El
.Pp
The
@@ -186,9 +198,11 @@
.Bx 4.3 .
.Pp
The
-.Fl s
+.Fl a ,
+.Fl s ,
+.Fl u ,
and
-.Fl a
+.Fl v
options are
.Fx 2.2
extensions.
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199807140703.DAA02420>
