svn commit: trunk/busybox: include libbb modutils

landley at busybox.net landley at busybox.net
Mon Aug 28 19:40:09 UTC 2006


Author: landley
Date: 2006-08-28 12:40:08 -0700 (Mon, 28 Aug 2006)
New Revision: 16003

Log:
No real need for my_query_module() and this eliminates some type-punned
pointer warning on certain gcc versions (and saves 38 bytes).


Removed:
   trunk/busybox/libbb/qmodule.c

Modified:
   trunk/busybox/include/libbb.h
   trunk/busybox/libbb/Makefile.in
   trunk/busybox/modutils/lsmod.c
   trunk/busybox/modutils/rmmod.c


Changeset:
Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2006-08-28 16:45:51 UTC (rev 16002)
+++ trunk/busybox/include/libbb.h	2006-08-28 19:40:08 UTC (rev 16003)
@@ -521,8 +521,6 @@
 extern procps_status_t * procps_scan(int save_user_arg0);
 extern int compare_string_array(const char * const string_array[], const char *key);
 
-extern int my_query_module(const char *name, int which, void **buf, size_t *bufsize, size_t *ret);
-
 extern void print_login_issue(const char *issue_file, const char *tty);
 extern void print_login_prompt(void);
 

Modified: trunk/busybox/libbb/Makefile.in
===================================================================
--- trunk/busybox/libbb/Makefile.in	2006-08-28 16:45:51 UTC (rev 16002)
+++ trunk/busybox/libbb/Makefile.in	2006-08-28 19:40:08 UTC (rev 16003)
@@ -23,7 +23,7 @@
 	make_directory.c md5.c mode_string.c mtab_file.c \
 	obscure.c parse_mode.c parse_number.c perror_msg.c \
 	perror_msg_and_die.c get_console.c \
-	process_escape_sequence.c procps.c qmodule.c \
+	process_escape_sequence.c procps.c \
 	recursive_action.c remove_file.c \
 	restricted_shell.c run_parts.c run_shell.c safe_read.c safe_write.c \
 	safe_strncpy.c setup_environment.c sha1.c simplify_path.c \

Deleted: trunk/busybox/libbb/qmodule.c
===================================================================
--- trunk/busybox/libbb/qmodule.c	2006-08-28 16:45:51 UTC (rev 16002)
+++ trunk/busybox/libbb/qmodule.c	2006-08-28 19:40:08 UTC (rev 16003)
@@ -1,30 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
-   Copyright (C) 2002 Tim Riker <Tim at Rikers.org>
-   everyone seems to claim it someplace. ;-)
-*/
-
-#include <errno.h>
-
-#include "libbb.h"
-
-int query_module(const char *name, int which, void *buf, size_t bufsize, size_t *ret);
-
-int my_query_module(const char *name, int which, void **buf,
-		size_t *bufsize, size_t *ret)
-{
-	int my_ret;
-
-	my_ret = query_module(name, which, *buf, *bufsize, ret);
-
-	if (my_ret == -1 && errno == ENOSPC) {
-		*buf = xrealloc(*buf, *ret);
-		*bufsize = *ret;
-
-		my_ret = query_module(name, which, *buf, *bufsize, ret);
-	}
-
-	return my_ret;
-}
-
-

Modified: trunk/busybox/modutils/lsmod.c
===================================================================
--- trunk/busybox/modutils/lsmod.c	2006-08-28 16:45:51 UTC (rev 16002)
+++ trunk/busybox/modutils/lsmod.c	2006-08-28 19:40:08 UTC (rev 16003)
@@ -15,7 +15,7 @@
 
 
 #ifndef CONFIG_FEATURE_CHECK_TAINTED_MODULE
-static inline void check_tainted(void) { printf("\n"); }
+static void check_tainted(void) { printf("\n"); }
 #else
 #define TAINT_FILENAME                  "/proc/sys/kernel/tainted"
 #define TAINT_PROPRIETORY_MODULE        (1<<0)
@@ -80,13 +80,15 @@
 	char *module_names, *mn, *deps, *dn;
 	size_t bufsize, depsize, nmod, count, i, j;
 
