diff options
author | Eric Andersen <andersen@codepoet.org> | 2000-11-17 18:25:26 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2000-11-17 18:25:26 +0000 |
commit | e5aef92e22172d36152bae6e15d5c0419c758121 (patch) | |
tree | 1576263a85553b8bd1b3efd08a53b5c2898efb8b | |
parent | cf32e23796a94e96d36d302973509935ea051816 (diff) | |
download | busybox-w32-e5aef92e22172d36152bae6e15d5c0419c758121.tar.gz busybox-w32-e5aef92e22172d36152bae6e15d5c0419c758121.tar.bz2 busybox-w32-e5aef92e22172d36152bae6e15d5c0419c758121.zip |
Fix up builtin overrides, and hack in the binary search for finding
matching applets into the shell.
-rw-r--r-- | Config.h | 10 | ||||
-rw-r--r-- | applets/busybox.c | 8 | ||||
-rw-r--r-- | busybox.c | 8 | ||||
-rw-r--r-- | busybox.h | 2 | ||||
-rw-r--r-- | include/busybox.h | 2 | ||||
-rw-r--r-- | lash.c | 60 | ||||
-rw-r--r-- | sh.c | 60 | ||||
-rw-r--r-- | shell/lash.c | 60 | ||||
-rw-r--r-- | utility.c | 8 |
9 files changed, 113 insertions, 105 deletions
@@ -235,11 +235,11 @@ | |||
235 | #define BB_FEATURE_SH_STANDALONE_SHELL | 235 | #define BB_FEATURE_SH_STANDALONE_SHELL |
236 | // | 236 | // |
237 | //When this is enabled, busybox shell builtins can be called using full path | 237 | //When this is enabled, busybox shell builtins can be called using full path |
238 | //names. This causes builtins (which includes every single busybox command | 238 | //names. This causes builtins (i.e. every single busybox command) to override |
239 | //when you enable BB_FEATURE_SH_STANDALONE_SHELL) to override real commands on | 239 | //real commands on the filesystem. For example, if you run run /bin/cat, it |
240 | //the filesystem. When this is enabled, if you run /bin/cat, it will use | 240 | //will use BusyBox cat even if /bin/cat exists on the filesystem and is _not_ |
241 | //BusyBox cat even if /bin/cat exists on the filesystem and is _not_ busybox. | 241 | //busybox. Some systems want this, others do not. Choose wisely. :-) This |
242 | //Some systems want this, others do not. Choose wisely. :-) | 242 | //only has meaning when BB_FEATURE_SH_STANDALONE_SHELL is enabled. |
243 | //BB_FEATURE_SH_BUILTINS_ALWAYS_WIN | 243 | //BB_FEATURE_SH_BUILTINS_ALWAYS_WIN |
244 | // | 244 | // |
245 | // Enable tab completion in the shell (not yet | 245 | // Enable tab completion in the shell (not yet |
diff --git a/applets/busybox.c b/applets/busybox.c index d356e4cae..0a3333d99 100644 --- a/applets/busybox.c +++ b/applets/busybox.c | |||
@@ -81,14 +81,6 @@ static void install_links(const char *busybox, int use_symbolic_links) | |||
81 | 81 | ||
82 | #endif /* BB_FEATURE_INSTALLER */ | 82 | #endif /* BB_FEATURE_INSTALLER */ |
83 | 83 | ||
84 | static int applet_name_compare(const void *x, const void *y) | ||
85 | { | ||
86 | const struct BB_applet *applet1 = x; | ||
87 | const struct BB_applet *applet2 = y; | ||
88 | |||
89 | return strcmp(applet1->name, applet2->name); | ||
90 | } | ||
91 | |||
92 | int main(int argc, char **argv) | 84 | int main(int argc, char **argv) |
93 | { | 85 | { |
94 | struct BB_applet search_applet, *applet; | 86 | struct BB_applet search_applet, *applet; |
@@ -81,14 +81,6 @@ static void install_links(const char *busybox, int use_symbolic_links) | |||
81 | 81 | ||
82 | #endif /* BB_FEATURE_INSTALLER */ | 82 | #endif /* BB_FEATURE_INSTALLER */ |
83 | 83 | ||
84 | static int applet_name_compare(const void *x, const void *y) | ||
85 | { | ||
86 | const struct BB_applet *applet1 = x; | ||
87 | const struct BB_applet *applet2 = y; | ||
88 | |||
89 | return strcmp(applet1->name, applet2->name); | ||
90 | } | ||
91 | |||
92 | int main(int argc, char **argv) | 84 | int main(int argc, char **argv) |
93 | { | 85 | { |
94 | struct BB_applet search_applet, *applet; | 86 | struct BB_applet search_applet, *applet; |
@@ -108,6 +108,8 @@ struct BB_applet { | |||
108 | /* From busybox.c */ | 108 | /* From busybox.c */ |
109 | extern const struct BB_applet applets[]; | 109 | extern const struct BB_applet applets[]; |
110 | 110 | ||
111 | extern int applet_name_compare(const void *x, const void *y); | ||
112 | |||
111 | extern int ar_main(int argc, char **argv); | 113 | extern int ar_main(int argc, char **argv); |
112 | extern int basename_main(int argc, char **argv); | 114 | extern int basename_main(int argc, char **argv); |
113 | extern int bogomips_main(int argc, char **argv); | 115 | extern int bogomips_main(int argc, char **argv); |
diff --git a/include/busybox.h b/include/busybox.h index d947ba328..2bc1c997e 100644 --- a/include/busybox.h +++ b/include/busybox.h | |||
@@ -108,6 +108,8 @@ struct BB_applet { | |||
108 | /* From busybox.c */ | 108 | /* From busybox.c */ |
109 | extern const struct BB_applet applets[]; | 109 | extern const struct BB_applet applets[]; |
110 | 110 | ||
111 | extern int applet_name_compare(const void *x, const void *y); | ||
112 | |||
111 | extern int ar_main(int argc, char **argv); | 113 | extern int ar_main(int argc, char **argv); |
112 | extern int basename_main(int argc, char **argv); | 114 | extern int basename_main(int argc, char **argv); |
113 | extern int bogomips_main(int argc, char **argv); | 115 | extern int bogomips_main(int argc, char **argv); |
@@ -1152,7 +1152,7 @@ static int runCommand(struct job *newJob, struct jobSet *jobList, int inBg, int | |||
1152 | int pipefds[2]; /* pipefd[0] is for reading */ | 1152 | int pipefds[2]; /* pipefd[0] is for reading */ |
1153 | struct builtInCommand *x; | 1153 | struct builtInCommand *x; |
1154 | #ifdef BB_FEATURE_SH_STANDALONE_SHELL | 1154 | #ifdef BB_FEATURE_SH_STANDALONE_SHELL |
1155 | const struct BB_applet *a = applets; | 1155 | struct BB_applet search_applet, *applet = applets; |
1156 | #endif | 1156 | #endif |
1157 | 1157 | ||
1158 | nextin = 0, nextout = 1; | 1158 | nextin = 0, nextout = 1; |
@@ -1214,40 +1214,44 @@ static int runCommand(struct job *newJob, struct jobSet *jobList, int inBg, int | |||
1214 | } | 1214 | } |
1215 | } | 1215 | } |
1216 | #ifdef BB_FEATURE_SH_STANDALONE_SHELL | 1216 | #ifdef BB_FEATURE_SH_STANDALONE_SHELL |
1217 | /* Check if the command matches any busybox internal commands here */ | 1217 | /* Check if the command matches any busybox internal |
1218 | while (a->name != 0) { | 1218 | * commands ("applets") here. Following discussions from |
1219 | * November 2000 on busybox@opensource.lineo.com, don't use | ||
1220 | * get_last_path_component(). This way explicit (with | ||
1221 | * slashes) filenames will never be interpreted as an | ||
1222 | * applet, just like with builtins. This way the user can | ||
1223 | * override an applet with an explicit filename reference. | ||
1224 | * The only downside to this change is that an explicit | ||
1225 | * /bin/foo invocation fill fork and exec /bin/foo, even if | ||
1226 | * /bin/foo is a symlink to busybox. | ||
1227 | */ | ||
1228 | search_applet.name = newJob->progs[i].argv[0]; | ||
1229 | |||
1219 | #ifdef BB_FEATURE_SH_BUILTINS_ALWAYS_WIN | 1230 | #ifdef BB_FEATURE_SH_BUILTINS_ALWAYS_WIN |
1220 | if (strcmp(get_last_path_component(newJob->progs[i].argv[0]), | 1231 | /* If you enable BB_FEATURE_SH_BUILTINS_ALWAYS_WIN, then |
1221 | a->name) == 0) | 1232 | * if you run /bin/cat, it will use BusyBox cat even if |
1222 | #else | 1233 | * /bin/cat exists on the filesystem and is _not_ busybox. |
1223 | /* Check if the command matches any busybox internal | 1234 | * Some systems want this, others do not. Choose wisely. :-) |
1224 | * commands ("applets") here. Following discussions from | 1235 | */ |
1225 | * November 2000 on busybox@opensource.lineo.com, don't use | 1236 | search_applet.name = get_last_path_component(search_applet.name); |
1226 | * get_last_path_component(). This way explicit (with | ||
1227 | * slashes) filenames will never be interpreted as an | ||
1228 | * applet, just like with builtins. This way the user can | ||
1229 | * override an applet with an explicit filename reference. | ||
1230 | * The only downside to this change is that an explicit | ||
1231 | * /bin/foo invocation fill fork and exec /bin/foo, even if | ||
1232 | * /bin/foo is a symlink to busybox. | ||
1233 | */ | ||
1234 | if (strcmp(newJob->progs[i].argv[0], a->name) == 0) | ||
1235 | #endif | 1237 | #endif |
1236 | { | 1238 | |
1237 | int argc_l; | 1239 | /* Do a binary search to find the applet entry given the name. */ |
1238 | char** argv=newJob->progs[i].argv; | 1240 | applet = bsearch(&search_applet, applets, NUM_APPLETS, |
1239 | for(argc_l=0;*argv!=NULL; argv++, argc_l++); | 1241 | sizeof(struct BB_applet), applet_name_compare); |
1240 | applet_name=a->name; | 1242 | if (applet != NULL) { |
1241 | optind = 1; | 1243 | int argc_l; |
1242 | exit((*(a->main)) (argc_l, newJob->progs[i].argv)); | 1244 | char** argv=newJob->progs[i].argv; |
1243 | } | 1245 | for(argc_l=0;*argv!=NULL; argv++, argc_l++); |
1244 | a++; | 1246 | applet_name=applet->name; |
1247 | optind = 1; | ||
1248 | exit((*(applet->main)) (argc_l, newJob->progs[i].argv)); | ||
1245 | } | 1249 | } |
1246 | #endif | 1250 | #endif |
1247 | 1251 | ||
1248 | execvp(newJob->progs[i].argv[0], newJob->progs[i].argv); | 1252 | execvp(newJob->progs[i].argv[0], newJob->progs[i].argv); |
1249 | fatalError("%s: %s\n", newJob->progs[i].argv[0], | 1253 | fatalError("%s: %s\n", newJob->progs[i].argv[0], |
1250 | strerror(errno)); | 1254 | strerror(errno)); |
1251 | } | 1255 | } |
1252 | if (outPipe[1]!=-1) { | 1256 | if (outPipe[1]!=-1) { |
1253 | close(outPipe[1]); | 1257 | close(outPipe[1]); |
@@ -1152,7 +1152,7 @@ static int runCommand(struct job *newJob, struct jobSet *jobList, int inBg, int | |||
1152 | int pipefds[2]; /* pipefd[0] is for reading */ | 1152 | int pipefds[2]; /* pipefd[0] is for reading */ |
1153 | struct builtInCommand *x; | 1153 | struct builtInCommand *x; |
1154 | #ifdef BB_FEATURE_SH_STANDALONE_SHELL | 1154 | #ifdef BB_FEATURE_SH_STANDALONE_SHELL |
1155 | const struct BB_applet *a = applets; | 1155 | struct BB_applet search_applet, *applet = applets; |
1156 | #endif | 1156 | #endif |
1157 | 1157 | ||
1158 | nextin = 0, nextout = 1; | 1158 | nextin = 0, nextout = 1; |
@@ -1214,40 +1214,44 @@ static int runCommand(struct job *newJob, struct jobSet *jobList, int inBg, int | |||
1214 | } | 1214 | } |
1215 | } | 1215 | } |
1216 | #ifdef BB_FEATURE_SH_STANDALONE_SHELL | 1216 | #ifdef BB_FEATURE_SH_STANDALONE_SHELL |
1217 | /* Check if the command matches any busybox internal commands here */ | 1217 | /* Check if the command matches any busybox internal |
1218 | while (a->name != 0) { | 1218 | * commands ("applets") here. Following discussions from |
1219 | * November 2000 on busybox@opensource.lineo.com, don't use | ||
1220 | * get_last_path_component(). This way explicit (with | ||
1221 | * slashes) filenames will never be interpreted as an | ||
1222 | * applet, just like with builtins. This way the user can | ||
1223 | * override an applet with an explicit filename reference. | ||
1224 | * The only downside to this change is that an explicit | ||
1225 | * /bin/foo invocation fill fork and exec /bin/foo, even if | ||
1226 | * /bin/foo is a symlink to busybox. | ||
1227 | */ | ||
1228 | search_applet.name = newJob->progs[i].argv[0]; | ||
1229 | |||
1219 | #ifdef BB_FEATURE_SH_BUILTINS_ALWAYS_WIN | 1230 | #ifdef BB_FEATURE_SH_BUILTINS_ALWAYS_WIN |
1220 | if (strcmp(get_last_path_component(newJob->progs[i].argv[0]), | 1231 | /* If you enable BB_FEATURE_SH_BUILTINS_ALWAYS_WIN, then |
1221 | a->name) == 0) | 1232 | * if you run /bin/cat, it will use BusyBox cat even if |
1222 | #else | 1233 | * /bin/cat exists on the filesystem and is _not_ busybox. |
1223 | /* Check if the command matches any busybox internal | 1234 | * Some systems want this, others do not. Choose wisely. :-) |
1224 | * commands ("applets") here. Following discussions from | 1235 | */ |
1225 | * November 2000 on busybox@opensource.lineo.com, don't use | 1236 | search_applet.name = get_last_path_component(search_applet.name); |
1226 | * get_last_path_component(). This way explicit (with | ||
1227 | * slashes) filenames will never be interpreted as an | ||
1228 | * applet, just like with builtins. This way the user can | ||
1229 | * override an applet with an explicit filename reference. | ||
1230 | * The only downside to this change is that an explicit | ||
1231 | * /bin/foo invocation fill fork and exec /bin/foo, even if | ||
1232 | * /bin/foo is a symlink to busybox. | ||
1233 | */ | ||
1234 | if (strcmp(newJob->progs[i].argv[0], a->name) == 0) | ||
1235 | #endif | 1237 | #endif |
1236 | { | 1238 | |
1237 | int argc_l; | 1239 | /* Do a binary search to find the applet entry given the name. */ |
1238 | char** argv=newJob->progs[i].argv; | 1240 | applet = bsearch(&search_applet, applets, NUM_APPLETS, |
1239 | for(argc_l=0;*argv!=NULL; argv++, argc_l++); | 1241 | sizeof(struct BB_applet), applet_name_compare); |
1240 | applet_name=a->name; | 1242 | if (applet != NULL) { |
1241 | optind = 1; | 1243 | int argc_l; |
1242 | exit((*(a->main)) (argc_l, newJob->progs[i].argv)); | 1244 | char** argv=newJob->progs[i].argv; |
1243 | } | 1245 | for(argc_l=0;*argv!=NULL; argv++, argc_l++); |
1244 | a++; | 1246 | applet_name=applet->name; |
1247 | optind = 1; | ||
1248 | exit((*(applet->main)) (argc_l, newJob->progs[i].argv)); | ||
1245 | } | 1249 | } |
1246 | #endif | 1250 | #endif |
1247 | 1251 | ||
1248 | execvp(newJob->progs[i].argv[0], newJob->progs[i].argv); | 1252 | execvp(newJob->progs[i].argv[0], newJob->progs[i].argv); |
1249 | fatalError("%s: %s\n", newJob->progs[i].argv[0], | 1253 | fatalError("%s: %s\n", newJob->progs[i].argv[0], |
1250 | strerror(errno)); | 1254 | strerror(errno)); |
1251 | } | 1255 | } |
1252 | if (outPipe[1]!=-1) { | 1256 | if (outPipe[1]!=-1) { |
1253 | close(outPipe[1]); | 1257 | close(outPipe[1]); |
diff --git a/shell/lash.c b/shell/lash.c index d6ac1fc17..1e0803f77 100644 --- a/shell/lash.c +++ b/shell/lash.c | |||
@@ -1152,7 +1152,7 @@ static int runCommand(struct job *newJob, struct jobSet *jobList, int inBg, int | |||
1152 | int pipefds[2]; /* pipefd[0] is for reading */ | 1152 | int pipefds[2]; /* pipefd[0] is for reading */ |
1153 | struct builtInCommand *x; | 1153 | struct builtInCommand *x; |
1154 | #ifdef BB_FEATURE_SH_STANDALONE_SHELL | 1154 | #ifdef BB_FEATURE_SH_STANDALONE_SHELL |
1155 | const struct BB_applet *a = applets; | 1155 | struct BB_applet search_applet, *applet = applets; |
1156 | #endif | 1156 | #endif |
1157 | 1157 | ||
1158 | nextin = 0, nextout = 1; | 1158 | nextin = 0, nextout = 1; |
@@ -1214,40 +1214,44 @@ static int runCommand(struct job *newJob, struct jobSet *jobList, int inBg, int | |||
1214 | } | 1214 | } |
1215 | } | 1215 | } |
1216 | #ifdef BB_FEATURE_SH_STANDALONE_SHELL | 1216 | #ifdef BB_FEATURE_SH_STANDALONE_SHELL |
1217 | /* Check if the command matches any busybox internal commands here */ | 1217 | /* Check if the command matches any busybox internal |
1218 | while (a->name != 0) { | 1218 | * commands ("applets") here. Following discussions from |
1219 | * November 2000 on busybox@opensource.lineo.com, don't use | ||
1220 | * get_last_path_component(). This way explicit (with | ||
1221 | * slashes) filenames will never be interpreted as an | ||
1222 | * applet, just like with builtins. This way the user can | ||
1223 | * override an applet with an explicit filename reference. | ||
1224 | * The only downside to this change is that an explicit | ||
1225 | * /bin/foo invocation fill fork and exec /bin/foo, even if | ||
1226 | * /bin/foo is a symlink to busybox. | ||
1227 | */ | ||
1228 | search_applet.name = newJob->progs[i].argv[0]; | ||
1229 | |||
1219 | #ifdef BB_FEATURE_SH_BUILTINS_ALWAYS_WIN | 1230 | #ifdef BB_FEATURE_SH_BUILTINS_ALWAYS_WIN |
1220 | if (strcmp(get_last_path_component(newJob->progs[i].argv[0]), | 1231 | /* If you enable BB_FEATURE_SH_BUILTINS_ALWAYS_WIN, then |
1221 | a->name) == 0) | 1232 | * if you run /bin/cat, it will use BusyBox cat even if |
1222 | #else | 1233 | * /bin/cat exists on the filesystem and is _not_ busybox. |
1223 | /* Check if the command matches any busybox internal | 1234 | * Some systems want this, others do not. Choose wisely. :-) |
1224 | * commands ("applets") here. Following discussions from | 1235 | */ |
1225 | * November 2000 on busybox@opensource.lineo.com, don't use | 1236 | search_applet.name = get_last_path_component(search_applet.name); |
1226 | * get_last_path_component(). This way explicit (with | ||
1227 | * slashes) filenames will never be interpreted as an | ||
1228 | * applet, just like with builtins. This way the user can | ||
1229 | * override an applet with an explicit filename reference. | ||
1230 | * The only downside to this change is that an explicit | ||
1231 | * /bin/foo invocation fill fork and exec /bin/foo, even if | ||
1232 | * /bin/foo is a symlink to busybox. | ||
1233 | */ | ||
1234 | if (strcmp(newJob->progs[i].argv[0], a->name) == 0) | ||
1235 | #endif | 1237 | #endif |
1236 | { | 1238 | |
1237 | int argc_l; | 1239 | /* Do a binary search to find the applet entry given the name. */ |
1238 | char** argv=newJob->progs[i].argv; | 1240 | applet = bsearch(&search_applet, applets, NUM_APPLETS, |
1239 | for(argc_l=0;*argv!=NULL; argv++, argc_l++); | 1241 | sizeof(struct BB_applet), applet_name_compare); |
1240 | applet_name=a->name; | 1242 | if (applet != NULL) { |
1241 | optind = 1; | 1243 | int argc_l; |
1242 | exit((*(a->main)) (argc_l, newJob->progs[i].argv)); | 1244 | char** argv=newJob->progs[i].argv; |
1243 | } | 1245 | for(argc_l=0;*argv!=NULL; argv++, argc_l++); |
1244 | a++; | 1246 | applet_name=applet->name; |
1247 | optind = 1; | ||
1248 | exit((*(applet->main)) (argc_l, newJob->progs[i].argv)); | ||
1245 | } | 1249 | } |
1246 | #endif | 1250 | #endif |
1247 | 1251 | ||
1248 | execvp(newJob->progs[i].argv[0], newJob->progs[i].argv); | 1252 | execvp(newJob->progs[i].argv[0], newJob->progs[i].argv); |
1249 | fatalError("%s: %s\n", newJob->progs[i].argv[0], | 1253 | fatalError("%s: %s\n", newJob->progs[i].argv[0], |
1250 | strerror(errno)); | 1254 | strerror(errno)); |
1251 | } | 1255 | } |
1252 | if (outPipe[1]!=-1) { | 1256 | if (outPipe[1]!=-1) { |
1253 | close(outPipe[1]); | 1257 | close(outPipe[1]); |
@@ -1775,6 +1775,14 @@ FILE *xfopen(const char *path, const char *mode) | |||
1775 | } | 1775 | } |
1776 | #endif | 1776 | #endif |
1777 | 1777 | ||
1778 | int applet_name_compare(const void *x, const void *y) | ||
1779 | { | ||
1780 | const struct BB_applet *applet1 = x; | ||
1781 | const struct BB_applet *applet2 = y; | ||
1782 | |||
1783 | return strcmp(applet1->name, applet2->name); | ||
1784 | } | ||
1785 | |||
1778 | /* END CODE */ | 1786 | /* END CODE */ |
1779 | /* | 1787 | /* |
1780 | Local Variables: | 1788 | Local Variables: |