aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--init/init.c39
1 files changed, 14 insertions, 25 deletions
diff --git a/init/init.c b/init/init.c
index 10cb015dd..9cbe8189a 100644
--- a/init/init.c
+++ b/init/init.c
@@ -174,7 +174,7 @@ static const char * const environment[] = {
174 174
175/* Function prototypes */ 175/* Function prototypes */
176static void delete_init_action(struct init_action *a); 176static void delete_init_action(struct init_action *a);
177static int waitfor(const struct init_action *a); 177static int waitfor(const struct init_action *a, pid_t pid);
178static void halt_signal(int sig); 178static void halt_signal(int sig);
179 179
180 180
@@ -200,14 +200,14 @@ static void message(int device, const char *fmt, ...)
200{ 200{
201 va_list arguments; 201 va_list arguments;
202 int l; 202 int l;
203 char msg[1024]; 203 RESERVE_CONFIG_BUFFER(msg, 1024);
204#ifndef CONFIG_SYSLOGD 204#ifndef CONFIG_SYSLOGD
205 static int log_fd = -1; 205 static int log_fd = -1;
206#endif 206#endif
207 207
208 msg[0] = '\r'; 208 msg[0] = '\r';
209 va_start(arguments, fmt); 209 va_start(arguments, fmt);
210 l = vsnprintf(msg + 1, sizeof(msg) - 2, fmt, arguments) + 1; 210 l = vsnprintf(msg + 1, 1024 - 2, fmt, arguments) + 1;
211 va_end(arguments); 211 va_end(arguments);
212 212
213#ifdef CONFIG_SYSLOGD 213#ifdef CONFIG_SYSLOGD
@@ -258,6 +258,7 @@ static void message(int device, const char *fmt, ...)
258#endif 258#endif
259 } 259 }
260 } 260 }
261 RELEASE_CONFIG_BUFFER(msg);
261} 262}
262 263
263/* Set terminal settings to reasonable defaults */ 264/* Set terminal settings to reasonable defaults */
@@ -400,7 +401,7 @@ static void open_new_terminal(const char *device, char fail) {
400 401
401static pid_t run(const struct init_action *a) 402static pid_t run(const struct init_action *a)
402{ 403{
403 int i, junk; 404 int i;
404 pid_t pid; 405 pid_t pid;
405 char *s, *tmpCmd, *cmd[INIT_BUFFS_SIZE], *cmdpath; 406 char *s, *tmpCmd, *cmd[INIT_BUFFS_SIZE], *cmdpath;
406 char buf[INIT_BUFFS_SIZE + 6]; /* INIT_BUFFS_SIZE+strlen("exec ")+1 */ 407 char buf[INIT_BUFFS_SIZE + 6]; /* INIT_BUFFS_SIZE+strlen("exec ")+1 */
@@ -452,7 +453,6 @@ static pid_t run(const struct init_action *a)
452 /* If the init Action requires us to wait, then force the 453 /* If the init Action requires us to wait, then force the
453 * supplied terminal to be the controlling tty. */ 454 * supplied terminal to be the controlling tty. */
454 if (a->action & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) { 455 if (a->action & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) {
455 pid_t pgrp, tmp_pid;
456 456
457 /* Now fork off another process to just hang around */ 457 /* Now fork off another process to just hang around */
458 if ((pid = fork()) < 0) { 458 if ((pid = fork()) < 0) {
@@ -468,17 +468,9 @@ static pid_t run(const struct init_action *a)
468 signal(SIGQUIT, SIG_IGN); 468 signal(SIGQUIT, SIG_IGN);
469 signal(SIGCHLD, SIG_DFL); 469 signal(SIGCHLD, SIG_DFL);
470 470
471 /* Wait for child to exit */ 471 waitfor(NULL, pid);
472 while ((tmp_pid = waitpid(pid, &junk, 0)) != pid) {
473 if (tmp_pid == -1 && errno == ECHILD) {
474 break;
475 }
476 /* FIXME handle other errors */
477 }
478
479 /* See if stealing the controlling tty back is necessary */ 472 /* See if stealing the controlling tty back is necessary */
480 pgrp = tcgetpgrp(0); 473 if (tcgetpgrp(0) != getpid())
481 if (pgrp != getpid())
482 _exit(0); 474 _exit(0);
483 475
484 /* Use a temporary process to steal the controlling tty. */ 476 /* Use a temporary process to steal the controlling tty. */
@@ -491,10 +483,7 @@ static pid_t run(const struct init_action *a)
491 ioctl(0, TIOCSCTTY, 1); 483 ioctl(0, TIOCSCTTY, 1);
492 _exit(0); 484 _exit(0);
493 } 485 }
494 while ((tmp_pid = waitpid(pid, &junk, 0)) != pid) { 486 waitfor(NULL, pid);
495 if (tmp_pid < 0 && errno == ECHILD)
496 break;
497 }
498 _exit(0); 487 _exit(0);
499 } 488 }
500 489
@@ -603,15 +592,15 @@ static pid_t run(const struct init_action *a)
603 return pid; 592 return pid;
604} 593}
605 594
606static int waitfor(const struct init_action *a) 595static int waitfor(const struct init_action *a, pid_t pid)
607{ 596{
608 int pid; 597 int runpid;
609 int status, wpid; 598 int status, wpid;
610 599
611 pid = run(a); 600 runpid = (NULL == a)? pid : run(a);
612 while (1) { 601 while (1) {
613 wpid = waitpid(pid,&status,0); 602 wpid = waitpid(runpid,&status,0);
614 if (wpid == pid) 603 if (wpid == runpid)
615 break; 604 break;
616 if (wpid == -1 && errno == ECHILD) { 605 if (wpid == -1 && errno == ECHILD) {
617 /* we missed its termination */ 606 /* we missed its termination */
@@ -634,7 +623,7 @@ static void run_actions(int action)
634 if (access(a->terminal, R_OK | W_OK)) { 623 if (access(a->terminal, R_OK | W_OK)) {
635 delete_init_action(a); 624 delete_init_action(a);
636 } else if (a->action & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) { 625 } else if (a->action & (SYSINIT | WAIT | CTRLALTDEL | SHUTDOWN | RESTART)) {
637 waitfor(a); 626 waitfor(a, 0);
638 delete_init_action(a); 627 delete_init_action(a);
639 } else if (a->action & ONCE) { 628 } else if (a->action & ONCE) {
640 run(a); 629 run(a);