diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2015-03-23 03:59:44 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-03-23 03:59:44 +0100 |
commit | be947c4d97c0dacb703a6f24dd813ff6dd3a33b6 (patch) | |
tree | ad9b443c79e4b8547a86567328231c09dfcac108 /modutils/modprobe-small.c | |
parent | 1ecfe811fe2f70380170ef7d820e8150054e88ca (diff) | |
download | busybox-w32-1_23_2.tar.gz busybox-w32-1_23_2.tar.bz2 busybox-w32-1_23_2.zip |
Apply post-1.23.1 patches, bump version to 1.23.21_23_2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'modutils/modprobe-small.c')
-rw-r--r-- | modutils/modprobe-small.c | 75 |
1 files changed, 43 insertions, 32 deletions
diff --git a/modutils/modprobe-small.c b/modutils/modprobe-small.c index cf8a3f0fe..e6d43229c 100644 --- a/modutils/modprobe-small.c +++ b/modutils/modprobe-small.c | |||
@@ -552,9 +552,23 @@ static int already_loaded(const char *name) | |||
552 | return ret; | 552 | return ret; |
553 | } | 553 | } |
554 | #else | 554 | #else |
555 | #define already_loaded(name) is_rmmod | 555 | #define already_loaded(name) 0 |
556 | #endif | 556 | #endif |
557 | 557 | ||
558 | static int rmmod(const char *filename) | ||
559 | { | ||
560 | int r; | ||
561 | char modname[MODULE_NAME_LEN]; | ||
562 | |||
563 | filename2modname(filename, modname); | ||
564 | r = delete_module(modname, O_NONBLOCK | O_EXCL); | ||
565 | dbg1_error_msg("delete_module('%s', O_NONBLOCK | O_EXCL):%d", modname, r); | ||
566 | if (r != 0 && !(option_mask32 & OPT_q)) { | ||
567 | bb_perror_msg("remove '%s'", modname); | ||
568 | } | ||
569 | return r; | ||
570 | } | ||
571 | |||
558 | /* | 572 | /* |
559 | * Given modules definition and module name (or alias, or symbol) | 573 | * Given modules definition and module name (or alias, or symbol) |
560 | * load/remove the module respecting dependencies. | 574 | * load/remove the module respecting dependencies. |
@@ -571,26 +585,36 @@ static void process_module(char *name, const char *cmdline_options) | |||
571 | module_info **infovec; | 585 | module_info **infovec; |
572 | module_info *info; | 586 | module_info *info; |
573 | int infoidx; | 587 | int infoidx; |
574 | int is_rmmod = (option_mask32 & OPT_r) != 0; | 588 | int is_remove = (option_mask32 & OPT_r) != 0; |
575 | 589 | ||
576 | dbg1_error_msg("process_module('%s','%s')", name, cmdline_options); | 590 | dbg1_error_msg("process_module('%s','%s')", name, cmdline_options); |
577 | 591 | ||
578 | replace(name, '-', '_'); | 592 | replace(name, '-', '_'); |
579 | 593 | ||
580 | dbg1_error_msg("already_loaded:%d is_rmmod:%d", already_loaded(name), is_rmmod); | 594 | dbg1_error_msg("already_loaded:%d is_remove:%d", already_loaded(name), is_remove); |
595 | |||
596 | if (applet_name[0] == 'r') { | ||
597 | /* rmmod. | ||
598 | * Does not remove dependencies, no need to scan, just remove. | ||
599 | * (compat note: this allows and strips .ko suffix) | ||
600 | */ | ||
601 | rmmod(name); | ||
602 | return; | ||
603 | } | ||
604 | |||
581 | /* | 605 | /* |
582 | * We used to have "is_rmmod != already_loaded(name)" check here, but | 606 | * We used to have "is_remove != already_loaded(name)" check here, but |
583 | * modprobe -r pci:v00008086d00007010sv00000000sd00000000bc01sc01i80 | 607 | * modprobe -r pci:v00008086d00007010sv00000000sd00000000bc01sc01i80 |
584 | * won't unload modules (there are more than one) | 608 | * won't unload modules (there are more than one) |
585 | * which have this alias. | 609 | * which have this alias. |
586 | */ | 610 | */ |
587 | if (!is_rmmod && already_loaded(name)) { | 611 | if (!is_remove && already_loaded(name)) { |
588 | dbg1_error_msg("nothing to do for '%s'", name); | 612 | dbg1_error_msg("nothing to do for '%s'", name); |
589 | return; | 613 | return; |
590 | } | 614 | } |
591 | 615 | ||
592 | options = NULL; | 616 | options = NULL; |
593 | if (!is_rmmod) { | 617 | if (!is_remove) { |
594 | char *opt_filename = xasprintf("/etc/modules/%s", name); | 618 | char *opt_filename = xasprintf("/etc/modules/%s", name); |
595 | options = xmalloc_open_read_close(opt_filename, NULL); | 619 | options = xmalloc_open_read_close(opt_filename, NULL); |
596 | if (options) | 620 | if (options) |
@@ -624,7 +648,7 @@ static void process_module(char *name, const char *cmdline_options) | |||
624 | 0 /* depth */ | 648 | 0 /* depth */ |
625 | ); | 649 | ); |
626 | dbg1_error_msg("dirscan complete"); | 650 | dbg1_error_msg("dirscan complete"); |
627 | /* Module was not found, or load failed, or is_rmmod */ | 651 | /* Module was not found, or load failed, or is_remove */ |
628 | if (module_found_idx >= 0) { /* module was found */ | 652 | if (module_found_idx >= 0) { /* module was found */ |
629 | infovec = xzalloc(2 * sizeof(infovec[0])); | 653 | infovec = xzalloc(2 * sizeof(infovec[0])); |
630 | infovec[0] = &modinfo[module_found_idx]; | 654 | infovec[0] = &modinfo[module_found_idx]; |
@@ -637,7 +661,7 @@ static void process_module(char *name, const char *cmdline_options) | |||
637 | 661 | ||
638 | if (!infovec) { | 662 | if (!infovec) { |
639 | /* both dirscan and find_alias found nothing */ | 663 | /* both dirscan and find_alias found nothing */ |
640 | if (!is_rmmod && applet_name[0] != 'd') /* it wasn't rmmod or depmod */ | 664 | if (!is_remove && applet_name[0] != 'd') /* it wasn't rmmod or depmod */ |
641 | bb_error_msg("module '%s' not found", name); | 665 | bb_error_msg("module '%s' not found", name); |
642 | //TODO: _and_die()? or should we continue (un)loading modules listed on cmdline? | 666 | //TODO: _and_die()? or should we continue (un)loading modules listed on cmdline? |
643 | goto ret; | 667 | goto ret; |
@@ -651,29 +675,15 @@ static void process_module(char *name, const char *cmdline_options) | |||
651 | * a *list* of modinfo pointers from find_alias(). | 675 | * a *list* of modinfo pointers from find_alias(). |
652 | */ | 676 | */ |
653 | 677 | ||
654 | /* rmmod or modprobe -r? unload module(s) */ | 678 | /* modprobe -r? unload module(s) */ |
655 | if (is_rmmod) { | 679 | if (is_remove) { |
656 | infoidx = 0; | 680 | infoidx = 0; |
657 | while ((info = infovec[infoidx++]) != NULL) { | 681 | while ((info = infovec[infoidx++]) != NULL) { |
658 | int r; | 682 | int r = rmmod(bb_get_last_path_component_nostrip(info->pathname)); |
659 | char modname[MODULE_NAME_LEN]; | ||
660 | |||
661 | filename2modname( | ||
662 | bb_get_last_path_component_nostrip(info->pathname), modname); | ||
663 | r = delete_module(modname, O_NONBLOCK | O_EXCL); | ||
664 | dbg1_error_msg("delete_module('%s', O_NONBLOCK | O_EXCL):%d", modname, r); | ||
665 | if (r != 0) { | 683 | if (r != 0) { |
666 | if (!(option_mask32 & OPT_q)) | 684 | goto ret; /* error */ |
667 | bb_perror_msg("remove '%s'", modname); | ||
668 | goto ret; | ||
669 | } | 685 | } |
670 | } | 686 | } |
671 | |||
672 | if (applet_name[0] == 'r') { | ||
673 | /* rmmod: do not remove dependencies, exit */ | ||
674 | goto ret; | ||
675 | } | ||
676 | |||
677 | /* modprobe -r: we do not stop here - | 687 | /* modprobe -r: we do not stop here - |
678 | * continue to unload modules on which the module depends: | 688 | * continue to unload modules on which the module depends: |
679 | * "-r --remove: option causes modprobe to remove a module. | 689 | * "-r --remove: option causes modprobe to remove a module. |
@@ -694,7 +704,7 @@ static void process_module(char *name, const char *cmdline_options) | |||
694 | } | 704 | } |
695 | free(deps); | 705 | free(deps); |
696 | 706 | ||
697 | if (is_rmmod) | 707 | if (is_remove) |
698 | continue; | 708 | continue; |
699 | 709 | ||
700 | /* We are modprobe: load it */ | 710 | /* We are modprobe: load it */ |
@@ -897,10 +907,10 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv) | |||
897 | } | 907 | } |
898 | 908 | ||
899 | #if ENABLE_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE | 909 | #if ENABLE_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE |
900 | /* If not rmmod, parse possible module options given on command line. | 910 | /* If not rmmod/-r, parse possible module options given on command line. |
901 | * insmod/modprobe takes one module name, the rest are parameters. */ | 911 | * insmod/modprobe takes one module name, the rest are parameters. */ |
902 | options = NULL; | 912 | options = NULL; |
903 | if ('r' != applet0) { | 913 | if (!(option_mask32 & OPT_r)) { |
904 | char **arg = argv; | 914 | char **arg = argv; |
905 | while (*++arg) { | 915 | while (*++arg) { |
906 | /* Enclose options in quotes */ | 916 | /* Enclose options in quotes */ |
@@ -911,7 +921,7 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv) | |||
911 | } | 921 | } |
912 | } | 922 | } |
913 | #else | 923 | #else |
914 | if ('r' != applet0) | 924 | if (!(option_mask32 & OPT_r)) |
915 | argv[1] = NULL; | 925 | argv[1] = NULL; |
916 | #endif | 926 | #endif |
917 | 927 | ||
@@ -935,10 +945,11 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv) | |||
935 | } | 945 | } |
936 | 946 | ||
937 | /* Try to load modprobe.dep.bb */ | 947 | /* Try to load modprobe.dep.bb */ |
938 | load_dep_bb(); | 948 | if ('r' != applet0) /* not rmmod */ |
949 | load_dep_bb(); | ||
939 | 950 | ||
940 | /* Load/remove modules. | 951 | /* Load/remove modules. |
941 | * Only rmmod loops here, modprobe has only argv[0] */ | 952 | * Only rmmod/modprobe -r loops here, insmod/modprobe has only argv[0] */ |
942 | do { | 953 | do { |
943 | process_module(*argv, options); | 954 | process_module(*argv, options); |
944 | } while (*++argv); | 955 | } while (*++argv); |