diff options
Diffstat (limited to 'init.c')
-rw-r--r-- | init.c | 46 |
1 files changed, 22 insertions, 24 deletions
@@ -61,9 +61,11 @@ | |||
61 | #define VT_LOG "/dev/tty3" /* Virtual console */ | 61 | #define VT_LOG "/dev/tty3" /* Virtual console */ |
62 | #define SERIAL_CON0 "/dev/ttyS0" /* Primary serial console */ | 62 | #define SERIAL_CON0 "/dev/ttyS0" /* Primary serial console */ |
63 | #define SERIAL_CON1 "/dev/ttyS1" /* Serial console */ | 63 | #define SERIAL_CON1 "/dev/ttyS1" /* Serial console */ |
64 | #define SHELL "-sh" /* Default shell */ | 64 | #define SHELL "/bin/sh" /* Default shell */ |
65 | #define INITTAB "/etc/inittab" /* inittab file location */ | 65 | #define INITTAB "/etc/inittab" /* inittab file location */ |
66 | #ifndef INIT_SCRIPT | ||
66 | #define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */ | 67 | #define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */ |
68 | #endif | ||
67 | 69 | ||
68 | #define LOG 0x1 | 70 | #define LOG 0x1 |
69 | #define CONSOLE 0x2 | 71 | #define CONSOLE 0x2 |
@@ -330,6 +332,7 @@ static pid_t run(char* command, | |||
330 | "\nPlease press Enter to activate this console. "; | 332 | "\nPlease press Enter to activate this console. "; |
331 | 333 | ||
332 | if ((pid = fork()) == 0) { | 334 | if ((pid = fork()) == 0) { |
335 | int fd; | ||
333 | pid_t shell_pgid = getpid (); | 336 | pid_t shell_pgid = getpid (); |
334 | 337 | ||
335 | /* Clean up */ | 338 | /* Clean up */ |
@@ -338,17 +341,14 @@ static pid_t run(char* command, | |||
338 | close(2); | 341 | close(2); |
339 | setsid(); | 342 | setsid(); |
340 | 343 | ||
341 | if (device_open(terminal, O_RDWR) < 0) { | 344 | if ((fd=device_open(terminal, O_RDWR)) < 0) { |
342 | message(LOG|CONSOLE, "Bummer, can't open %s\r\n", terminal); | 345 | message(LOG|CONSOLE, "Bummer, can't open %s\r\n", terminal); |
343 | exit(1); | 346 | exit(1); |
344 | } | 347 | } |
345 | dup(0); | 348 | dup(fd); |
346 | dup(0); | 349 | dup(fd); |
347 | /* Grab control of the terminal. */ | 350 | set_term(fd); |
348 | if (tcsetpgrp (0, getpgrp()) < 0) { | 351 | tcsetpgrp (fd, getpgrp()); |
349 | message(LOG|CONSOLE, "tcsetpgrp error: %s\r\n", strerror(errno)); | ||
350 | } | ||
351 | set_term(0); | ||
352 | 352 | ||
353 | /* Reset signal handlers set for parent process */ | 353 | /* Reset signal handlers set for parent process */ |
354 | signal(SIGUSR1, SIG_DFL); | 354 | signal(SIGUSR1, SIG_DFL); |
@@ -497,7 +497,7 @@ static void reboot_signal(int sig) | |||
497 | 497 | ||
498 | #endif | 498 | #endif |
499 | 499 | ||
500 | void new_initAction (const struct initActionType *a, | 500 | void new_initAction (initActionEnum action, |
501 | char* process, char* cons) | 501 | char* process, char* cons) |
502 | { | 502 | { |
503 | initAction* newAction; | 503 | initAction* newAction; |
@@ -517,7 +517,7 @@ void new_initAction (const struct initActionType *a, | |||
517 | newAction->nextPtr = initActionList; | 517 | newAction->nextPtr = initActionList; |
518 | initActionList = newAction; | 518 | initActionList = newAction; |
519 | strncpy( newAction->process, process, 255); | 519 | strncpy( newAction->process, process, 255); |
520 | newAction->action = a->action; | 520 | newAction->action = action; |
521 | if (*cons != '\0') { | 521 | if (*cons != '\0') { |
522 | strncpy(newAction->console, cons, 255); | 522 | strncpy(newAction->console, cons, 255); |
523 | } else | 523 | } else |
@@ -561,12 +561,12 @@ void parse_inittab(void) | |||
561 | /* No inittab file -- set up some default behavior */ | 561 | /* No inittab file -- set up some default behavior */ |
562 | #endif | 562 | #endif |
563 | /* Askfirst shell on tty1 */ | 563 | /* Askfirst shell on tty1 */ |
564 | new_initAction( &(actions[3]), SHELL, console ); | 564 | new_initAction( ASKFIRST, SHELL, console ); |
565 | /* Askfirst shell on tty2 */ | 565 | /* Askfirst shell on tty2 */ |
566 | if (second_console != NULL) | 566 | if (second_console != NULL) |
567 | new_initAction( &(actions[3]), SHELL, second_console ); | 567 | new_initAction( ASKFIRST, SHELL, second_console ); |
568 | /* sysinit */ | 568 | /* sysinit */ |
569 | new_initAction( &(actions[0]), INIT_SCRIPT, console ); | 569 | new_initAction( SYSINIT, INIT_SCRIPT, console ); |
570 | 570 | ||
571 | return; | 571 | return; |
572 | #ifdef BB_FEATURE_USE_INITTAB | 572 | #ifdef BB_FEATURE_USE_INITTAB |
@@ -584,7 +584,6 @@ void parse_inittab(void) | |||
584 | 584 | ||
585 | /* Keep a copy around for posterity's sake (and error msgs) */ | 585 | /* Keep a copy around for posterity's sake (and error msgs) */ |
586 | strcpy(lineAsRead, buf); | 586 | strcpy(lineAsRead, buf); |
587 | message(LOG|CONSOLE, "read='%s'\n", lineAsRead); | ||
588 | 587 | ||
589 | /* Grab the ID field */ | 588 | /* Grab the ID field */ |
590 | s=p; | 589 | s=p; |
@@ -628,7 +627,7 @@ message(LOG|CONSOLE, "read='%s'\n", lineAsRead); | |||
628 | } | 627 | } |
629 | s = tmpConsole; | 628 | s = tmpConsole; |
630 | } | 629 | } |
631 | new_initAction( a, q, s); | 630 | new_initAction( a->action, q, s); |
632 | foundIt=TRUE; | 631 | foundIt=TRUE; |
633 | } | 632 | } |
634 | a++; | 633 | a++; |
@@ -712,9 +711,9 @@ extern int init_main(int argc, char **argv) | |||
712 | { | 711 | { |
713 | /* Ask first then start a shell on tty2 */ | 712 | /* Ask first then start a shell on tty2 */ |
714 | if (second_console != NULL) | 713 | if (second_console != NULL) |
715 | new_initAction( &(actions[3]), SHELL, second_console); | 714 | new_initAction( ASKFIRST, SHELL, second_console); |
716 | /* Ask first then start a shell on tty1 */ | 715 | /* Ask first then start a shell on tty1 */ |
717 | new_initAction( &(actions[3]), SHELL, console); | 716 | new_initAction( ASKFIRST, SHELL, console); |
718 | } else { | 717 | } else { |
719 | /* Not in single user mode -- see what inittab says */ | 718 | /* Not in single user mode -- see what inittab says */ |
720 | 719 | ||
@@ -731,7 +730,7 @@ extern int init_main(int argc, char **argv) | |||
731 | /* First run the sysinit command */ | 730 | /* First run the sysinit command */ |
732 | for( a=initActionList ; a; a=a->nextPtr) { | 731 | for( a=initActionList ; a; a=a->nextPtr) { |
733 | if (a->action == SYSINIT) { | 732 | if (a->action == SYSINIT) { |
734 | waitfor(a->process, console, FALSE); | 733 | waitfor(a->process, a->console, FALSE); |
735 | /* Now remove the "sysinit" entry from the list */ | 734 | /* Now remove the "sysinit" entry from the list */ |
736 | delete_initAction( a); | 735 | delete_initAction( a); |
737 | } | 736 | } |
@@ -739,7 +738,7 @@ extern int init_main(int argc, char **argv) | |||
739 | /* Next run anything that wants to block */ | 738 | /* Next run anything that wants to block */ |
740 | for( a=initActionList ; a; a=a->nextPtr) { | 739 | for( a=initActionList ; a; a=a->nextPtr) { |
741 | if (a->action == WAIT) { | 740 | if (a->action == WAIT) { |
742 | waitfor(a->process, console, FALSE); | 741 | waitfor(a->process, a->console, FALSE); |
743 | /* Now remove the "wait" entry from the list */ | 742 | /* Now remove the "wait" entry from the list */ |
744 | delete_initAction( a); | 743 | delete_initAction( a); |
745 | } | 744 | } |
@@ -747,7 +746,7 @@ extern int init_main(int argc, char **argv) | |||
747 | /* Next run anything to be run only once */ | 746 | /* Next run anything to be run only once */ |
748 | for( a=initActionList ; a; a=a->nextPtr) { | 747 | for( a=initActionList ; a; a=a->nextPtr) { |
749 | if (a->action == ONCE) { | 748 | if (a->action == ONCE) { |
750 | run(a->process, console, FALSE); | 749 | run(a->process, a->console, FALSE); |
751 | /* Now remove the "once" entry from the list */ | 750 | /* Now remove the "once" entry from the list */ |
752 | delete_initAction( a); | 751 | delete_initAction( a); |
753 | } | 752 | } |
@@ -760,7 +759,6 @@ extern int init_main(int argc, char **argv) | |||
760 | 759 | ||
761 | /* Now run the looping stuff for the rest of forever */ | 760 | /* Now run the looping stuff for the rest of forever */ |
762 | while (1) { | 761 | while (1) { |
763 | message(LOG|CONSOLE, "Looping\n"); | ||
764 | for( a=initActionList ; a; a=a->nextPtr) { | 762 | for( a=initActionList ; a; a=a->nextPtr) { |
765 | /* Only run stuff with pid==0. If they have | 763 | /* Only run stuff with pid==0. If they have |
766 | * a pid, that means they are still running */ | 764 | * a pid, that means they are still running */ |
@@ -768,11 +766,11 @@ extern int init_main(int argc, char **argv) | |||
768 | switch(a->action) { | 766 | switch(a->action) { |
769 | case RESPAWN: | 767 | case RESPAWN: |
770 | /* run the respawn stuff */ | 768 | /* run the respawn stuff */ |
771 | a->pid = run(a->process, console, FALSE); | 769 | a->pid = run(a->process, a->console, FALSE); |
772 | break; | 770 | break; |
773 | case ASKFIRST: | 771 | case ASKFIRST: |
774 | /* run the askfirst stuff */ | 772 | /* run the askfirst stuff */ |
775 | a->pid = run(a->process, console, TRUE); | 773 | a->pid = run(a->process, a->console, TRUE); |
776 | break; | 774 | break; |
777 | /* silence the compiler's incessant whining */ | 775 | /* silence the compiler's incessant whining */ |
778 | default: | 776 | default: |