aboutsummaryrefslogtreecommitdiff
path: root/applets
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-04-09 03:11:58 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-04-09 03:11:58 +0000
commit829bc8ff46527231a59862553c65a5457ed8bec9 (patch)
tree7aaff270868ae6e6ff78fb5c42d42f5645a6a67a /applets
parent20459e98ef1f0a16f34c1b9287390209dbb1f9eb (diff)
downloadbusybox-w32-829bc8ff46527231a59862553c65a5457ed8bec9.tar.gz
busybox-w32-829bc8ff46527231a59862553c65a5457ed8bec9.tar.bz2
busybox-w32-829bc8ff46527231a59862553c65a5457ed8bec9.zip
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. git-svn-id: svn://busybox.net/trunk/busybox@18370 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'applets')
-rw-r--r--applets/applets.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/applets/applets.c b/applets/applets.c
index 8acfd95a9..c8e85cdb1 100644
--- a/applets/applets.c
+++ b/applets/applets.c
@@ -49,7 +49,7 @@ static const char usage_messages[] =
49const unsigned short NUM_APPLETS = sizeof(applets) / sizeof(struct BB_applet) - 1; 49const unsigned short NUM_APPLETS = sizeof(applets) / sizeof(struct BB_applet) - 1;
50 50
51 51
52static struct BB_applet *current_applet; 52const struct BB_applet *current_applet;
53const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE; 53const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE;
54#ifdef BB_NOMMU 54#ifdef BB_NOMMU
55smallint re_execed; 55smallint re_execed;
@@ -60,14 +60,11 @@ smallint re_execed;
60#if ENABLE_FEATURE_SUID_CONFIG 60#if ENABLE_FEATURE_SUID_CONFIG
61 61
62/* applets[] is const, so we have to define this "override" structure */ 62/* applets[] is const, so we have to define this "override" structure */
63static struct BB_suid_config 63static struct BB_suid_config {
64{ 64 const struct BB_applet *m_applet;
65 struct BB_applet *m_applet;
66
67 uid_t m_uid; 65 uid_t m_uid;
68 gid_t m_gid; 66 gid_t m_gid;
69 mode_t m_mode; 67 mode_t m_mode;
70
71 struct BB_suid_config *m_next; 68 struct BB_suid_config *m_next;
72} *suid_config; 69} *suid_config;
73 70
@@ -133,7 +130,7 @@ static void parse_config_file(void)
133{ 130{
134 struct BB_suid_config *sct_head; 131 struct BB_suid_config *sct_head;
135 struct BB_suid_config *sct; 132 struct BB_suid_config *sct;
136 struct BB_applet *applet; 133 const struct BB_applet *applet;
137 FILE *f; 134 FILE *f;
138 const char *errmsg; 135 const char *errmsg;
139 char *s; 136 char *s;
@@ -330,7 +327,7 @@ static void parse_config_file(void)
330 327
331 328
332#if ENABLE_FEATURE_SUID 329#if ENABLE_FEATURE_SUID
333static void check_suid(struct BB_applet *applet) 330static void check_suid(const struct BB_applet *applet)
334{ 331{
335 uid_t ruid = getuid(); /* real [ug]id */ 332 uid_t ruid = getuid(); /* real [ug]id */
336 uid_t rgid = getgid(); 333 uid_t rgid = getgid();
@@ -476,7 +473,7 @@ static int applet_name_compare(const void *name, const void *vapplet)
476 return strcmp(name, applet->name); 473 return strcmp(name, applet->name);
477} 474}
478 475
479struct BB_applet *find_applet_by_name(const char *name) 476const struct BB_applet *find_applet_by_name(const char *name)
480{ 477{
481 /* Do a binary search to find the applet entry given the name. */ 478 /* Do a binary search to find the applet entry given the name. */
482 return bsearch(name, applets, NUM_APPLETS, sizeof(struct BB_applet), 479 return bsearch(name, applets, NUM_APPLETS, sizeof(struct BB_applet),
@@ -599,17 +596,21 @@ static int busybox_main(int argc, char **argv)
599 bb_error_msg_and_die("applet not found"); 596 bb_error_msg_and_die("applet not found");
600} 597}
601 598
599void run_current_applet_and_exit(int argc, char **argv)
600{
601 applet_name = current_applet->name;
602 if (argc == 2 && !strcmp(argv[1], "--help"))
603 bb_show_usage();
604 if (ENABLE_FEATURE_SUID)
605 check_suid(current_applet);
606 exit(current_applet->main(argc, argv));
607}
608
602void run_applet_by_name(const char *name, int argc, char **argv) 609void run_applet_by_name(const char *name, int argc, char **argv)
603{ 610{
604 current_applet = find_applet_by_name(name); 611 current_applet = find_applet_by_name(name);
605 if (current_applet) { 612 if (current_applet)
606 applet_name = current_applet->name; 613 run_current_applet_and_exit(argc, argv);
607 if (argc == 2 && !strcmp(argv[1], "--help"))
608 bb_show_usage();
609 if (ENABLE_FEATURE_SUID)
610 check_suid(current_applet);
611 exit(current_applet->main(argc, argv));
612 }
613 if (!strncmp(name, "busybox", 7)) 614 if (!strncmp(name, "busybox", 7))
614 exit(busybox_main(argc, argv)); 615 exit(busybox_main(argc, argv));
615} 616}