From owner-freebsd-bugs Fri Sep 27 11:40: 8 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5474637B401 for ; Fri, 27 Sep 2002 11:40:03 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 82D0943E75 for ; Fri, 27 Sep 2002 11:40:02 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.6/8.12.6) with ESMTP id g8RIe2Co000222 for ; Fri, 27 Sep 2002 11:40:02 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.6/8.12.6/Submit) id g8RIe2lW000221; Fri, 27 Sep 2002 11:40:02 -0700 (PDT) Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7895237B401 for ; Fri, 27 Sep 2002 11:35:18 -0700 (PDT) Received: from nebula.wanadoo.fr (ca-sqy-5-26.abo.wanadoo.fr [80.8.58.26]) by mx1.FreeBSD.org (Postfix) with ESMTP id D2BF543E42 for ; Fri, 27 Sep 2002 11:35:16 -0700 (PDT) (envelope-from dak@wanadoo.fr) Received: from nebula.wanadoo.fr (localhost [127.0.0.1]) by nebula.wanadoo.fr (8.12.5/8.12.5) with ESMTP id g8RIareQ091645 for ; Fri, 27 Sep 2002 20:36:53 +0200 (CEST) (envelope-from dak@nebula.wanadoo.fr) Received: (from dak@localhost) by nebula.wanadoo.fr (8.12.6/8.12.6/Submit) id g8RIaqVo091644; Fri, 27 Sep 2002 20:36:52 +0200 (CEST) Message-Id: <200209271836.g8RIaqVo091644@nebula.wanadoo.fr> Date: Fri, 27 Sep 2002 20:36:52 +0200 (CEST) From: Aurélien Nephtali Reply-To: Aurélien Nephtali To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/43434: New option to 'dmesg' which allow to display or not old boot messages Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 43434 >Category: bin >Synopsis: New option to 'dmesg' which allow to display or not old boot messages >Confidential: no >Severity: critical >Priority: high >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Fri Sep 27 11:40:01 PDT 2002 >Closed-Date: >Last-Modified: >Originator: dak >Release: FreeBSD 4.7-RC i386 >Organization: none >Environment: System: FreeBSD nebula.wanadoo.fr 4.7-RC FreeBSD 4.7-RC #168: Fri Sep 27 07:44:50 CEST 2002 dak@nebula.wanadoo.fr:/usr/src/sys/compile/NEBULA i386 >Description: Some times it could be usefull to display only the last boot message (ie: when grep'ing). The attached patch modifies sys/kern/subr_prf.c and dmesg.c (and the also the manual). It adds a tag (---<<>>---) at the begining of each boot message (the tag macro is stored in sys/sys/msgbuf.h and could also be stored in /usr/include/msgbuf.h) dmesg.c is modified and has a new option: -o, which when it is specified, displays the full content of the message buffer, otherwise only the last message is displayed). This patch has been tested (by me :p) without any troubles on -CURRENT. >How-To-Repeat: >Fix: --- current.patch begins here --- --- sbin/dmesg/dmesg.c Sun Aug 18 19:57:07 2002 +++ sbin/dmesg/dmesg.c Sun Sep 15 20:12:42 2002 @@ -66,12 +66,35 @@ { NULL }, }; +int getlastbootpos(char *buf, int len); void usage(void) __dead2; #define KREAD(addr, var) \ kvm_read(kd, addr, &var, sizeof(var)) != sizeof(var) int +getlastbootpos(char *buf, int len) +{ + int i; + char *ptr, *save; + + /* Skip NULL bytes */ + for(i = 0; (buf[i] == 0x0) && (i < len); i++); + + if (strlen(buf) == 0) + return(-1); + + while((ptr = (char *) strstr((buf +i), BOOT_TAG)) != NULL) { + save = (char *) ptr; + i += strlen(BOOT_TAG); /* Force strstr() to catch + * the next tag + */ + } + + return((int) ((int) (save + (strlen(BOOT_TAG))) - (int) buf)); +} + +int main(int argc, char *argv[]) { int ch, newl, skip; @@ -84,10 +107,12 @@ int pri; size_t buflen; int bufpos; + int old = 0; + int lastboot = 0; (void) setlocale(LC_CTYPE, ""); memf = nlistf = NULL; - while ((ch = getopt(argc, argv, "aM:N:")) != -1) + while ((ch = getopt(argc, argv, "aM:N:o")) != -1) switch(ch) { case 'a': all++; @@ -98,6 +123,9 @@ case 'N': nlistf = optarg; break; + case 'o': + old = 1; + break; case '?': default: usage(); @@ -151,11 +179,19 @@ * we effectively start at the oldest data. */ p = bp + bufpos; + if (!old) { + lastboot = getlastbootpos(p, buflen); + if (lastboot != -1) + p = bp + lastboot; + } ep = (bufpos == 0 ? bp + buflen : p); newl = skip = 0; do { if (p == bp + buflen) p = bp; + /* Skipping boot tag */ + if (!memcmp(p, BOOT_TAG, strlen(BOOT_TAG))) + p += strlen(BOOT_TAG); ch = *p; /* Skip "\n<.*>" syslog sequences. */ if (skip) { @@ -193,6 +229,6 @@ void usage(void) { - (void)fprintf(stderr, "usage: dmesg [-a] [-M core] [-N system]\n"); + (void)fprintf(stderr, "usage: dmesg [-a] [-M core] [-N system] [-o]\n"); exit(1); } --- sbin/dmesg/dmesg.8 Sat Aug 31 21:15:54 2002 +++ sbin/dmesg/dmesg.8 Sat Aug 31 20:57:27 2002 @@ -43,6 +43,7 @@ .Op Fl a .Op Fl M Ar core .Op Fl N Ar system +.Op Fl o .Sh DESCRIPTION The .Nm @@ -73,6 +74,8 @@ .It Fl N Extract the name list from the specified system instead of the default, which is the kernel image the system has booted from. +.It Fl o +Display all boot messages, not only the last. .El .Sh FILES .Bl -tag -width ".Pa /var/run/dmesg.boot" -compact --- sys/sys/msgbuf.h Sat Aug 31 21:07:05 2002 +++ sys/sys/msgbuf.h Sat Aug 31 21:08:40 2002 @@ -46,6 +46,10 @@ char * msg_ptr; /* pointer to buffer */ }; +#define BOOT_TAG "---<>---" /* used by dmesg util to know where a + * boot message starts. + */ + #ifdef _KERNEL extern int msgbuftrigger; extern struct msgbuf *msgbufp; --- sys/kern/subr_prf.c Sat Aug 31 21:00:35 2002 +++ sys/kern/subr_prf.c Sat Aug 31 21:01:01 2002 @@ -818,6 +818,9 @@ msgbufp->msg_size = (char *)msgbufp - cp; } msgbufp->msg_ptr = cp; + memcpy((void *) (msgbufp->msg_ptr + msgbufp->msg_bufx), BOOT_TAG, + strlen(BOOT_TAG)); + msgbufp->msg_bufx += strlen(BOOT_TAG); if (msgbufmapped && oldp != msgbufp) msgbufcopy(oldp); msgbufmapped = 1; --- current.patch ends here --- >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message