aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-10-10 14:38:47 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-10-10 14:38:47 +0000
commit82d38dab917754c9c37aaa7e414a47318b5082fe (patch)
treeea00ffed0879edb0f2dce87953d6f9c5908a18bf
parent141750e38897900db98eaeab1ea35c18f5794023 (diff)
downloadbusybox-w32-82d38dab917754c9c37aaa7e414a47318b5082fe.tar.gz
busybox-w32-82d38dab917754c9c37aaa7e414a47318b5082fe.tar.bz2
busybox-w32-82d38dab917754c9c37aaa7e414a47318b5082fe.zip
get rid of global "struct bb_applet *current_applet"
-rw-r--r--applets/applets.c15
-rw-r--r--docs/busybox.net/FAQ.html2
-rw-r--r--include/libbb.h5
-rw-r--r--libbb/appletlib.c5
-rw-r--r--libbb/vfork_daemon_rexec.c10
-rw-r--r--shell/ash.c6
-rw-r--r--shell/hush.c5
7 files changed, 21 insertions, 27 deletions
diff --git a/applets/applets.c b/applets/applets.c
index 55f8e6b23..3b4f395c9 100644
--- a/applets/applets.c
+++ b/applets/applets.c
@@ -28,7 +28,6 @@
28#endif 28#endif
29 29
30 30
31const struct bb_applet *current_applet;
32const char *applet_name; 31const char *applet_name;
33#if !BB_MMU 32#if !BB_MMU
34bool re_execed; 33bool re_execed;
@@ -507,7 +506,7 @@ static int busybox_main(char **argv)
507 bb_error_msg_and_die("applet not found"); 506 bb_error_msg_and_die("applet not found");
508} 507}
509 508
510void run_current_applet_and_exit(char **argv) 509void run_appletstruct_and_exit(const struct bb_applet *applet, char **argv)
511{ 510{
512 int argc = 1; 511 int argc = 1;
513 512
@@ -518,19 +517,19 @@ void run_current_applet_and_exit(char **argv)
518 optind = 1; 517 optind = 1;
519 xfunc_error_retval = EXIT_FAILURE; 518 xfunc_error_retval = EXIT_FAILURE;
520 519
521 applet_name = current_applet->name; 520 applet_name = applet->name;
522 if (argc == 2 && !strcmp(argv[1], "--help")) 521 if (argc == 2 && !strcmp(argv[1], "--help"))
523 bb_show_usage(); 522 bb_show_usage();
524 if (ENABLE_FEATURE_SUID) 523 if (ENABLE_FEATURE_SUID)
525 check_suid(current_applet); 524 check_suid(applet);
526 exit(current_applet->main(argc, argv)); 525 exit(applet->main(argc, argv));
527} 526}
528 527
529void run_applet_and_exit(const char *name, char **argv) 528void run_applet_and_exit(const char *name, char **argv)
530{ 529{
531 current_applet = find_applet_by_name(name); 530 const struct bb_applet *applet = find_applet_by_name(name);
532 if (current_applet) 531 if (applet)
533 run_current_applet_and_exit(argv); 532 run_appletstruct_and_exit(applet, argv);
534 if (!strncmp(name, "busybox", 7)) 533 if (!strncmp(name, "busybox", 7))
535 exit(busybox_main(argv)); 534 exit(busybox_main(argv));
536} 535}
diff --git a/docs/busybox.net/FAQ.html b/docs/busybox.net/FAQ.html
index 7b15bf78c..e0a759781 100644
--- a/docs/busybox.net/FAQ.html
+++ b/docs/busybox.net/FAQ.html
@@ -568,7 +568,7 @@ functionality: main() looks up argv[0] in applets[] to get a function pointer
568to APPLET_main().</p> 568to APPLET_main().</p>
569 569
570<p>Busybox applets may also be invoked through the multiplexor applet 570<p>Busybox applets may also be invoked through the multiplexor applet
571"busybox" (see busybox_main() in applets/busybox.c), and through the 571"busybox" (see busybox_main() in libbb/appletlib.c), and through the
572standalone shell (grep for STANDALONE_SHELL in applets/shell/*.c). 572standalone shell (grep for STANDALONE_SHELL in applets/shell/*.c).
573See <a href="FAQ.html#getting_started">getting started</a> in the 573See <a href="FAQ.html#getting_started">getting started</a> in the
574FAQ for more information on these alternate usage mechanisms, which are 574FAQ for more information on these alternate usage mechanisms, which are
diff --git a/include/libbb.h b/include/libbb.h
index d76571b58..9d8b5f3df 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -564,7 +564,7 @@ int wait_nohang(int *wstat);
564int spawn_and_wait(char **argv); 564int spawn_and_wait(char **argv);
565struct nofork_save_area { 565struct nofork_save_area {
566 jmp_buf die_jmp; 566 jmp_buf die_jmp;
567 const struct bb_applet *current_applet; 567 const char *applet_name;
568 int xfunc_error_retval; 568 int xfunc_error_retval;
569 uint32_t option_mask32; 569 uint32_t option_mask32;
570 int die_sleep; 570 int die_sleep;
@@ -748,7 +748,7 @@ const struct hwtype *get_hwntype(int type);
748extern const struct bb_applet *find_applet_by_name(const char *name); 748extern const struct bb_applet *find_applet_by_name(const char *name);
749/* Returns only if applet is not found. */ 749/* Returns only if applet is not found. */
750extern void run_applet_and_exit(const char *name, char **argv); 750extern void run_applet_and_exit(const char *name, char **argv);
751extern void run_current_applet_and_exit(char **argv) ATTRIBUTE_NORETURN; 751extern void run_appletstruct_and_exit(const struct bb_applet *a, char **argv) ATTRIBUTE_NORETURN;
752#endif 752#endif
753 753
754extern int match_fstype(const struct mntent *mt, const char *fstypes); 754extern int match_fstype(const struct mntent *mt, const char *fstypes);
@@ -1040,7 +1040,6 @@ enum { /* DO NOT CHANGE THESE VALUES! cp.c, mv.c, install.c depend on them. */
1040}; 1040};
1041 1041
1042#define FILEUTILS_CP_OPTSTR "pdRfils" USE_SELINUX("c") 1042#define FILEUTILS_CP_OPTSTR "pdRfils" USE_SELINUX("c")
1043extern const struct bb_applet *current_applet;
1044extern const char *applet_name; 1043extern const char *applet_name;
1045/* "BusyBox vN.N.N (timestamp or extra_vestion)" */ 1044/* "BusyBox vN.N.N (timestamp or extra_vestion)" */
1046extern const char bb_banner[]; 1045extern const char bb_banner[];
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 565dacf36..cfa60a940 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -133,7 +133,10 @@ void bbox_prepare_main(char **argv)
133 if (ENABLE_LOCALE_SUPPORT && getpid() != 1) 133 if (ENABLE_LOCALE_SUPPORT && getpid() != 1)
134 setlocale(LC_ALL, ""); 134 setlocale(LC_ALL, "");
135 135
136 /* Redundant for busybox, but needed for individual applets */ 136#if ENABLE_FEATURE_INDIVIDUAL
137 /* Redundant for busybox (run_applet_and_exit covers that case)
138 * but needed for "individual applet" mode */
137 if (argv[1] && strcmp(argv[1], "--help") == 0) 139 if (argv[1] && strcmp(argv[1], "--help") == 0)
138 bb_show_usage(); 140 bb_show_usage();
141#endif
139} 142}
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index 80c72f165..a01065d69 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -104,7 +104,7 @@ int wait_pid(int *wstat, int pid)
104void save_nofork_data(struct nofork_save_area *save) 104void save_nofork_data(struct nofork_save_area *save)
105{ 105{
106 memcpy(&save->die_jmp, &die_jmp, sizeof(die_jmp)); 106 memcpy(&save->die_jmp, &die_jmp, sizeof(die_jmp));
107 save->current_applet = current_applet; 107 save->applet_name = applet_name;
108 save->xfunc_error_retval = xfunc_error_retval; 108 save->xfunc_error_retval = xfunc_error_retval;
109 save->option_mask32 = option_mask32; 109 save->option_mask32 = option_mask32;
110 save->die_sleep = die_sleep; 110 save->die_sleep = die_sleep;
@@ -114,19 +114,16 @@ void save_nofork_data(struct nofork_save_area *save)
114void restore_nofork_data(struct nofork_save_area *save) 114void restore_nofork_data(struct nofork_save_area *save)
115{ 115{
116 memcpy(&die_jmp, &save->die_jmp, sizeof(die_jmp)); 116 memcpy(&die_jmp, &save->die_jmp, sizeof(die_jmp));
117 current_applet = save->current_applet; 117 applet_name = save->applet_name;
118 xfunc_error_retval = save->xfunc_error_retval; 118 xfunc_error_retval = save->xfunc_error_retval;
119 option_mask32 = save->option_mask32; 119 option_mask32 = save->option_mask32;
120 die_sleep = save->die_sleep; 120 die_sleep = save->die_sleep;
121
122 applet_name = current_applet->name;
123} 121}
124 122
125int run_nofork_applet_prime(struct nofork_save_area *old, const struct bb_applet *a, char **argv) 123int run_nofork_applet_prime(struct nofork_save_area *old, const struct bb_applet *a, char **argv)
126{ 124{
127 int rc, argc; 125 int rc, argc;
128 126
129 current_applet = a;
130 applet_name = a->name; 127 applet_name = a->name;
131 xfunc_error_retval = EXIT_FAILURE; 128 xfunc_error_retval = EXIT_FAILURE;
132 /*option_mask32 = 0; - not needed */ 129 /*option_mask32 = 0; - not needed */
@@ -193,8 +190,7 @@ int spawn_and_wait(char **argv)
193 return wait4pid(rc); 190 return wait4pid(rc);
194 /* child */ 191 /* child */
195 xfunc_error_retval = EXIT_FAILURE; 192 xfunc_error_retval = EXIT_FAILURE;
196 current_applet = a; 193 run_appletstruct_and_exit(a, argv);
197 run_current_applet_and_exit(argv);
198#endif 194#endif
199 } 195 }
200#endif /* FEATURE_PREFER_APPLETS */ 196#endif /* FEATURE_PREFER_APPLETS */
diff --git a/shell/ash.c b/shell/ash.c
index 8b21e655c..af96c4d1d 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -6470,10 +6470,8 @@ tryexec(char *cmd, char **argv, char **envp)
6470 6470
6471 a = find_applet_by_name(cmd); 6471 a = find_applet_by_name(cmd);
6472 if (a) { 6472 if (a) {
6473 if (a->noexec) { 6473 if (a->noexec)
6474 current_applet = a; 6474 run_appletstruct_and_exit(a, argv);
6475 run_current_applet_and_exit(argv);
6476 }
6477 /* re-exec ourselves with the new arguments */ 6475 /* re-exec ourselves with the new arguments */
6478 execve(bb_busybox_exec_path, argv, envp); 6476 execve(bb_busybox_exec_path, argv, envp);
6479 /* If they called chroot or otherwise made the binary no longer 6477 /* If they called chroot or otherwise made the binary no longer
diff --git a/shell/hush.c b/shell/hush.c
index 90ed15547..1977da0f0 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -1399,10 +1399,9 @@ static void pseudo_exec_argv(char **argv)
1399 const struct bb_applet *a = find_applet_by_name(argv[0]); 1399 const struct bb_applet *a = find_applet_by_name(argv[0]);
1400 if (a) { 1400 if (a) {
1401 if (a->noexec) { 1401 if (a->noexec) {
1402 current_applet = a;
1403 debug_printf_exec("running applet '%s'\n", argv[0]); 1402 debug_printf_exec("running applet '%s'\n", argv[0]);
1404// is it ok that run_current_applet_and_exit() does exit(), not _exit()? 1403// is it ok that run_appletstruct_and_exit() does exit(), not _exit()?
1405 run_current_applet_and_exit(argv); 1404 run_appletstruct_and_exit(a, argv);
1406 } 1405 }
1407 /* re-exec ourselves with the new arguments */ 1406 /* re-exec ourselves with the new arguments */
1408 debug_printf_exec("re-execing applet '%s'\n", argv[0]); 1407 debug_printf_exec("re-execing applet '%s'\n", argv[0]);