aboutsummaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-12-25 23:58:42 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-12-25 23:58:42 +0100
commit6088e138e1c6d0b73f8004fc4b4e9ec40430e18e (patch)
tree87e2e5d630c8f56e69642f61b6e7e678d78a64ae /init
parent8993c3f260ba50ca8cbbd8a0185dd9d825bbaa2b (diff)
downloadbusybox-w32-6088e138e1c6d0b73f8004fc4b4e9ec40430e18e.tar.gz
busybox-w32-6088e138e1c6d0b73f8004fc4b4e9ec40430e18e.tar.bz2
busybox-w32-6088e138e1c6d0b73f8004fc4b4e9ec40430e18e.zip
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 (limited to 'init')
-rw-r--r--init/init.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/init/init.c b/init/init.c
index 0a0d503b5..a2cc3b5f5 100644
--- a/init/init.c
+++ b/init/init.c
@@ -401,20 +401,22 @@ static void init_exec(const char *command)
401 char buf[COMMAND_SIZE + 6]; /* COMMAND_SIZE+strlen("exec ")+1 */ 401 char buf[COMMAND_SIZE + 6]; /* COMMAND_SIZE+strlen("exec ")+1 */
402 int dash = (command[0] == '-' /* maybe? && command[1] == '/' */); 402 int dash = (command[0] == '-' /* maybe? && command[1] == '/' */);
403 403
404 command += dash;
405
404 /* See if any special /bin/sh requiring characters are present */ 406 /* See if any special /bin/sh requiring characters are present */
405 if (strpbrk(command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) { 407 if (strpbrk(command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) {
406 strcpy(buf, "exec "); 408 sprintf(buf, "exec %s", command); /* excluding "-" */
407 strcpy(buf + 5, command + dash); /* excluding "-" */
408 /* NB: LIBBB_DEFAULT_LOGIN_SHELL define has leading dash */ 409 /* NB: LIBBB_DEFAULT_LOGIN_SHELL define has leading dash */
409 cmd[0] = (char*)(LIBBB_DEFAULT_LOGIN_SHELL + !dash); 410 cmd[0] = (char*)(LIBBB_DEFAULT_LOGIN_SHELL + !dash);
410 cmd[1] = (char*)"-c"; 411 cmd[1] = (char*)"-c";
411 cmd[2] = buf; 412 cmd[2] = buf;
412 cmd[3] = NULL; 413 cmd[3] = NULL;
414 command = LIBBB_DEFAULT_LOGIN_SHELL + 1;
413 } else { 415 } else {
414 /* Convert command (char*) into cmd (char**, one word per string) */ 416 /* Convert command (char*) into cmd (char**, one word per string) */
415 char *word, *next; 417 char *word, *next;
416 int i = 0; 418 int i = 0;
417 next = strcpy(buf, command); /* including "-" */ 419 next = strcpy(buf, command - dash); /* command including "-" */
418 while ((word = strsep(&next, " \t")) != NULL) { 420 while ((word = strsep(&next, " \t")) != NULL) {
419 if (*word != '\0') { /* not two spaces/tabs together? */ 421 if (*word != '\0') { /* not two spaces/tabs together? */
420 cmd[i] = word; 422 cmd[i] = word;
@@ -425,14 +427,14 @@ static void init_exec(const char *command)
425 } 427 }
426 /* If we saw leading "-", it is interactive shell. 428 /* If we saw leading "-", it is interactive shell.
427 * Try harder to give it a controlling tty. 429 * Try harder to give it a controlling tty.
428 * And skip "-" in actual exec call. */ 430 */
429 if (dash) { 431 if (ENABLE_FEATURE_INIT_SCTTY && dash) {
430 /* _Attempt_ to make stdin a controlling tty. */ 432 /* _Attempt_ to make stdin a controlling tty. */
431 if (ENABLE_FEATURE_INIT_SCTTY) 433 ioctl(STDIN_FILENO, TIOCSCTTY, 0 /*only try, don't steal*/);
432 ioctl(STDIN_FILENO, TIOCSCTTY, 0 /*only try, don't steal*/);
433 } 434 }
434 BB_EXECVP(cmd[0] + dash, cmd); 435 /* Here command never contains the dash, cmd[0] might */
435 message(L_LOG | L_CONSOLE, "can't run '%s': %s", cmd[0], strerror(errno)); 436 BB_EXECVP(command, cmd);
437 message(L_LOG | L_CONSOLE, "can't run '%s': %s", command, strerror(errno));
436 /* returns if execvp fails */ 438 /* returns if execvp fails */
437} 439}
438 440