diff options
| author | vodz <vodz@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-02-02 14:48:54 +0000 |
|---|---|---|
| committer | vodz <vodz@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-02-02 14:48:54 +0000 |
| commit | 86513ecc5ea94b4e90ca4659722712044d074aa8 (patch) | |
| tree | 7f4e7befe49ad4dd9c488649cb04bc8aa10cd2fa | |
| parent | fe03e7d91035e34645b610d77b4b5c1c3ae3ca73 (diff) | |
| download | busybox-w32-86513ecc5ea94b4e90ca4659722712044d074aa8.tar.gz busybox-w32-86513ecc5ea94b4e90ca4659722712044d074aa8.tar.bz2 busybox-w32-86513ecc5ea94b4e90ca4659722712044d074aa8.zip | |
destroy bug 679, use getopt_ulflags with new feature: usage option. Removed two strdup
git-svn-id: svn://busybox.net/trunk/busybox@13797 69ca8d6d-28ef-0310-b511-8ec308f3f277
| -rw-r--r-- | libbb/getopt_ulflags.c | 10 | ||||
| -rw-r--r-- | modutils/modprobe.c | 93 |
2 files changed, 49 insertions, 54 deletions
diff --git a/libbb/getopt_ulflags.c b/libbb/getopt_ulflags.c index f18ee2d2d..3e77bbfea 100644 --- a/libbb/getopt_ulflags.c +++ b/libbb/getopt_ulflags.c | |||
| @@ -182,6 +182,10 @@ Special characters: | |||
| 182 | "-N" A dash as the first char in a bb_opt_complementally group with | 182 | "-N" A dash as the first char in a bb_opt_complementally group with |
| 183 | number 0-9 as one char is means check minimal arguments required. | 183 | number 0-9 as one char is means check minimal arguments required. |
| 184 | 184 | ||
| 185 | "V-" A option with dash before colon or end line indicate: call | ||
| 186 | bb_show_usage if this option give, for example verbose | ||
| 187 | usage option. | ||
| 188 | |||
| 185 | "--" A double dash between two options, or between an option and a group | 189 | "--" A double dash between two options, or between an option and a group |
| 186 | of options, means that they are mutually exclusive. Unlike | 190 | of options, means that they are mutually exclusive. Unlike |
| 187 | the "-" case above, an error will be forced if the options | 191 | the "-" case above, an error will be forced if the options |
| @@ -387,6 +391,12 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...) | |||
| 387 | requires |= on_off->switch_on; | 391 | requires |= on_off->switch_on; |
| 388 | continue; | 392 | continue; |
| 389 | } | 393 | } |
| 394 | if(c == '-' && (s[2] == ':' || s[2] == '\0')) { | ||
| 395 | flags |= on_off->switch_on; | ||
| 396 | on_off->incongruously |= on_off->switch_on; | ||
| 397 | s++; | ||
| 398 | continue; | ||
| 399 | } | ||
| 390 | if(c == *s) { | 400 | if(c == *s) { |
| 391 | on_off->counter = va_arg (p, int *); | 401 | on_off->counter = va_arg (p, int *); |
| 392 | s++; | 402 | s++; |
diff --git a/modutils/modprobe.c b/modutils/modprobe.c index 844eb99c5..d04c7ffff 100644 --- a/modutils/modprobe.c +++ b/modutils/modprobe.c | |||
| @@ -55,7 +55,30 @@ struct mod_list_t { /* two-way list of modules to process */ | |||
| 55 | 55 | ||
| 56 | 56 | ||
| 57 | static struct dep_t *depend; | 57 | static struct dep_t *depend; |
| 58 | static int autoclean, show_only, quiet, do_syslog, verbose; | 58 | |
| 59 | #define main_options "acdklnqrst:vVC:" | ||
| 60 | #define INSERT_ALL 1 /* a */ | ||
| 61 | #define DUMP_CONF_EXIT 2 /* c */ | ||
| 62 | #define D_OPT_IGNORED 4 /* d */ | ||
| 63 | #define AUTOCLEAN_FLG 8 /* k */ | ||
| 64 | #define LIST_ALL 16 /* l */ | ||
| 65 | #define SHOW_ONLY 32 /* n */ | ||
| 66 | #define QUIET 64 /* q */ | ||
| 67 | #define REMOVE_OPT 128 /* r */ | ||
| 68 | #define DO_SYSLOG 256 /* s */ | ||
| 69 | #define RESTRICT_DIR 512 /* t */ | ||
| 70 | #define VERBOSE 1024 /* v */ | ||
| 71 | #define VERSION_ONLY 2048 /* V */ | ||
| 72 | #define CONFIG_FILE 4096 /* C */ | ||
| 73 | |||
| 74 | #define autoclean (main_opts & AUTOCLEAN_FLG) | ||
| 75 | #define show_only (main_opts & SHOW_ONLY) | ||
| 76 | #define quiet (main_opts & QUIET) | ||
| 77 | #define remove_opt (main_opts & REMOVE_OPT) | ||
| 78 | #define do_syslog (main_opts & DO_SYSLOG) | ||
| 79 | #define verbose (main_opts & VERBOSE) | ||
| 80 | |||
| 81 | static int main_opts; | ||
| 59 | 82 | ||
| 60 | static int parse_tag_value ( char *buffer, char **ptag, char **pvalue ) | 83 | static int parse_tag_value ( char *buffer, char **ptag, char **pvalue ) |
| 61 | { | 84 | { |
| @@ -234,8 +257,8 @@ static char *parse_command_string( char *src, char **dst ) | |||
| 234 | if( opt_status & ( ARG_IN_DQUOTES | ARG_IN_SQUOTES ) ) { | 257 | if( opt_status & ( ARG_IN_DQUOTES | ARG_IN_SQUOTES ) ) { |
| 235 | bb_error_msg_and_die( "unterminated (single or double) quote in options list: %s", src ); | 258 | bb_error_msg_and_die( "unterminated (single or double) quote in options list: %s", src ); |
| 236 | } | 259 | } |
| 237 | *tmp_str = '\0'; | 260 | *tmp_str++ = '\0'; |
| 238 | *dst = xrealloc( *dst, strlen( *dst ) ); | 261 | *dst = xrealloc( *dst, (tmp_str - *dst ) ); |
| 239 | return src; | 262 | return src; |
| 240 | } | 263 | } |
| 241 | #else | 264 | #else |
| @@ -254,7 +277,7 @@ static struct dep_t *build_dep ( void ) | |||
| 254 | struct dep_t *first = 0; | 277 | struct dep_t *first = 0; |
| 255 | struct dep_t *current = 0; | 278 | struct dep_t *current = 0; |
| 256 | char buffer[2048]; | 279 | char buffer[2048]; |
| 257 | char *filename = buffer; | 280 | char *filename; |
| 258 | int continuation_line = 0; | 281 | int continuation_line = 0; |
| 259 | int k_version; | 282 | int k_version; |
| 260 | 283 | ||
| @@ -262,17 +285,11 @@ static struct dep_t *build_dep ( void ) | |||
| 262 | if ( uname ( &un )) | 285 | if ( uname ( &un )) |
| 263 | bb_error_msg_and_die("can't determine kernel version"); | 286 | bb_error_msg_and_die("can't determine kernel version"); |
| 264 | 287 | ||
| 265 | // check for buffer overflow in following code | ||
| 266 | if ( bb_strlen ( un.release ) > ( sizeof( buffer ) - 64 )) { | ||
| 267 | return 0; | ||
| 268 | } | ||
| 269 | if (un.release[0] == '2') { | 288 | if (un.release[0] == '2') { |
| 270 | k_version = un.release[2] - '0'; | 289 | k_version = un.release[2] - '0'; |
| 271 | } | 290 | } |
| 272 | 291 | ||
| 273 | strcpy ( filename, "/lib/modules/" ); | 292 | filename = bb_xasprintf("/lib/modules/%s/modules.dep", un.release ); |
| 274 | strcat ( filename, un.release ); | ||
| 275 | strcat ( filename, "/modules.dep" ); | ||
| 276 | 293 | ||
| 277 | if (( fd = open ( filename, O_RDONLY )) < 0 ) { | 294 | if (( fd = open ( filename, O_RDONLY )) < 0 ) { |
| 278 | 295 | ||
| @@ -281,12 +298,13 @@ static struct dep_t *build_dep ( void ) | |||
| 281 | return 0; | 298 | return 0; |
| 282 | } | 299 | } |
| 283 | } | 300 | } |
| 301 | free(filename); | ||
| 284 | 302 | ||
| 285 | while ( reads ( fd, buffer, sizeof( buffer ))) { | 303 | while ( reads ( fd, buffer, sizeof( buffer ))) { |
| 286 | int l = bb_strlen ( buffer ); | 304 | int l = bb_strlen ( buffer ); |
| 287 | char *p = 0; | 305 | char *p = 0; |
| 288 | 306 | ||
| 289 | while ( isspace ( buffer [l-1] )) { | 307 | while ( l > 0 && isspace ( buffer [l-1] )) { |
| 290 | buffer [l-1] = 0; | 308 | buffer [l-1] = 0; |
| 291 | l--; | 309 | l--; |
| 292 | } | 310 | } |
| @@ -787,7 +805,7 @@ static int mod_insert ( char *mod, int argc, char **argv ) | |||
| 787 | static int mod_remove ( char *mod ) | 805 | static int mod_remove ( char *mod ) |
| 788 | { | 806 | { |
| 789 | int rc; | 807 | int rc; |
| 790 | static struct mod_list_t rm_a_dummy = { "-a", 0, 0 }; | 808 | static struct mod_list_t rm_a_dummy = { "-a", NULL, NULL, NULL, NULL }; |
| 791 | 809 | ||
| 792 | struct mod_list_t *head = 0; | 810 | struct mod_list_t *head = 0; |
| 793 | struct mod_list_t *tail = 0; | 811 | struct mod_list_t *tail = 0; |
| @@ -807,50 +825,17 @@ static int mod_remove ( char *mod ) | |||
| 807 | 825 | ||
| 808 | extern int modprobe_main(int argc, char** argv) | 826 | extern int modprobe_main(int argc, char** argv) |
| 809 | { | 827 | { |
| 810 | int opt; | ||
| 811 | int rc = EXIT_SUCCESS; | 828 | int rc = EXIT_SUCCESS; |
| 812 | int remove_opt = 0; | 829 | char *unused; |
| 813 | 830 | ||
| 814 | autoclean = show_only = quiet = do_syslog = verbose = 0; | 831 | bb_opt_complementally = "?V-:q-v:v-q"; |
| 815 | 832 | main_opts = bb_getopt_ulflags(argc, argv, "acdklnqrst:vVC:", | |
| 816 | while ((opt = getopt(argc, argv, "acdklnqrst:vVC:")) != -1) { | 833 | &unused, &unused); |
| 817 | switch(opt) { | 834 | if((main_opts & (DUMP_CONF_EXIT | LIST_ALL))) |
| 818 | case 'c': // no config used | ||
| 819 | case 'l': // no pattern matching | ||
| 820 | return EXIT_SUCCESS; | 835 | return EXIT_SUCCESS; |
| 821 | break; | 836 | if((main_opts & (RESTRICT_DIR | CONFIG_FILE))) |
| 822 | case 'C': // no config used | ||
| 823 | case 't': // no pattern matching | ||
| 824 | bb_error_msg_and_die("-t and -C not supported"); | 837 | bb_error_msg_and_die("-t and -C not supported"); |
| 825 | 838 | ||
| 826 | case 'a': // ignore | ||
| 827 | case 'd': // ignore | ||
| 828 | break; | ||
| 829 | case 'k': | ||
| 830 | autoclean++; | ||
| 831 | break; | ||
| 832 | case 'n': | ||
| 833 | show_only++; | ||
| 834 | break; | ||
| 835 | case 'q': | ||
| 836 | quiet++; verbose=0; | ||
| 837 | break; | ||
| 838 | case 'r': | ||
| 839 | remove_opt++; | ||
| 840 | break; | ||
| 841 | case 's': | ||
| 842 | do_syslog++; | ||
| 843 | break; | ||
| 844 | case 'v': | ||
| 845 | verbose++; quiet=0; | ||
| 846 | break; | ||
| 847 | case 'V': | ||
| 848 | default: | ||
| 849 | bb_show_usage(); | ||
| 850 | break; | ||
| 851 | } | ||
| 852 | } | ||
| 853 | |||
| 854 | depend = build_dep ( ); | 839 | depend = build_dep ( ); |
| 855 | 840 | ||
| 856 | if ( !depend ) | 841 | if ( !depend ) |
| @@ -859,7 +844,7 @@ extern int modprobe_main(int argc, char** argv) | |||
| 859 | if (remove_opt) { | 844 | if (remove_opt) { |
| 860 | do { | 845 | do { |
| 861 | if (mod_remove ( optind < argc ? | 846 | if (mod_remove ( optind < argc ? |
| 862 | bb_xstrdup (argv [optind]) : NULL )) { | 847 | argv [optind] : NULL )) { |
| 863 | bb_error_msg ("failed to remove module %s", | 848 | bb_error_msg ("failed to remove module %s", |
| 864 | argv [optind] ); | 849 | argv [optind] ); |
| 865 | rc = EXIT_FAILURE; | 850 | rc = EXIT_FAILURE; |
| @@ -869,7 +854,7 @@ extern int modprobe_main(int argc, char** argv) | |||
| 869 | if (optind >= argc) | 854 | if (optind >= argc) |
| 870 | bb_error_msg_and_die ( "No module or pattern provided\n" ); | 855 | bb_error_msg_and_die ( "No module or pattern provided\n" ); |
| 871 | 856 | ||
| 872 | if ( mod_insert ( bb_xstrdup ( argv [optind] ), argc - optind - 1, argv + optind + 1 )) | 857 | if ( mod_insert ( argv [optind], argc - optind - 1, argv + optind + 1 )) |
| 873 | bb_error_msg_and_die ( "failed to load module %s", argv [optind] ); | 858 | bb_error_msg_and_die ( "failed to load module %s", argv [optind] ); |
| 874 | } | 859 | } |
| 875 | 860 | ||