-	module_names = xmalloc(bufsize = 256);
-	if (my_query_module(NULL, QM_MODULES, &module_names, &bufsize, &nmod)) {
-		bb_perror_msg_and_die("QM_MODULES");
+	module_names = deps = NULL;
+	bufsize = depsize = 0;
+	while(query_module(NULL, QM_MODULES, module_names, bufsize, &nmod)) {
+		if (errno != ENOSPC) bb_perror_msg_and_die("QM_MODULES");
+		module_names = xmalloc(bufsize = nmod);
 	}
 
 	deps = xmalloc(depsize = 256);
-	printf("Module                  Size  Used by");
+	printf("Module\t\t\tSize  Used by");
 	check_tainted();
 
 	for (i = 0, mn = module_names; i < nmod; mn += strlen(mn) + 1, i++) {
@@ -98,12 +100,13 @@
 			/* else choke */
 			bb_perror_msg_and_die("module %s: QM_INFO", mn);
 		}
-		if (my_query_module(mn, QM_REFS, &deps, &depsize, &count)) {
+		while (query_module(mn, QM_REFS, deps, depsize, &count)) {
 			if (errno == ENOENT) {
 				/* The module was removed out from underneath us. */
 				continue;
-			}
-			bb_perror_msg_and_die("module %s: QM_REFS", mn);
+			} else if (errno != ENOSPC) 
+				bb_perror_msg_and_die("module %s: QM_REFS", mn);
+			deps = xrealloc(deps, count);
 		}
 		printf("%-20s%8lu%4ld", mn, info.size, info.usecount);
 		if (info.flags & NEW_MOD_DELETED)

Modified: trunk/busybox/modutils/rmmod.c
===================================================================
--- trunk/busybox/modutils/rmmod.c	2006-08-28 16:45:51 UTC (rev 16002)
+++ trunk/busybox/modutils/rmmod.c	2006-08-28 19:40:08 UTC (rev 16003)
@@ -8,29 +8,18 @@
  */
 
 #include "busybox.h"
-#include <stdio.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <getopt.h>
-#include <fcntl.h>
-#include <string.h>
-#include <sys/utsname.h>
 #include <sys/syscall.h>
 
 #ifdef CONFIG_FEATURE_2_6_MODULES
 static inline void filename2modname(char *modname, const char *afterslash)
 {
 	unsigned int i;
-
-#if ENABLE_FEATURE_2_4_MODULES
 	int kr_chk = 1;
-	if (get_linux_version_code() <= KERNEL_VERSION(2,6,0))
-		kr_chk = 0;
-#else
-#define kr_chk 1
-#endif
 
+	if (ENABLE_FEATURE_2_4_MODULES
+			&& get_linux_version_code() <= KERNEL_VERSION(2,6,0))
+				kr_chk = 0;
+
 	/* Convert to underscores, stop at first . */
 	for (i = 0; afterslash[i] && afterslash[i] != '.'; i++) {
 		if (kr_chk && (afterslash[i] == '-'))
@@ -40,17 +29,19 @@
 	}
 	modname[i] = '\0';
 }
+#else
+void filename2modname(char *modname, const char *afterslash);
 #endif
 
+// There really should be a header file for this...
+
+int query_module(const char *name, int which, void *buf,
+		        size_t bufsize, size_t *ret);
+
 int rmmod_main(int argc, char **argv)
 {
 	int n, ret = EXIT_SUCCESS;
 	unsigned int flags = O_NONBLOCK|O_EXCL;
-#ifdef CONFIG_FEATURE_QUERY_MODULE_INTERFACE
-	/* bb_common_bufsiz1 hold the module names which we ignore
-	   but must get */
-	size_t bufsize = sizeof(bb_common_bufsiz1);
-#endif
 
 	/* Parse command line. */
 	n = bb_getopt_ulflags(argc, argv, "wfa");
@@ -71,12 +62,13 @@
 				bb_perror_msg_and_die("rmmod");
 			}
 			pnmod = nmod;
-#ifdef CONFIG_FEATURE_QUERY_MODULE_INTERFACE
-			/* 1 == QM_MODULES */
-			if (my_query_module(NULL, 1, &bb_common_bufsiz1, &bufsize, &nmod)) {
+			// the 1 here is QM_MODULES.
+			if (ENABLE_FEATURE_QUERY_MODULE_INTERFACE && query_module(NULL,
+					1, bb_common_bufsiz1, sizeof(bb_common_bufsiz1),
+					&nmod))
+			{
 				bb_perror_msg_and_die("QM_MODULES");
 			}
-#endif
 		}
 		return EXIT_SUCCESS;
 	}
@@ -85,21 +77,16 @@
 		bb_show_usage();
 
 	for (n = optind; n < argc; n++) {
-#ifdef CONFIG_FEATURE_2_6_MODULES
-		const char *afterslash;
-		char *module_name;
+		if (ENABLE_FEATURE_2_6_MODULES) {
+			const char *afterslash;
 
-		afterslash = strrchr(argv[n], '/');
-		if (!afterslash)
-			afterslash = argv[n];
-		else
-			afterslash++;
-		module_name = alloca(strlen(afterslash) + 1);
-		filename2modname(module_name, afterslash);
-#else
-#define module_name		argv[n]
-#endif
-		if (syscall(__NR_delete_module, module_name, flags) != 0) {
+			afterslash = strrchr(argv[n], '/');
+			if (!afterslash) afterslash = argv[n];
+			else afterslash++;
+			filename2modname(bb_common_bufsiz1, afterslash);
+		}
+
+		if (syscall(__NR_delete_module, ENABLE_FEATURE_2_6_MODULES ? bb_common_bufsiz1 : argv[n], flags)) {
 			bb_perror_msg("%s", argv[n]);
 			ret = EXIT_FAILURE;
 		}




More information about the busybox-cvs mailing list