aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKang-Che Sung <explorer09@gmail.com>2017-01-31 17:06:43 +0800
committerDenys Vlasenko <vda.linux@googlemail.com>2017-02-01 01:33:37 +0100
commitfdfd716a858f6f63289b1156a80d06d7e86947de (patch)
treeee18761f141e343e01f5527d8937feb37a4d2d97
parentdc7637d0aa0efeb7cc8a7bcd798f0b5679251ad9 (diff)
downloadbusybox-w32-fdfd716a858f6f63289b1156a80d06d7e86947de.tar.gz
busybox-w32-fdfd716a858f6f63289b1156a80d06d7e86947de.tar.bz2
busybox-w32-fdfd716a858f6f63289b1156a80d06d7e86947de.zip
modprobe-small: move lsmod code out of modprobe_main()
Having lsmod code inside modprobe_main() makes some of the applet name checking code awkward. Besides, this make busybox x86_64 binary a few bytes smaller. :) function old new delta lsmod_main - 23 +23 modprobe_main 599 564 -35 ------------------------------------------------------------------- (add/remove: 1/0 grow/shrink: 0/1 up/down: 23/-35) Total: -12 bytes Signed-off-by: Kang-Che Sung <explorer09@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--modutils/modprobe-small.c44
1 files changed, 24 insertions, 20 deletions
diff --git a/modutils/modprobe-small.c b/modutils/modprobe-small.c
index 49c06d759..325f8376b 100644
--- a/modutils/modprobe-small.c
+++ b/modutils/modprobe-small.c
@@ -24,12 +24,12 @@
24//config: help 24//config: help
25//config: Check if the module is already loaded. 25//config: Check if the module is already loaded.
26 26
27//applet:IF_LSMOD( IF_MODPROBE_SMALL(APPLET(lsmod, BB_DIR_SBIN, BB_SUID_DROP)))
27//applet:IF_MODPROBE(IF_MODPROBE_SMALL(APPLET(modprobe, BB_DIR_SBIN, BB_SUID_DROP))) 28//applet:IF_MODPROBE(IF_MODPROBE_SMALL(APPLET(modprobe, BB_DIR_SBIN, BB_SUID_DROP)))
28// APPLET_ODDNAME:name main location suid_type help 29// APPLET_ODDNAME:name main location suid_type help
29//applet:IF_DEPMOD(IF_MODPROBE_SMALL(APPLET_ODDNAME(depmod, modprobe, BB_DIR_SBIN, BB_SUID_DROP, depmod))) 30//applet:IF_DEPMOD(IF_MODPROBE_SMALL(APPLET_ODDNAME(depmod, modprobe, BB_DIR_SBIN, BB_SUID_DROP, depmod)))
30//applet:IF_INSMOD(IF_MODPROBE_SMALL(APPLET_ODDNAME(insmod, modprobe, BB_DIR_SBIN, BB_SUID_DROP, insmod))) 31//applet:IF_INSMOD(IF_MODPROBE_SMALL(APPLET_ODDNAME(insmod, modprobe, BB_DIR_SBIN, BB_SUID_DROP, insmod)))
31//applet:IF_LSMOD(IF_MODPROBE_SMALL( APPLET_ODDNAME(lsmod, modprobe, BB_DIR_SBIN, BB_SUID_DROP, lsmod))) 32//applet:IF_RMMOD( IF_MODPROBE_SMALL(APPLET_ODDNAME(rmmod, modprobe, BB_DIR_SBIN, BB_SUID_DROP, rmmod)))
32//applet:IF_RMMOD(IF_MODPROBE_SMALL( APPLET_ODDNAME(rmmod, modprobe, BB_DIR_SBIN, BB_SUID_DROP, rmmod)))
33 33
34//kbuild:lib-$(CONFIG_MODPROBE_SMALL) += modprobe-small.o 34//kbuild:lib-$(CONFIG_MODPROBE_SMALL) += modprobe-small.o
35 35
@@ -59,7 +59,27 @@
59 59
60#define DEPFILE_BB CONFIG_DEFAULT_DEPMOD_FILE".bb" 60#define DEPFILE_BB CONFIG_DEFAULT_DEPMOD_FILE".bb"
61 61
62#define MOD_APPLET_CNT (ENABLE_MODPROBE + ENABLE_DEPMOD + ENABLE_INSMOD + ENABLE_LSMOD + ENABLE_RMMOD) 62//usage:#if ENABLE_MODPROBE_SMALL
63
64//usage:#define lsmod_trivial_usage
65//usage: ""
66//usage:#define lsmod_full_usage "\n\n"
67//usage: "List loaded kernel modules"
68
69//usage:#endif
70
71#if ENABLE_LSMOD
72int lsmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
73int lsmod_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
74{
75 xprint_and_close_file(xfopen_for_read("/proc/modules"));
76 return EXIT_SUCCESS;
77}
78#endif
79
80/* Num of applets that use modprobe_main() entry point. */
81/* lsmod is not here. */
82#define MOD_APPLET_CNT (ENABLE_MODPROBE + ENABLE_DEPMOD + ENABLE_INSMOD + ENABLE_RMMOD)
63 83
64/* Do not bother if MODPROBE_SMALL=y but no applets selected. */ 84/* Do not bother if MODPROBE_SMALL=y but no applets selected. */
65/* The rest of the file is in this if block. */ 85/* The rest of the file is in this if block. */
@@ -69,7 +89,6 @@
69#define is_modprobe (ENABLE_MODPROBE && (ONLY_APPLET || applet_name[0] == 'm')) 89#define is_modprobe (ENABLE_MODPROBE && (ONLY_APPLET || applet_name[0] == 'm'))
70#define is_depmod (ENABLE_DEPMOD && (ONLY_APPLET || applet_name[0] == 'd')) 90#define is_depmod (ENABLE_DEPMOD && (ONLY_APPLET || applet_name[0] == 'd'))
71#define is_insmod (ENABLE_INSMOD && (ONLY_APPLET || applet_name[0] == 'i')) 91#define is_insmod (ENABLE_INSMOD && (ONLY_APPLET || applet_name[0] == 'i'))
72#define is_lsmod (ENABLE_LSMOD && (ONLY_APPLET || applet_name[0] == 'l'))
73#define is_rmmod (ENABLE_RMMOD && (ONLY_APPLET || applet_name[0] == 'r')) 92#define is_rmmod (ENABLE_RMMOD && (ONLY_APPLET || applet_name[0] == 'r'))
74 93
75enum { 94enum {
@@ -890,11 +909,6 @@ The following options are useful for people managing distributions:
890//usage:#define depmod_trivial_usage NOUSAGE_STR 909//usage:#define depmod_trivial_usage NOUSAGE_STR
891//usage:#define depmod_full_usage "" 910//usage:#define depmod_full_usage ""
892 911
893//usage:#define lsmod_trivial_usage
894//usage: ""
895//usage:#define lsmod_full_usage "\n\n"
896//usage: "List loaded kernel modules"
897
898//usage:#define insmod_trivial_usage 912//usage:#define insmod_trivial_usage
899//usage: "FILE" IF_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE(" [SYMBOL=VALUE]...") 913//usage: "FILE" IF_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE(" [SYMBOL=VALUE]...")
900//usage:#define insmod_full_usage "\n\n" 914//usage:#define insmod_full_usage "\n\n"
@@ -922,12 +936,6 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
922 struct utsname uts; 936 struct utsname uts;
923 IF_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE(char *options = NULL;) 937 IF_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE(char *options = NULL;)
924 938
925 /* are we lsmod? -> just dump /proc/modules */
926 if (is_lsmod) {
927 xprint_and_close_file(xfopen_for_read("/proc/modules"));
928 return EXIT_SUCCESS;
929 }
930
931 INIT_G(); 939 INIT_G();
932 940
933 /* Prevent ugly corner cases with no modules at all */ 941 /* Prevent ugly corner cases with no modules at all */
@@ -940,11 +948,7 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
940 uname(&uts); /* never fails */ 948 uname(&uts); /* never fails */
941 949
942 /* depmod? */ 950 /* depmod? */
943 if ((MOD_APPLET_CNT == 2 && ENABLE_DEPMOD && ENABLE_LSMOD) 951 if (is_depmod) {
944 /* ^^^"only depmod and lsmod is configured"^^^^^^^^^^^^^^ */
945 /* note: we already know here it is not lsmod (handled before) */
946 || is_depmod
947 ) {
948 /* Supported: 952 /* Supported:
949 * -n: print result to stdout 953 * -n: print result to stdout
950 * -a: process all modules (default) 954 * -a: process all modules (default)