Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/dmesg Make is worthwhile haveing #ifdef SMALL by making...



details:   https://anonhg.NetBSD.org/src/rev/87a409ca339d
branches:  trunk
changeset: 584028:87a409ca339d
user:      dsl <dsl%NetBSD.org@localhost>
date:      Mon Sep 05 20:56:41 2005 +0000

description:
Make is worthwhile haveing #ifdef SMALL by making the Makefile set it when
SMALLPROG is defined (eg by src/distrib/commonMakefile.crunch).
Shrink SMALL version even more.

diffstat:

 sbin/dmesg/Makefile |   6 +++++-
 sbin/dmesg/dmesg.c  |  29 ++++++++++++++---------------
 2 files changed, 19 insertions(+), 16 deletions(-)

diffs (113 lines):

diff -r e45c443d3442 -r 87a409ca339d sbin/dmesg/Makefile
--- a/sbin/dmesg/Makefile       Mon Sep 05 20:42:37 2005 +0000
+++ b/sbin/dmesg/Makefile       Mon Sep 05 20:56:41 2005 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.11 2005/01/20 16:39:23 xtraeme Exp $
+#      $NetBSD: Makefile,v 1.12 2005/09/05 20:56:41 dsl Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/5/93
 
 PROG=  dmesg
@@ -6,4 +6,8 @@
 LDADD= -lkvm
 DPADD= ${LIBKVM}
 
+.ifdef SMALLPROG
+CPPFLAGS+=-DSMALL
+.endif
+
 .include <bsd.prog.mk>
diff -r e45c443d3442 -r 87a409ca339d sbin/dmesg/dmesg.c
--- a/sbin/dmesg/dmesg.c        Mon Sep 05 20:42:37 2005 +0000
+++ b/sbin/dmesg/dmesg.c        Mon Sep 05 20:56:41 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dmesg.c,v 1.23 2005/01/20 15:55:01 xtraeme Exp $       */
+/*     $NetBSD: dmesg.c,v 1.24 2005/09/05 20:56:41 dsl Exp $   */
 /*-
  * Copyright (c) 1991, 1993
  *     The Regents of the University of California.  All rights reserved.
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)dmesg.c    8.1 (Berkeley) 6/5/93";
 #else
-__RCSID("$NetBSD: dmesg.c,v 1.23 2005/01/20 15:55:01 xtraeme Exp $");
+__RCSID("$NetBSD: dmesg.c,v 1.24 2005/09/05 20:56:41 dsl Exp $");
 #endif
 #endif /* not lint */
 
@@ -62,12 +62,12 @@
        { "_msgbufp" },
        { NULL },
 };
-#endif
 
 void   usage(void);
 
 #define        KREAD(addr, var) \
        kvm_read(kd, addr, &var, sizeof(var)) != sizeof(var)
+#endif
 
 int
 main(int argc, char *argv[])
@@ -105,17 +105,14 @@
                mib[0] = CTL_KERN;
                mib[1] = KERN_MSGBUF;
 
-               if (sysctl(mib, 2, NULL, &size, NULL, 0) == -1)
-                       errx(1, "can't get size of msgbuf");
-
-               if ((bufdata = malloc(size)) == NULL)
-                       err(1, "couldn't allocate space for buffer data");
-
-               if (sysctl(mib, 2, bufdata, &size, NULL, 0) == -1)
+               if (sysctl(mib, 2, NULL, &size, NULL, 0) == -1 ||
+                   (bufdata = malloc(size)) == NULL ||
+                   sysctl(mib, 2, bufdata, &size, NULL, 0) == -1)
                        err(1, "can't get msgbuf");
 
                /* make a dummy struct msgbuf for the display logic */
-               cur.msg_bufx =  cur.msg_bufs = size;
+               cur.msg_bufx = 0;
+               cur.msg_bufs = size;
 #ifndef SMALL
        } else {
                kvm_t *kd;
@@ -164,8 +161,10 @@
         */
        for (newl = skip = i = 0, p = bufdata + cur.msg_bufx;
            i < cur.msg_bufs; i++, p++) {
+#ifndef SMALL
                if (p == bufdata + cur.msg_bufs)
                        p = bufdata;
+#endif
                ch = *p;
                /* Skip "\n<.*>" syslog sequences. */
                if (skip) {
@@ -181,9 +180,11 @@
                        continue;
                newl = ch == '\n';
                (void)vis(buf, ch, VIS_NOSLASH, 0);
+#ifndef SMALL
                if (buf[1] == 0)
                        (void)putchar(buf[0]);
                else
+#endif
                        (void)printf("%s", buf);
        }
        if (!newl)
@@ -191,14 +192,12 @@
        exit(0);
 }
 
+#ifndef SMALL
 void
 usage(void)
 {
 
-#ifdef SMALL
-       (void)fprintf(stderr, "usage: dmesg\n");
-#else
        (void)fprintf(stderr, "usage: dmesg [-M core] [-N system]\n");
-#endif
        exit(1);
 }
+#endif



Home | Main Index | Thread Index | Old Index