aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-09-23 12:32:58 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-09-23 12:32:58 +0000
commitfe76cd5a5c26793b67de07a424e3c2ef395a0440 (patch)
treea6cca4e12064d9379c5acf9683f982d88d9efbb8
parentd78b433414fead8ef8de0da63484edaee7e3f80a (diff)
downloadbusybox-w32-fe76cd5a5c26793b67de07a424e3c2ef395a0440.tar.gz
busybox-w32-fe76cd5a5c26793b67de07a424e3c2ef395a0440.tar.bz2
busybox-w32-fe76cd5a5c26793b67de07a424e3c2ef395a0440.zip
insmod: getopt_ulflags'isation
-rw-r--r--modutils/insmod.c102
1 files changed, 40 insertions, 62 deletions
diff --git a/modutils/insmod.c b/modutils/insmod.c
index 2b2e3637d..f8e26dba3 100644
--- a/modutils/insmod.c
+++ b/modutils/insmod.c
@@ -693,12 +693,36 @@ enum { STRVERSIONLEN = 32 };
693 693
694/*======================================================================*/ 694/*======================================================================*/
695 695
696static int flag_force_load = 0; 696static unsigned option_mask;
697static int flag_autoclean = 0; 697#define OPTION_STR "sLo:fkvqx" USE_FEATURE_INSMOD_LOAD_MAP("m")
698static int flag_verbose = 0; 698enum {
699static int flag_quiet = 0; 699 OPT_s = 0x1, // -s /* log to syslog */
700static int flag_export = 1; 700 /* Not supported but kernel needs this for request_module(),
701 701 as this calls: modprobe -k -s -- <module>
702 so silently ignore this flag */
703 OPT_L = 0x2, // -L /* Stub warning */
704 /* Compatibility with modprobe.
705 In theory, this does locking, but we don't do
706 that. So be careful and plan your life around not
707 loading the same module 50 times concurrently. */
708 OPT_o = 0x4, // -o /* name the output module */
709 OPT_f = 0x8, // -f /* force loading */
710 OPT_k = 0x10, // -k /* module loaded by kerneld, auto-cleanable */
711 OPT_v = 0x20, // -v /* verbose output */
712 OPT_q = 0x40, // -q /* silent */
713 OPT_x = 0x80, // -x /* do not export externs */
714 OPT_m = 0x100, // -m /* print module load map */
715};
716#define flag_force_load (option_mask & OPT_f)
717#define flag_autoclean (option_mask & OPT_k)
718#define flag_verbose (option_mask & OPT_v)
719#define flag_quiet (option_mask & OPT_q)
720#define flag_noexport (option_mask & OPT_x)
721#ifdef CONFIG_FEATURE_INSMOD_LOAD_MAP
722#define flag_print_load_map (option_mask & OPT_m)
723#else
724#define flag_print_load_map 0
725#endif
702 726
703/*======================================================================*/ 727/*======================================================================*/
704 728
@@ -2851,7 +2875,7 @@ static int new_create_module_ksymtab(struct obj_file *f)
2851 } 2875 }
2852 } 2876 }
2853 2877
2854 if (flag_export && !obj_find_section(f, "__ksymtab")) { 2878 if (!flag_noexport && !obj_find_section(f, "__ksymtab")) {
2855 size_t nsyms; 2879 size_t nsyms;
2856 int *loaded; 2880 int *loaded;
2857 2881
@@ -3764,7 +3788,7 @@ add_ksymoops_symbols(struct obj_file *f, const char *filename,
3764 * are not to be exported. otherwise leave ksymtab alone for now, the 3788 * are not to be exported. otherwise leave ksymtab alone for now, the
3765 * "export all symbols" compatibility code will export these symbols later. 3789 * "export all symbols" compatibility code will export these symbols later.
3766 */ 3790 */
3767 use_ksymtab = obj_find_section(f, "__ksymtab") || !flag_export; 3791 use_ksymtab = obj_find_section(f, "__ksymtab") || flag_noexport;
3768 3792
3769 if ((sec = obj_find_section(f, ".this"))) { 3793 if ((sec = obj_find_section(f, ".this"))) {
3770 /* tag the module header with the object name, last modified 3794 /* tag the module header with the object name, last modified
@@ -3928,12 +3952,13 @@ static void print_load_map(struct obj_file *f)
3928 } 3952 }
3929#endif 3953#endif
3930} 3954}
3931 3955#else /* !CONFIG_FEATURE_INSMOD_LOAD_MAP */
3956void print_load_map(struct obj_file *f);
3932#endif 3957#endif
3933 3958
3934int insmod_main( int argc, char **argv) 3959int insmod_main( int argc, char **argv)
3935{ 3960{
3936 int opt; 3961 char *opt_o;
3937 int len; 3962 int len;
3938 int k_crcs; 3963 int k_crcs;
3939 char *tmp, *tmp1; 3964 char *tmp, *tmp1;
@@ -3954,60 +3979,15 @@ int insmod_main( int argc, char **argv)
3954#else 3979#else
3955 FILE *fp; 3980 FILE *fp;
3956#endif 3981#endif
3957#ifdef CONFIG_FEATURE_INSMOD_LOAD_MAP
3958 int flag_print_load_map = 0;
3959#endif
3960 int k_version = 0; 3982 int k_version = 0;
3961 struct utsname myuname; 3983 struct utsname myuname;
3962 3984
3963 /* Parse any options */ 3985 /* Parse any options */
3964#ifdef CONFIG_FEATURE_INSMOD_LOAD_MAP 3986 option_mask = bb_getopt_ulflags(argc, argv, OPTION_STR, &opt_o);
3965 while ((opt = getopt(argc, argv, "fkqsvxmLo:")) > 0) 3987 if (option_mask & OPT_o) { // -o /* name the output module */
3966#else 3988 free(m_name);
3967 while ((opt = getopt(argc, argv, "fkqsvxLo:")) > 0) 3989 m_name = xstrdup(opt_o);
3968#endif 3990 }
3969 {
3970 switch (opt) {
3971 case 'f': /* force loading */
3972 flag_force_load = 1;
3973 break;
3974 case 'k': /* module loaded by kerneld, auto-cleanable */
3975 flag_autoclean = 1;
3976 break;
3977 case 's': /* log to syslog */
3978 /* log to syslog -- not supported */
3979 /* but kernel needs this for request_module(), */
3980 /* as this calls: modprobe -k -s -- <module> */
3981 /* so silently ignore this flag */
3982 break;
3983 case 'v': /* verbose output */
3984 flag_verbose = 1;
3985 break;
3986 case 'q': /* silent */
3987 flag_quiet = 1;
3988 break;
3989 case 'x': /* do not export externs */
3990 flag_export = 0;
3991 break;
3992 case 'o': /* name the output module */
3993 free(m_name);
3994 m_name = xstrdup(optarg);
3995 break;
3996 case 'L': /* Stub warning */
3997 /* This is needed for compatibility with modprobe.
3998 * In theory, this does locking, but we don't do
3999 * that. So be careful and plan your life around not
4000 * loading the same module 50 times concurrently. */
4001 break;
4002#ifdef CONFIG_FEATURE_INSMOD_LOAD_MAP
4003 case 'm': /* print module load map */
4004 flag_print_load_map = 1;
4005 break;
4006#endif
4007 default:
4008 bb_show_usage();
4009 }
4010 }
4011 3991
4012 if (argv[optind] == NULL) { 3992 if (argv[optind] == NULL) {
4013 bb_show_usage(); 3993 bb_show_usage();
@@ -4248,10 +4228,8 @@ int insmod_main( int argc, char **argv)
4248 goto out; 4228 goto out;
4249 } 4229 }
4250 4230
4251#ifdef CONFIG_FEATURE_INSMOD_LOAD_MAP
4252 if(flag_print_load_map) 4231 if(flag_print_load_map)
4253 print_load_map(f); 4232 print_load_map(f);
4254#endif
4255 4233
4256 exit_status = EXIT_SUCCESS; 4234 exit_status = EXIT_SUCCESS;
4257 4235