aboutsummaryrefslogtreecommitdiff
path: root/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'init.c')
-rw-r--r--init.c74
1 files changed, 51 insertions, 23 deletions
diff --git a/init.c b/init.c
index 84b558d84..dbd9f2812 100644
--- a/init.c
+++ b/init.c
@@ -55,6 +55,7 @@
55#define VT_LOG "/dev/tty3" /* Virtual console */ 55#define VT_LOG "/dev/tty3" /* Virtual console */
56#define SERIAL_CON0 "/dev/ttyS0" /* Primary serial console */ 56#define SERIAL_CON0 "/dev/ttyS0" /* Primary serial console */
57#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */ 57#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
58#define GETTY "/sbin/getty" /* Default location of getty */
58#define SHELL "/bin/sh" /* Default shell */ 59#define SHELL "/bin/sh" /* Default shell */
59#define INITSCRIPT "/etc/init.d/rcS" /* Initscript. */ 60#define INITSCRIPT "/etc/init.d/rcS" /* Initscript. */
60 61
@@ -446,15 +447,19 @@ static void reboot_signal(int sig)
446 447
447extern int init_main(int argc, char **argv) 448extern int init_main(int argc, char **argv)
448{ 449{
449 int run_rc = TRUE; 450 int run_rc = FALSE;
450 int wait_for_enter = TRUE; 451 int single = FALSE;
452 int wait_for_enter_tty1 = TRUE;
453 int wait_for_enter_tty2 = TRUE;
451 pid_t pid1 = 0; 454 pid_t pid1 = 0;
452 pid_t pid2 = 0; 455 pid_t pid2 = 0;
453 struct stat statbuf; 456 struct stat statbuf;
454 const char* const rc_script_command[] = { INITSCRIPT, INITSCRIPT, 0}; 457 const char* const rc_script_command[] = { INITSCRIPT, INITSCRIPT, 0};
458 const char* const getty1_command[] = { GETTY, GETTY, VT_PRIMARY, 0};
459 const char* const getty2_command[] = { GETTY, GETTY, VT_SECONDARY, 0};
455 const char* const shell_command[] = { SHELL, "-" SHELL, 0}; 460 const char* const shell_command[] = { SHELL, "-" SHELL, 0};
456 const char* const* tty0_command = shell_command;
457 const char* const* tty1_command = shell_command; 461 const char* const* tty1_command = shell_command;
462 const char* const* tty2_command = shell_command;
458#ifdef BB_INIT_CMD_IF_RC_SCRIPT_EXITS 463#ifdef BB_INIT_CMD_IF_RC_SCRIPT_EXITS
459 const char* const rc_exit_command[] = { "BB_INIT_CMD_IF_RC_SCRIPT_EXITS", 464 const char* const rc_exit_command[] = { "BB_INIT_CMD_IF_RC_SCRIPT_EXITS",
460 "BB_INIT_CMD_IF_RC_SCRIPT_EXITS", 0 }; 465 "BB_INIT_CMD_IF_RC_SCRIPT_EXITS", 0 };
@@ -477,13 +482,6 @@ extern int init_main(int argc, char **argv)
477 } 482 }
478#endif 483#endif
479 484
480 /* Check if we are supposed to be in single user mode */
481 if ( argc > 1 && (!strcmp(argv[1], "single") ||
482 !strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) {
483 run_rc = FALSE;
484 }
485
486
487 /* Set up sig handlers -- be sure to 485 /* Set up sig handlers -- be sure to
488 * clear all of these in run() */ 486 * clear all of these in run() */
489 signal(SIGUSR1, halt_signal); 487 signal(SIGUSR1, halt_signal);
@@ -529,27 +527,55 @@ extern int init_main(int argc, char **argv)
529 /* Make sure there is enough memory to do something useful. */ 527 /* Make sure there is enough memory to do something useful. */
530 check_memory(); 528 check_memory();
531 529
530 /* Check if we are supposed to be in single user mode */
531 if ( argc > 1 && (!strcmp(argv[1], "single") ||
532 !strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) {
533 single = TRUE;
534 tty1_command = shell_command;
535 tty2_command = shell_command;
536 }
532 537
533 /* Make sure an init script exists before trying to run it */ 538 /* Make sure an init script exists before trying to run it */
534 if (run_rc == TRUE && stat(INITSCRIPT, &statbuf)==0) { 539 if (single==FALSE && stat(INITSCRIPT, &statbuf)==0) {
535 wait_for_enter = FALSE; 540 run_rc = TRUE;
536 tty0_command = rc_script_command; 541 wait_for_enter_tty1 = FALSE;
542 tty1_command = rc_script_command;
537 } 543 }
544
545 /* Make sure /sbin/getty exists before trying to run it */
546 if (stat(GETTY, &statbuf)==0) {
547 char* where;
548 wait_for_enter_tty2 = FALSE;
549 where = strrchr( console, '/');
550 if ( where != NULL) {
551 strcpy( (char*)getty2_command[2], where);
552 }
553 tty2_command = getty2_command;
554 /* Check on hooking a getty onto tty1 */
555 if (run_rc == FALSE && single==FALSE) {
556 wait_for_enter_tty1 = FALSE;
557 where = strrchr( second_console, '/');
558 if ( where != NULL) {
559 strcpy( (char*)getty1_command[2], where);
560 }
561 tty1_command = getty1_command;
562 }
563 }
564
538 565
539 566 /* Ok, now launch the tty1_command and tty2_command */
540 /* Ok, now launch the rc script and/or prepare to
541 * start up some VTs if somebody hits enter...
542 */
543 for (;;) { 567 for (;;) {
544 pid_t wpid; 568 pid_t wpid;
545 int status; 569 int status;
546 570
547 if (pid1 == 0 && tty0_command) { 571 if (pid1 == 0 && tty1_command) {
548 pid1 = run(tty0_command, console, wait_for_enter); 572 pid1 = run(tty1_command, console, wait_for_enter_tty1);
549 } 573 }
550 if (pid2 == 0 && tty1_command && second_console) { 574#ifdef BB_FEATURE_INIT_SECOND_CONSOLE
551 pid2 = run(tty1_command, second_console, TRUE); 575 if (pid2 == 0 && tty2_command && second_console) {
576 pid2 = run(tty2_command, second_console, wait_for_enter_tty2);
552 } 577 }
578#endif
553 wpid = wait(&status); 579 wpid = wait(&status);
554 if (wpid > 0 ) { 580 if (wpid > 0 ) {
555 message(LOG, "pid %d exited, status=%x.\n", wpid, status); 581 message(LOG, "pid %d exited, status=%x.\n", wpid, status);
@@ -563,14 +589,16 @@ extern int init_main(int argc, char **argv)
563 else { 589 else {
564 pid1 = 0; 590 pid1 = 0;
565 run_rc=FALSE; 591 run_rc=FALSE;
566 wait_for_enter=TRUE; 592 wait_for_enter_tty1=TRUE;
567 tty0_command=rc_exit_command; 593 tty1_command=rc_exit_command;
568 } 594 }
569#endif 595#endif
570 } 596 }
597#ifdef BB_FEATURE_INIT_SECOND_CONSOLE
571 if (wpid == pid2) { 598 if (wpid == pid2) {
572 pid2 = 0; 599 pid2 = 0;
573 } 600 }
601#endif
574 sleep(1); 602 sleep(1);
575 } 603 }
576} 604}