aboutsummaryrefslogtreecommitdiff
path: root/applets
diff options
context:
space:
mode:
Diffstat (limited to 'applets')
-rw-r--r--applets/applets.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/applets/applets.c b/applets/applets.c
index 82a7eeea1..fb37fbea5 100644
--- a/applets/applets.c
+++ b/applets/applets.c
@@ -514,14 +514,14 @@ static void install_links(const char *busybox, int use_symbolic_links)
514 514
515 515
516/* If we were called as "busybox..." */ 516/* If we were called as "busybox..." */
517static int busybox_main(int argc, char **argv) 517static int busybox_main(char **argv)
518{ 518{
519 if (ENABLE_FEATURE_INSTALLER && argc > 1 && !strcmp(argv[1], "--install")) { 519 if (ENABLE_FEATURE_INSTALLER && argv[1] && !strcmp(argv[1], "--install")) {
520 int use_symbolic_links = 0; 520 int use_symbolic_links = 0;
521 char *busybox; 521 char *busybox;
522 522
523 /* to use symlinks, or not to use symlinks... */ 523 /* to use symlinks, or not to use symlinks... */
524 if (argc > 2) 524 if (argv[2])
525 if (strcmp(argv[2], "-s") == 0) 525 if (strcmp(argv[2], "-s") == 0)
526 use_symbolic_links = 1; 526 use_symbolic_links = 1;
527 527
@@ -537,11 +537,12 @@ static int busybox_main(int argc, char **argv)
537 537
538 /* Deal with --help. Also print help when called with no arguments */ 538 /* Deal with --help. Also print help when called with no arguments */
539 539
540 if (argc == 1 || !strcmp(argv[1], "--help") ) { 540 if (!argv[1] || !strcmp(argv[1], "--help") ) {
541 if (argc > 2) { 541 if (argv[2]) {
542 /* set name for proper "<name>: applet not found" */ 542 /* set name for proper "<name>: applet not found" */
543 applet_name = argv[2]; 543 applet_name = argv[2];
544 run_applet_and_exit(applet_name, 2, argv); 544 argv[2] = NULL;
545 run_applet_and_exit(applet_name, argv);
545 } else { 546 } else {
546 const struct bb_applet *a; 547 const struct bb_applet *a;
547 int col, output_width; 548 int col, output_width;
@@ -582,14 +583,19 @@ static int busybox_main(int argc, char **argv)
582 } else { 583 } else {
583 /* we want "<argv[1]>: applet not found", not "busybox: ..." */ 584 /* we want "<argv[1]>: applet not found", not "busybox: ..." */
584 applet_name = argv[1]; 585 applet_name = argv[1];
585 run_applet_and_exit(argv[1], argc - 1, argv + 1); 586 run_applet_and_exit(argv[1], argv + 1);
586 } 587 }
587 588
588 bb_error_msg_and_die("applet not found"); 589 bb_error_msg_and_die("applet not found");
589} 590}
590 591
591void run_current_applet_and_exit(int argc, char **argv) 592void run_current_applet_and_exit(char **argv)
592{ 593{
594 int argc = 1;
595
596 while (argv[argc])
597 argc++;
598
593 /* Reinit some shared global data */ 599 /* Reinit some shared global data */
594 optind = 1; 600 optind = 1;
595 xfunc_error_retval = EXIT_FAILURE; 601 xfunc_error_retval = EXIT_FAILURE;
@@ -602,13 +608,13 @@ void run_current_applet_and_exit(int argc, char **argv)
602 exit(current_applet->main(argc, argv)); 608 exit(current_applet->main(argc, argv));
603} 609}
604 610
605void run_applet_and_exit(const char *name, int argc, char **argv) 611void run_applet_and_exit(const char *name, char **argv)
606{ 612{
607 current_applet = find_applet_by_name(name); 613 current_applet = find_applet_by_name(name);
608 if (current_applet) 614 if (current_applet)
609 run_current_applet_and_exit(argc, argv); 615 run_current_applet_and_exit(argv);
610 if (!strncmp(name, "busybox", 7)) 616 if (!strncmp(name, "busybox", 7))
611 exit(busybox_main(argc, argv)); 617 exit(busybox_main(argv));
612} 618}
613 619
614 620
@@ -637,6 +643,6 @@ int main(int argc, char **argv)
637 if (ENABLE_LOCALE_SUPPORT && getpid() != 1) 643 if (ENABLE_LOCALE_SUPPORT && getpid() != 1)
638 setlocale(LC_ALL, ""); 644 setlocale(LC_ALL, "");
639 645
640 run_applet_and_exit(applet_name, argc, argv); 646 run_applet_and_exit(applet_name, argv);
641 bb_error_msg_and_die("applet not found"); 647 bb_error_msg_and_die("applet not found");
642} 648}