diff options
author | Eric Andersen <andersen@codepoet.org> | 2002-07-03 23:50:16 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2002-07-03 23:50:16 +0000 |
commit | 0826b6b0b3a3b569d3aebfe9a7ffb141cc72bd0d (patch) | |
tree | c73739aad055b94433a8c5812aeed6acc72d39cb | |
parent | 887ca79f04cdf45874ed783c1fb9b950bf25a246 (diff) | |
download | busybox-w32-0826b6b0b3a3b569d3aebfe9a7ffb141cc72bd0d.tar.gz busybox-w32-0826b6b0b3a3b569d3aebfe9a7ffb141cc72bd0d.tar.bz2 busybox-w32-0826b6b0b3a3b569d3aebfe9a7ffb141cc72bd0d.zip |
This is last_patch48 from vodz. More cleanups, kills a bit
of dead code, fixes one blatent bug.
-rw-r--r-- | init/init.c | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/init/init.c b/init/init.c index 4724ad7d5..229e3c4d6 100644 --- a/init/init.c +++ b/init/init.c | |||
@@ -51,6 +51,8 @@ | |||
51 | #define fork vfork | 51 | #define fork vfork |
52 | #endif | 52 | #endif |
53 | 53 | ||
54 | #define INIT_BUFFS_SIZE 256 | ||
55 | |||
54 | /* From <linux/vt.h> */ | 56 | /* From <linux/vt.h> */ |
55 | struct vt_stat { | 57 | struct vt_stat { |
56 | unsigned short v_active; /* active vt */ | 58 | unsigned short v_active; /* active vt */ |
@@ -149,8 +151,8 @@ static const struct init_action_type actions[] = { | |||
149 | /* Set up a linked list of init_actions, to be read from inittab */ | 151 | /* Set up a linked list of init_actions, to be read from inittab */ |
150 | struct init_action { | 152 | struct init_action { |
151 | pid_t pid; | 153 | pid_t pid; |
152 | char command[256]; | 154 | char command[INIT_BUFFS_SIZE]; |
153 | char terminal[256]; | 155 | char terminal[INIT_BUFFS_SIZE]; |
154 | struct init_action *next; | 156 | struct init_action *next; |
155 | int action; | 157 | int action; |
156 | }; | 158 | }; |
@@ -445,9 +447,10 @@ static void check_memory(void) | |||
445 | static pid_t run(struct init_action *a) | 447 | static pid_t run(struct init_action *a) |
446 | { | 448 | { |
447 | struct stat sb; | 449 | struct stat sb; |
448 | int i, j, fd, junk; | 450 | int i, j, junk; |
449 | pid_t pid, pgrp, tmp_pid; | 451 | pid_t pid, pgrp, tmp_pid; |
450 | char *s, *tmpCmd, *cmd[255], *cmdpath, buf[255]; | 452 | char *s, *tmpCmd, *cmd[INIT_BUFFS_SIZE], *cmdpath; |
453 | char buf[INIT_BUFFS_SIZE+6]; /* INIT_BUFFS_SIZE+strlen("exec ")+1 */ | ||
451 | sigset_t nmask, omask; | 454 | sigset_t nmask, omask; |
452 | char *environment[MAXENV+1] = { | 455 | char *environment[MAXENV+1] = { |
453 | termType, | 456 | termType, |
@@ -505,7 +508,7 @@ static pid_t run(struct init_action *a) | |||
505 | setsid(); | 508 | setsid(); |
506 | 509 | ||
507 | /* Open the new terminal device */ | 510 | /* Open the new terminal device */ |
508 | if ((fd = device_open(a->terminal, O_RDWR|O_NOCTTY)) < 0) { | 511 | if ((device_open(a->terminal, O_RDWR|O_NOCTTY)) < 0) { |
509 | if (stat(a->terminal, &sb) != 0) { | 512 | if (stat(a->terminal, &sb) != 0) { |
510 | message(LOG | CONSOLE, "\rdevice '%s' does not exist.\n", | 513 | message(LOG | CONSOLE, "\rdevice '%s' does not exist.\n", |
511 | a->terminal); | 514 | a->terminal); |
@@ -517,14 +520,14 @@ static pid_t run(struct init_action *a) | |||
517 | 520 | ||
518 | /* Non-interactive jobs should not get a controling tty */ | 521 | /* Non-interactive jobs should not get a controling tty */ |
519 | if ((a->action & (RESPAWN))==0) | 522 | if ((a->action & (RESPAWN))==0) |
520 | (void)ioctl(fd, TIOCSCTTY, 0); | 523 | (void)ioctl(0, TIOCSCTTY, 0); |
521 | 524 | ||
522 | /* Make sure the terminal will act fairly normal for us */ | 525 | /* Make sure the terminal will act fairly normal for us */ |
523 | set_term(0); | 526 | set_term(0); |
524 | /* Setup stdin, stdout, stderr for the new process so | 527 | /* Setup stdout, stderr for the new process so |
525 | * they point to the supplied terminal */ | 528 | * they point to the supplied terminal */ |
526 | dup(fd); | 529 | dup(0); |
527 | dup(fd); | 530 | dup(0); |
528 | 531 | ||
529 | /* For interactive jobs, create a new session | 532 | /* For interactive jobs, create a new session |
530 | * and become the process group leader */ | 533 | * and become the process group leader */ |
@@ -554,7 +557,7 @@ static pid_t run(struct init_action *a) | |||
554 | ; | 557 | ; |
555 | 558 | ||
556 | /* See if stealing the controlling tty back is necessary */ | 559 | /* See if stealing the controlling tty back is necessary */ |
557 | pgrp = tcgetpgrp(fd); | 560 | pgrp = tcgetpgrp(0); |
558 | if (pgrp != getpid()) | 561 | if (pgrp != getpid()) |
559 | _exit(0); | 562 | _exit(0); |
560 | 563 | ||
@@ -565,7 +568,7 @@ static pid_t run(struct init_action *a) | |||
565 | } | 568 | } |
566 | if (pid == 0) { | 569 | if (pid == 0) { |
567 | setsid(); | 570 | setsid(); |
568 | ioctl(tmp_pid, TIOCSCTTY, 1); | 571 | ioctl(0, TIOCSCTTY, 1); |
569 | _exit(0); | 572 | _exit(0); |
570 | } | 573 | } |
571 | while((tmp_pid = waitpid(pid, &junk, 0)) != pid) { | 574 | while((tmp_pid = waitpid(pid, &junk, 0)) != pid) { |
@@ -582,18 +585,17 @@ static pid_t run(struct init_action *a) | |||
582 | if (strpbrk(a->command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) { | 585 | if (strpbrk(a->command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) { |
583 | cmd[0] = SHELL; | 586 | cmd[0] = SHELL; |
584 | cmd[1] = "-c"; | 587 | cmd[1] = "-c"; |
585 | snprintf(buf, sizeof(buf), "exec %s", a->command); | 588 | strcat(strcpy(buf, "exec "), a->command); |
586 | cmd[2] = buf; | 589 | cmd[2] = buf; |
587 | cmd[3] = NULL; | 590 | cmd[3] = NULL; |
588 | } else { | 591 | } else { |
589 | /* Convert command (char*) into cmd (char**, one word per string) */ | 592 | /* Convert command (char*) into cmd (char**, one word per string) */ |
590 | safe_strncpy(buf, a->command, sizeof(buf)); | 593 | strcpy(buf, a->command); |
591 | s = buf; | 594 | s = buf; |
592 | for (tmpCmd = buf, i = 0; | 595 | for (tmpCmd = buf, i = 0; |
593 | (tmpCmd = strsep(&s, " \t")) != NULL;) { | 596 | (tmpCmd = strsep(&s, " \t")) != NULL;) { |
594 | if (*tmpCmd != '\0') { | 597 | if (*tmpCmd != '\0') { |
595 | cmd[i] = tmpCmd; | 598 | cmd[i] = tmpCmd; |
596 | tmpCmd++; | ||
597 | i++; | 599 | i++; |
598 | } | 600 | } |
599 | } | 601 | } |
@@ -886,9 +888,9 @@ static void new_init_action(int action, char *command, char *cons) | |||
886 | } else { | 888 | } else { |
887 | init_action_list = new_action; | 889 | init_action_list = new_action; |
888 | } | 890 | } |
889 | safe_strncpy(new_action->command, command, 255); | 891 | strcpy(new_action->command, command); |
890 | new_action->action = action; | 892 | new_action->action = action; |
891 | safe_strncpy(new_action->terminal, cons, 255); | 893 | strcpy(new_action->terminal, cons); |
892 | new_action->pid = 0; | 894 | new_action->pid = 0; |
893 | // message(LOG|CONSOLE, "command='%s' action='%d' terminal='%s'\n", | 895 | // message(LOG|CONSOLE, "command='%s' action='%d' terminal='%s'\n", |
894 | // new_action->command, new_action->action, new_action->terminal); | 896 | // new_action->command, new_action->action, new_action->terminal); |
@@ -922,7 +924,7 @@ static void parse_inittab(void) | |||
922 | { | 924 | { |
923 | #ifdef CONFIG_FEATURE_USE_INITTAB | 925 | #ifdef CONFIG_FEATURE_USE_INITTAB |
924 | FILE *file; | 926 | FILE *file; |
925 | char buf[256], lineAsRead[256], tmpConsole[256]; | 927 | char buf[INIT_BUFFS_SIZE], lineAsRead[INIT_BUFFS_SIZE], tmpConsole[INIT_BUFFS_SIZE]; |
926 | char *id, *runlev, *action, *command, *eol; | 928 | char *id, *runlev, *action, *command, *eol; |
927 | const struct init_action_type *a = actions; | 929 | const struct init_action_type *a = actions; |
928 | int foundIt; | 930 | int foundIt; |
@@ -960,7 +962,7 @@ static void parse_inittab(void) | |||
960 | #ifdef CONFIG_FEATURE_USE_INITTAB | 962 | #ifdef CONFIG_FEATURE_USE_INITTAB |
961 | } | 963 | } |
962 | 964 | ||
963 | while (fgets(buf, 255, file) != NULL) { | 965 | while (fgets(buf, INIT_BUFFS_SIZE, file) != NULL) { |
964 | foundIt = FALSE; | 966 | foundIt = FALSE; |
965 | /* Skip leading spaces */ | 967 | /* Skip leading spaces */ |
966 | for (id = buf; *id == ' ' || *id == '\t'; id++); | 968 | for (id = buf; *id == ' ' || *id == '\t'; id++); |
@@ -1013,7 +1015,7 @@ static void parse_inittab(void) | |||
1013 | if (strcmp(a->name, action) == 0) { | 1015 | if (strcmp(a->name, action) == 0) { |
1014 | if (*id != '\0') { | 1016 | if (*id != '\0') { |
1015 | strcpy(tmpConsole, "/dev/"); | 1017 | strcpy(tmpConsole, "/dev/"); |
1016 | strncat(tmpConsole, id, 200); | 1018 | strncat(tmpConsole, id, INIT_BUFFS_SIZE-6); |
1017 | id = tmpConsole; | 1019 | id = tmpConsole; |
1018 | } | 1020 | } |
1019 | new_init_action(a->action, command, id); | 1021 | new_init_action(a->action, command, id); |