diff options
Diffstat (limited to 'sh.c')
-rw-r--r-- | sh.c | 60 |
1 files changed, 32 insertions, 28 deletions
@@ -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]); |