modprobe-small: move lsmod code out of modprobe_main()
authorKang-Che Sung <explorer09@gmail.com>
Tue, 31 Jan 2017 09:06:43 +0000 (17:06 +0800)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 1 Feb 2017 00:33:37 +0000 (01:33 +0100)
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>
modutils/modprobe-small.c

index 49c06d7591a29026cf00e034d939694386497461..325f8376bc5ded1be2b0c7cd94c6c8d1dc2bf4fb 100644 (file)
 //config:      help
 //config:        Check if the module is already loaded.
 
+//applet:IF_LSMOD(   IF_MODPROBE_SMALL(APPLET(lsmod,    BB_DIR_SBIN, BB_SUID_DROP)))
 //applet:IF_MODPROBE(IF_MODPROBE_SMALL(APPLET(modprobe, BB_DIR_SBIN, BB_SUID_DROP)))
 //                                   APPLET_ODDNAME:name    main      location     suid_type     help
 //applet:IF_DEPMOD(IF_MODPROBE_SMALL(APPLET_ODDNAME(depmod, modprobe, BB_DIR_SBIN, BB_SUID_DROP, depmod)))
 //applet:IF_INSMOD(IF_MODPROBE_SMALL(APPLET_ODDNAME(insmod, modprobe, BB_DIR_SBIN, BB_SUID_DROP, insmod)))
-//applet:IF_LSMOD(IF_MODPROBE_SMALL( APPLET_ODDNAME(lsmod,  modprobe, BB_DIR_SBIN, BB_SUID_DROP, lsmod)))
-//applet:IF_RMMOD(IF_MODPROBE_SMALL( APPLET_ODDNAME(rmmod,  modprobe, BB_DIR_SBIN, BB_SUID_DROP, rmmod)))
+//applet:IF_RMMOD( IF_MODPROBE_SMALL(APPLET_ODDNAME(rmmod,  modprobe, BB_DIR_SBIN, BB_SUID_DROP, rmmod)))
 
 //kbuild:lib-$(CONFIG_MODPROBE_SMALL) += modprobe-small.o
 
 
 #define DEPFILE_BB CONFIG_DEFAULT_DEPMOD_FILE".bb"
 
-#define MOD_APPLET_CNT (ENABLE_MODPROBE + ENABLE_DEPMOD + ENABLE_INSMOD + ENABLE_LSMOD + ENABLE_RMMOD)
+//usage:#if ENABLE_MODPROBE_SMALL
+
+//usage:#define lsmod_trivial_usage
+//usage:       ""
+//usage:#define lsmod_full_usage "\n\n"
+//usage:       "List loaded kernel modules"
+
+//usage:#endif
+
+#if ENABLE_LSMOD
+int lsmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int lsmod_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
+{
+       xprint_and_close_file(xfopen_for_read("/proc/modules"));
+       return EXIT_SUCCESS;
+}
+#endif
+
+/* Num of applets that use modprobe_main() entry point. */
+/* lsmod is not here. */
+#define MOD_APPLET_CNT (ENABLE_MODPROBE + ENABLE_DEPMOD + ENABLE_INSMOD + ENABLE_RMMOD)
 
 /* Do not bother if MODPROBE_SMALL=y but no applets selected. */
 /* The rest of the file is in this if block. */
@@ -69,7 +89,6 @@
 #define is_modprobe (ENABLE_MODPROBE && (ONLY_APPLET || applet_name[0] == 'm'))
 #define is_depmod   (ENABLE_DEPMOD   && (ONLY_APPLET || applet_name[0] == 'd'))
 #define is_insmod   (ENABLE_INSMOD   && (ONLY_APPLET || applet_name[0] == 'i'))
-#define is_lsmod    (ENABLE_LSMOD    && (ONLY_APPLET || applet_name[0] == 'l'))
 #define is_rmmod    (ENABLE_RMMOD    && (ONLY_APPLET || applet_name[0] == 'r'))
 
 enum {
@@ -890,11 +909,6 @@ The following options are useful for people managing distributions:
 //usage:#define depmod_trivial_usage NOUSAGE_STR
 //usage:#define depmod_full_usage ""
 
-//usage:#define lsmod_trivial_usage
-//usage:       ""
-//usage:#define lsmod_full_usage "\n\n"
-//usage:       "List loaded kernel modules"
-
 //usage:#define insmod_trivial_usage
 //usage:       "FILE" IF_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE(" [SYMBOL=VALUE]...")
 //usage:#define insmod_full_usage "\n\n"
@@ -922,12 +936,6 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
        struct utsname uts;
        IF_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE(char *options = NULL;)
 
-       /* are we lsmod? -> just dump /proc/modules */
-       if (is_lsmod) {
-               xprint_and_close_file(xfopen_for_read("/proc/modules"));
-               return EXIT_SUCCESS;
-       }
-
        INIT_G();
 
        /* Prevent ugly corner cases with no modules at all */
@@ -940,11 +948,7 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
        uname(&uts); /* never fails */
 
        /* depmod? */
-       if ((MOD_APPLET_CNT == 2 && ENABLE_DEPMOD && ENABLE_LSMOD)
-        /* ^^^"only depmod and lsmod is configured"^^^^^^^^^^^^^^ */
-        /* note: we already know here it is not lsmod (handled before) */
-        || is_depmod
-       ) {
+       if (is_depmod) {
                /* Supported:
                 * -n: print result to stdout
                 * -a: process all modules (default)