[BusyBox-cvs] busybox/modutils lsmod.c,1.35,1.36 rmmod.c,1.21,1.22

Tim Riker timr at busybox.net
Sat Dec 14 01:59:03 UTC 2002


Update of /var/cvs/busybox/modutils
In directory winder:/tmp/cvs-serv4970/modutils

Modified Files:
	lsmod.c rmmod.c 
Log Message:
rmmod -a removed modules recursively

Index: lsmod.c
===================================================================
RCS file: /var/cvs/busybox/modutils/lsmod.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- lsmod.c	13 Dec 2002 22:59:15 -0000	1.35
+++ lsmod.c	14 Dec 2002 01:58:59 -0000	1.36
@@ -98,23 +98,6 @@
 static const int NEW_MOD_USED_ONCE = 16;
 static const int NEW_MOD_INITIALIZING = 64;
 
-static 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;
-}
-
 extern int lsmod_main(int argc, char **argv)
 {
 	struct module_info info;

Index: rmmod.c
===================================================================
RCS file: /var/cvs/busybox/modutils/rmmod.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- rmmod.c	24 Oct 2001 04:59:54 -0000	1.21
+++ rmmod.c	14 Dec 2002 01:58:59 -0000	1.22
@@ -34,14 +34,30 @@
 extern int rmmod_main(int argc, char **argv)
 {
 	int n, ret = EXIT_SUCCESS;
+	size_t nmod = 0; /* number of modules */
+	size_t pnmod = -1; /* previous number of modules */
+	void *buf; /* hold the module names which we ignore but must get */
+	size_t bufsize = 0;
 
 	/* Parse command line. */
 	while ((n = getopt(argc, argv, "a")) != EOF) {
 		switch (n) {
 			case 'a':
 				/* Unload _all_ unused modules via NULL delete_module() call */
-				if (delete_module(NULL))
-					perror_msg_and_die("rmmod");
+				/* until the number of modules does not change */
+				buf = xmalloc(bufsize = 256);
+				while (nmod != pnmod) {
+					if (delete_module(NULL))
+						perror_msg_and_die("rmmod");
+					pnmod = nmod;
+					/* 1 == QM_MODULES */
+					if (my_query_module(NULL, 1, &buf, &bufsize, &nmod)) {
+						perror_msg_and_die("QM_MODULES");
+					}
+				}
+#ifdef CONFIG_FEATURE_CLEAN_UP
+				free(buf);
+#endif
 				return EXIT_SUCCESS;
 			default:
 				show_usage();




More information about the busybox-cvs mailing list