static void check_dep ( char *mod, int do_syslog, int show_only, int verbose, int flags ) { static struct dep_t *depend = (struct dep_t *) -1; struct dep_t *dt; if ( depend == (struct dep_t *) -1 ) depend = build_dep ( ); if (( dt = find_dep ( depend, mod ))) { int i; for ( i = 0; i < dt->m_depcnt; i++ ) check_dep ( dt->m_deparr [i], do_syslog, show_only, verbose, flags|MODPROBE_EXECUTE); } if ( flags & MODPROBE_EXECUTE ) { char lcmd [256]; if ( flags & MODPROBE_INSERT ) { snprintf(lcmd, sizeof(lcmd)-1, "insmod %s -q -k %s 2>/dev/null", do_syslog ? "-s" : "", mod ); } if ( flags & MODPROBE_REMOVE ) { snprintf(lcmd, sizeof(lcmd)-1, "insmod %s -q -k %s 2>/dev/null", do_syslog ? "-s" : "", mod ); } if ( flags & (MODPROBE_REMOVE|MODPROBE_INSERT) ) { if (verbose) printf("%s\n", lcmd); if (!show_only) system ( lcmd ); } } }
int modprobe_main(int argc, char** argv) { int rc = EXIT_SUCCESS; char *unused; bb_opt_complementally = "?V-:q-v:v-q"; main_opts = bb_getopt_ulflags(argc, argv, "acdklnqrst:vVC:", &unused, &unused); if((main_opts & (DUMP_CONF_EXIT | LIST_ALL))) return EXIT_SUCCESS; if((main_opts & (RESTRICT_DIR | CONFIG_FILE))) bb_error_msg_and_die("-t and -C not supported"); depend = build_dep ( ); if ( !depend ) bb_error_msg_and_die ( "could not parse modules.dep" ); if (remove_opt) { do { if (mod_remove ( optind < argc ? argv [optind] : NULL )) { bb_error_msg ("failed to remove module %s", argv [optind] ); rc = EXIT_FAILURE; } } while ( ++optind < argc ); } else { if (optind >= argc) bb_error_msg_and_die ( "No module or pattern provided" ); if ( mod_insert ( argv [optind], argc - optind - 1, argv + optind + 1 )) bb_error_msg_and_die ( "failed to load module %s", argv [optind] ); } /* Here would be a good place to free up memory allocated during the dependencies build. */ return rc; }
int modprobe_main(int argc, char **argv) { int rc = EXIT_SUCCESS; char *unused; opt_complementary = "q-v:v-q"; getopt32(argv, MAIN_OPT_STR, &unused, &unused); if (option_mask32 & (DUMP_CONF_EXIT | LIST_ALL)) return EXIT_SUCCESS; if (option_mask32 & (RESTRICT_DIR | CONFIG_FILE)) bb_error_msg_and_die("-t and -C not supported"); depend = build_dep(); if (!depend) bb_error_msg_and_die("cannot parse "CONFIG_DEFAULT_DEPMOD_FILE); if (remove_opt) { do { /* argv[optind] can be NULL here */ if (mod_remove(argv[optind])) { bb_error_msg("failed to %s module %s", "remove", argv[optind]); rc = EXIT_FAILURE; } } while (++optind < argc); } else { if (optind >= argc) bb_error_msg_and_die("no module or pattern provided"); if (mod_insert(argv[optind], argc - optind - 1, argv + optind + 1)) bb_error_msg_and_die("failed to %s module %s", "load", argv[optind]); } /* Here would be a good place to free up memory allocated during the dependencies build. */ return rc; }
extern int modprobe_main(int argc, char** argv) { int opt; int remove_opt = 0; autoclean = show_only = quiet = do_syslog = verbose = 0; while ((opt = getopt(argc, argv, "acdklnqrst:vVC:")) != -1) { switch(opt) { case 'c': // no config used case 'l': // no pattern matching return EXIT_SUCCESS; break; case 'C': // no config used case 't': // no pattern matching error_msg_and_die("-t and -C not supported"); case 'a': // ignore case 'd': // ignore break; case 'k': autoclean++; break; case 'n': show_only++; break; case 'q': quiet++; break; case 'r': remove_opt++; break; case 's': do_syslog++; break; case 'v': verbose++; break; case 'V': default: show_usage(); break; } } depend = build_dep ( ); if ( !depend ) error_msg_and_die ( "could not parse modules.dep\n" ); if (remove_opt) { do { mod_remove ( optind < argc ? xstrdup ( argv [optind] ) : 0 ); } while ( ++optind < argc ); return EXIT_SUCCESS; } if (optind >= argc) error_msg_and_die ( "No module or pattern provided\n" ); return mod_insert ( xstrdup ( argv [optind] ), argc - optind - 1, argv + optind + 1 ) ? \ EXIT_FAILURE : EXIT_SUCCESS; }