[BusyBox-cvs] busybox/modutils modprobe.c,1.19,1.20

Erik Andersen andersen at busybox.net
Fri Jun 20 09:56:40 UTC 2003


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

Modified Files:
	modprobe.c 
Log Message:
Patch from Andrew Dennison:

I've had some issues with modprobe which I reported a few months ago. This  
is still an issue so I decided to sort it out.

The attached diff includes the changes against the unstable cvs tree that
work for me.

Changes are:
mod_process() will report success if the module at the head of the list
loads successfully. It will also report success if any module unloads
successfully.
The net result being that modprobe will succeed in the cases outlined below.
I've also added error reporting to modprobe -r. Previously it would silently
fail (but report success) if the module could not be unloaded.   

Andrew



Index: modprobe.c
===================================================================
RCS file: /var/cvs/busybox/modutils/modprobe.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- modprobe.c	19 Mar 2003 09:12:34 -0000	1.19
+++ modprobe.c	20 Jun 2003 09:56:37 -0000	1.20
@@ -3,6 +3,7 @@
  * Modprobe written from scratch for BusyBox
  *
  * Copyright (c) 2002 by Robert Griebl, griebl at gmx.de
+ * Copyright (c) 2003 by Andrew Dennison, andrew.dennison at motec.com.au
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -317,10 +318,7 @@
 static int mod_process ( struct mod_list_t *list, int do_insert )
 {
 	char lcmd [256];
-	int rc = 0;
-
-	if ( !list )
-		return 1;
+	int rc = 1;
 
 	while ( list ) {
 		if ( do_insert )
@@ -330,12 +328,15 @@
 		
 		if ( verbose )
 			printf ( "%s\n", lcmd );
-		if ( !show_only )
-			rc |= system ( lcmd );
+		if ( !show_only ) {
+			int rc2 = system ( lcmd );
+			if (do_insert) rc = rc2; /* only last module matters */
+			else if (!rc2) rc = 0; /* success if remove any mod */
+		}
 			
 		list = do_insert ? list-> m_prev : list-> m_next;
 	}
-	return rc;
+	return (show_only) ? 0 : rc;
 }
 
 static void check_dep ( char *mod, struct mod_list_t **head, struct mod_list_t **tail )
@@ -429,7 +430,7 @@
 {
 	struct mod_list_t *tail = 0;
 	struct mod_list_t *head = 0; 	
-	int rc = 0;
+	int rc;
 	
 	// get dep list for module mod
 	check_dep ( mod, &head, &tail );
@@ -453,7 +454,7 @@
 		}
 		
 		// process tail ---> head
-		rc |= mod_process ( tail, 1 );
+		rc = mod_process ( tail, 1 );
 	}
 	else
 		rc = 1;
@@ -461,8 +462,9 @@
 	return rc;
 }
 
-static void mod_remove ( char *mod )
+static int mod_remove ( char *mod )
 {
+	int rc;
 	static struct mod_list_t rm_a_dummy = { "-a", 0, 0 }; 
 	
 	struct mod_list_t *head = 0;
@@ -474,7 +476,11 @@
 		head = tail = &rm_a_dummy;
 	
 	if ( head && tail )
-		mod_process ( head, 0 );  // process head ---> tail
+		rc = mod_process ( head, 0 );  // process head ---> tail
+	else
+		rc = 1;
+	return rc;
+	
 }
 
 
@@ -530,11 +536,17 @@
 		bb_error_msg_and_die ( "could not parse modules.dep\n" );
 	
 	if (remove_opt) {
+		int rc = EXIT_SUCCESS;
 		do {
-			mod_remove ( optind < argc ? bb_xstrdup ( argv [optind] ) : NULL );
+			if (mod_remove ( optind < argc ?
+					 bb_xstrdup (argv [optind]) : NULL )) {
+				bb_error_msg ("failed to remove module %s",
+					argv [optind] );
+				rc = EXIT_FAILURE;
+			}
 		} while ( ++optind < argc );
 		
-		return EXIT_SUCCESS;
+		return rc;
 	}
 
 	if (optind >= argc) 



More information about the busybox-cvs mailing list