diff options
author | Denis Vlasenko | 2007-04-09 03:11:58 +0000 |
---|---|---|
committer | Denis Vlasenko | 2007-04-09 03:11:58 +0000 |
commit | c44ab01b75aba758fe0aff4b34b25d733e370dc2 (patch) | |
tree | 7aaff270868ae6e6ff78fb5c42d42f5645a6a67a /applets/applets.c | |
parent | 95cb3263ae8f9afda0f6af3f777739506a0dfc62 (diff) | |
download | busybox-c44ab01b75aba758fe0aff4b34b25d733e370dc2.zip busybox-c44ab01b75aba758fe0aff4b34b25d733e370dc2.tar.gz |
Improve STANDALONE_SHELL. "safe" applets are renamed NOEXEC applets
and now this fact is recorded in applets.h, not ash.c.
Several fixes to "--help + STANDALONE_SHELL" scenarios.
function old new delta
run_current_applet_and_exit - 355 +355
arith 2064 2073 +9
refresh 1148 1156 +8
getopt32 1068 1073 +5
telnet_main 1510 1514 +4
md5_sha1_sum_main 565 566 +1
xstrtoul_range_sfx 255 251 -4
packed_usage 22523 22514 -9
tryexec 255 203 -52
static.safe_applets 152 - -152
.rodata 131320 131128 -192
run_applet_by_name 869 506 -363
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 5/5 up/down: 382/-772) Total: -390 bytes
./busybox ash -c 'i=20000; while test $i != 0; do touch z; i=$((i-1)); done'
runs more than twice as fast with STANDALONE_SHELL versus without.
Diffstat (limited to 'applets/applets.c')
-rw-r--r-- | applets/applets.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/applets/applets.c b/applets/applets.c index 8acfd95..c8e85cd 100644 --- a/applets/applets.c +++ b/applets/applets.c @@ -49,7 +49,7 @@ static const char usage_messages[] = const unsigned short NUM_APPLETS = sizeof(applets) / sizeof(struct BB_applet) - 1; -static struct BB_applet *current_applet; +const struct BB_applet *current_applet; const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE; #ifdef BB_NOMMU smallint re_execed; @@ -60,14 +60,11 @@ smallint re_execed; #if ENABLE_FEATURE_SUID_CONFIG /* applets[] is const, so we have to define this "override" structure */ -static struct BB_suid_config -{ - struct BB_applet *m_applet; - +static struct BB_suid_config { + const struct BB_applet *m_applet; uid_t m_uid; gid_t m_gid; mode_t m_mode; - struct BB_suid_config *m_next; } *suid_config; @@ -133,7 +130,7 @@ static void parse_config_file(void) { struct BB_suid_config *sct_head; struct BB_suid_config *sct; - struct BB_applet *applet; + const struct BB_applet *applet; FILE *f; const char *errmsg; char *s; @@ -330,7 +327,7 @@ static void parse_config_file(void) #if ENABLE_FEATURE_SUID -static void check_suid(struct BB_applet *applet) +static void check_suid(const struct BB_applet *applet) { uid_t ruid = getuid(); /* real [ug]id */ uid_t rgid = getgid(); @@ -476,7 +473,7 @@ static int applet_name_compare(const void *name, const void *vapplet) return strcmp(name, applet->name); } -struct BB_applet *find_applet_by_name(const char *name) +const struct BB_applet *find_applet_by_name(const char *name) { /* Do a binary search to find the applet entry given the name. */ return bsearch(name, applets, NUM_APPLETS, sizeof(struct BB_applet), @@ -599,17 +596,21 @@ static int busybox_main(int argc, char **argv) bb_error_msg_and_die("applet not found"); } +void run_current_applet_and_exit(int argc, char **argv) +{ + applet_name = current_applet->name; + if (argc == 2 && !strcmp(argv[1], "--help")) + bb_show_usage(); + if (ENABLE_FEATURE_SUID) + check_suid(current_applet); + exit(current_applet->main(argc, argv)); +} + void run_applet_by_name(const char *name, int argc, char **argv) { current_applet = find_applet_by_name(name); - if (current_applet) { - applet_name = current_applet->name; - if (argc == 2 && !strcmp(argv[1], "--help")) - bb_show_usage(); - if (ENABLE_FEATURE_SUID) - check_suid(current_applet); - exit(current_applet->main(argc, argv)); - } + if (current_applet) + run_current_applet_and_exit(argc, argv); if (!strncmp(name, "busybox", 7)) exit(busybox_main(argc, argv)); } |