From a53dffb7742d7efd1a5ab956ba7c5d1e7163f009 Mon Sep 17 00:00:00 2001 From: Dima Dorfman Date: Tue, 27 Nov 2001 20:02:18 +0000 Subject: [PATCH] Make the default kernel prefix "kernel:" instead of the boot file, with the old behavior available via the -o option (it might still be useful if one has many kernels and cares which messages came from which). If the boot file is not used as the prefix, it is still logged once at startup. This change is prompted by the fact that the boot file is now much longer ("/boot/kernel/kernel" vs. "/kernel"), which significanlty bloats the syslogd output. Reviewed by: peter --- usr.sbin/syslogd/syslogd.8 | 9 +++++++-- usr.sbin/syslogd/syslogd.c | 20 ++++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/usr.sbin/syslogd/syslogd.8 b/usr.sbin/syslogd/syslogd.8 index 641bb4ad2ee1..85fb00e01a9d 100644 --- a/usr.sbin/syslogd/syslogd.8 +++ b/usr.sbin/syslogd/syslogd.8 @@ -32,7 +32,7 @@ .\" @(#)syslogd.8 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" -.Dd October 12, 1995 +.Dd November 24, 2001 .Dt SYSLOGD 8 .Os .Sh NAME @@ -40,7 +40,7 @@ .Nd log systems messages .Sh SYNOPSIS .Nm -.Op Fl 46Adknsuv +.Op Fl 46Adknosuv .Op Fl a Ar allowed_peer .Op Fl b Ar bind_address .Op Fl f Ar config_file @@ -181,6 +181,11 @@ Select the number of minutes between messages; the default is 20 minutes. .It Fl n Disable dns query for every request. +.It Fl o +Prefix kernel messages with the full kernel boot file as determined by +.Xr getbootfile 3 . +Without this, the kernel message prefix is always +.Dq kernel: . .It Fl p Specify the pathname of an alternate log socket to be used instead; the default is diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index b8d520238855..0cfa84c1f57d 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -273,6 +273,7 @@ int family = PF_UNSPEC; /* protocol family (IPv4, IPv6 or both) */ int family = PF_INET; /* protocol family (IPv4 only) */ #endif int send_to_all = 0; /* send message to all IPv4/IPv6 addresses */ +int use_bootfile = 0; /* log entire bootfile for every kern msg */ char bootfile[MAXLINE+1]; /* booted kernel file */ @@ -333,7 +334,7 @@ main(argc, argv) socklen_t len; bindhostname = NULL; - while ((ch = getopt(argc, argv, "46Aa:b:df:kl:m:np:P:suv")) != -1) + while ((ch = getopt(argc, argv, "46Aa:b:df:kl:m:nop:P:suv")) != -1) switch (ch) { case '4': family = PF_INET; @@ -375,6 +376,9 @@ main(argc, argv) case 'n': resolve = 0; break; + case 'o': + use_bootfile = 1; + break; case 'p': /* path */ funixn[0] = optarg; break; @@ -807,7 +811,8 @@ logmsg(pri, msg, from, flags) /* add kernel prefix for kernel messages */ if (flags & ISKERNEL) { - snprintf(buf, sizeof(buf), "%s: %s", bootfile, msg); + snprintf(buf, sizeof(buf), "%s: %s", + use_bootfile ? bootfile : "kernel", msg); msg = buf; msglen = strlen(buf); } @@ -1337,6 +1342,7 @@ init(signo) char host[MAXHOSTNAMELEN]; char oldLocalHostName[MAXHOSTNAMELEN]; char hostMsg[2*MAXHOSTNAMELEN+40]; + char bootfileMsg[LINE_MAX]; dprintf("init\n"); @@ -1526,6 +1532,16 @@ init(signo) logmsg(LOG_SYSLOG|LOG_INFO, hostMsg, LocalHostName, ADDDATE); dprintf("%s\n", hostMsg); } + /* + * Log the kernel boot file if we aren't going to use it as + * the prefix, and if this is *not* a restart. + */ + if (signo == 0 && !use_bootfile) { + (void)snprintf(bootfileMsg, sizeof(bootfileMsg), + "syslogd: kernel boot file is %s", bootfile); + logmsg(LOG_KERN|LOG_INFO, bootfileMsg, LocalHostName, ADDDATE); + dprintf("%s\n", bootfileMsg); + } } /*