summaryrefslogtreecommitdiff
authorDenys Vlasenko <vda.linux@googlemail.com>2010-12-25 22:58:42 (GMT)
committer Denys Vlasenko <vda.linux@googlemail.com>2010-12-25 22:58:42 (GMT)
commit6088e138e1c6d0b73f8004fc4b4e9ec40430e18e (patch)
tree87e2e5d630c8f56e69642f61b6e7e678d78a64ae
parent8993c3f260ba50ca8cbbd8a0185dd9d825bbaa2b (diff)
downloadbusybox-6088e138e1c6d0b73f8004fc4b4e9ec40430e18e.zip
busybox-6088e138e1c6d0b73f8004fc4b4e9ec40430e18e.tar.gz
busybox-6088e138e1c6d0b73f8004fc4b4e9ec40430e18e.tar.bz2
init: simpler handling of leading dash in commands
function old new delta init_exec 233 219 -14 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat
-rw-r--r--init/init.c20
-rw-r--r--shell/ash.c2
2 files changed, 12 insertions, 10 deletions
diff --git a/init/init.c b/init/init.c
index 0a0d503..a2cc3b5 100644
--- a/init/init.c
+++ b/init/init.c
@@ -401,20 +401,22 @@ static void init_exec(const char *command)
char buf[COMMAND_SIZE + 6]; /* COMMAND_SIZE+strlen("exec ")+1 */
int dash = (command[0] == '-' /* maybe? && command[1] == '/' */);
+ command += dash;
+
/* See if any special /bin/sh requiring characters are present */
if (strpbrk(command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) {
- strcpy(buf, "exec ");
- strcpy(buf + 5, command + dash); /* excluding "-" */
+ sprintf(buf, "exec %s", command); /* excluding "-" */
/* NB: LIBBB_DEFAULT_LOGIN_SHELL define has leading dash */
cmd[0] = (char*)(LIBBB_DEFAULT_LOGIN_SHELL + !dash);
cmd[1] = (char*)"-c";
cmd[2] = buf;
cmd[3] = NULL;
+ command = LIBBB_DEFAULT_LOGIN_SHELL + 1;
} else {
/* Convert command (char*) into cmd (char**, one word per string) */
char *word, *next;
int i = 0;
- next = strcpy(buf, command); /* including "-" */
+ next = strcpy(buf, command - dash); /* command including "-" */
while ((word = strsep(&next, " \t")) != NULL) {
if (*word != '\0') { /* not two spaces/tabs together? */
cmd[i] = word;
@@ -425,14 +427,14 @@ static void init_exec(const char *command)
}
/* If we saw leading "-", it is interactive shell.
* Try harder to give it a controlling tty.
- * And skip "-" in actual exec call. */
- if (dash) {
+ */
+ if (ENABLE_FEATURE_INIT_SCTTY && dash) {
/* _Attempt_ to make stdin a controlling tty. */
- if (ENABLE_FEATURE_INIT_SCTTY)
- ioctl(STDIN_FILENO, TIOCSCTTY, 0 /*only try, don't steal*/);
+ ioctl(STDIN_FILENO, TIOCSCTTY, 0 /*only try, don't steal*/);
}
- BB_EXECVP(cmd[0] + dash, cmd);
- message(L_LOG | L_CONSOLE, "can't run '%s': %s", cmd[0], strerror(errno));
+ /* Here command never contains the dash, cmd[0] might */
+ BB_EXECVP(command, cmd);
+ message(L_LOG | L_CONSOLE, "can't run '%s': %s", command, strerror(errno));
/* returns if execvp fails */
}
diff --git a/shell/ash.c b/shell/ash.c
index 5671a52..6f03ac1 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -13063,7 +13063,7 @@ int ash_main(int argc UNUSED_PARAM, char **argv)
}
}
#endif
- if (/* argv[0] && */ argv[0][0] == '-')
+ if (argv[0] && argv[0][0] == '-')
isloginsh = 1;
if (isloginsh) {
state = 1;