svn commit: branches/busybox_scratch/util-linux

aldot at busybox.net aldot at busybox.net
Tue Jul 4 11:06:08 UTC 2006


Author: aldot
Date: 2006-07-04 04:06:01 -0700 (Tue, 04 Jul 2006)
New Revision: 15596

Log:
- rewrite dmesg so it doesn't segfault left and right and is smaller too.
   text    data     bss     dec     hex filename
    207       0       0     207      cf util-linux/dmesg.o.orig
    203       0       0     203      cb util-linux/dmesg.o


Modified:
   branches/busybox_scratch/util-linux/dmesg.c


Changeset:
Modified: branches/busybox_scratch/util-linux/dmesg.c
===================================================================
--- branches/busybox_scratch/util-linux/dmesg.c	2006-07-04 10:59:15 UTC (rev 15595)
+++ branches/busybox_scratch/util-linux/dmesg.c	2006-07-04 11:06:01 UTC (rev 15596)
@@ -1,35 +1,39 @@
-/* vi: set ts=4:
- * 
- * dmesg - display/control kernel ring buffer.
+/* vi: set sw=4 ts=4: */
+/* 
+ * dmesg - print or control the kernel ring buffer
  *
- * Copyring 2006 Rob Landley <rob at landley.net>
+ * Copyright (C) 2006 Bernhard Fischer
  *
  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  */
 
 #include "busybox.h"
-#include <unistd.h>
 #include <sys/klog.h>
 
-int dmesg_main(int argc, char *argv[])
+int dmesg_main(int argc, char **argv)
 {
-	char *size, *level;
-	int flags = bb_getopt_ulflags(argc, argv, "c:s:n:", &size, &level);
+	int len;
+	unsigned flags;
+	char *size, *level, *buf;
 
-	if (flags & 4) {
-		if(klogctl(8, NULL, bb_xgetlarg(size, 10, 0, 10)))
-			bb_perror_msg_and_die("klogctl");
-	} else {
-		int len;
-		char *buf;
+	flags = bb_getopt_ulflags(argc, argv, "cs:n:", &size, &level);
+#define DMESG_OPT_c (1<<0)
+#define DMESG_OPT_s (1<<1)
+#define DMESG_OPT_n (1<<2)
 
-		len = (flags & 2) ? bb_xgetlarg(size, 10, 4096, INT_MAX) : 16384;
-		buf = xmalloc(len);
-		if (0 > (len = klogctl(3 + (flags & 1), buf, len)))
+	if (flags & DMESG_OPT_n) {
+		if (klogctl(8, NULL, bb_xgetlarg(level, 10, 0, 10)) < 0)
+klogctl_failed:
 			bb_perror_msg_and_die("klogctl");
-		write(1,buf,len);
-		if (len && buf[len-1]!='\n') putchar('\n');
+		bb_fflush_stdout_and_exit(EXIT_SUCCESS);
 	}
+	buf = xmalloc(len = (flags & DMESG_OPT_s)
+						? bb_xgetlarg(size, 10, 4096, INT_MAX) : 16392);
+	if ((len = klogctl(3 + (flags & DMESG_OPT_c), buf, len)) < 0)
+		goto klogctl_failed;
+	write(STDOUT_FILENO, buf, len);
+	if (len && buf[len-1] != '\n') putchar('\n');
+	if (ENABLE_FEATURE_CLEAN_UP) free (buf);
 
-	return 0;
+	bb_fflush_stdout_and_exit(EXIT_SUCCESS);
 }




More information about the busybox-cvs mailing list