aboutsummaryrefslogtreecommitdiff
path: root/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'init.c')
-rw-r--r--init.c57
1 files changed, 44 insertions, 13 deletions
diff --git a/init.c b/init.c
index 116d07954..95c2322f7 100644
--- a/init.c
+++ b/init.c
@@ -97,7 +97,7 @@ typedef struct initActionTag initAction;
97struct initActionTag { 97struct initActionTag {
98 pid_t pid; 98 pid_t pid;
99 char process[256]; 99 char process[256];
100 char *console; 100 char console[256];
101 initAction *nextPtr; 101 initAction *nextPtr;
102 initActionEnum action; 102 initActionEnum action;
103}; 103};
@@ -496,9 +496,16 @@ static void reboot_signal(int sig)
496#endif 496#endif
497 497
498void new_initAction (const struct initActionType *a, 498void new_initAction (const struct initActionType *a,
499 char* process, char* console) 499 char* process, char* cons)
500{ 500{
501 initAction* newAction; 501 initAction* newAction;
502
503 /* If BusyBox detects that a serial console is in use,
504 * then entries containing non-empty id fields will _not_ be run.
505 */
506 if (second_console != NULL && *cons != '\0')
507 return;
508
502 newAction = calloc ((size_t)(1), sizeof(initAction)); 509 newAction = calloc ((size_t)(1), sizeof(initAction));
503 if (!newAction) { 510 if (!newAction) {
504 fprintf(stderr, "Memory allocation failure\n"); 511 fprintf(stderr, "Memory allocation failure\n");
@@ -508,7 +515,10 @@ void new_initAction (const struct initActionType *a,
508 initActionList = newAction; 515 initActionList = newAction;
509 strncpy( newAction->process, process, 255); 516 strncpy( newAction->process, process, 255);
510 newAction->action = a->action; 517 newAction->action = a->action;
511 newAction->console = console; 518 if (*cons != '\0')
519 strncpy(newAction->console, cons, 255);
520 else
521 strncpy(newAction->console, console, 255);
512 newAction->pid = 0; 522 newAction->pid = 0;
513} 523}
514 524
@@ -524,11 +534,19 @@ void delete_initAction (initAction *action)
524 } 534 }
525} 535}
526 536
537/* NOTE that if BB_FEATURE_USE_INITTAB is NOT defined,
538 * then parse_inittab() simply adds in some default
539 * actions(i.e runs INIT_SCRIPT and then starts a pair
540 * of "askfirst" shells. If BB_FEATURE_USE_INITTAB
541 * _is_ defined, but /etc/inittab is missing == same
542 * default behavior.
543 * */
527void parse_inittab(void) 544void parse_inittab(void)
528{ 545{
546#ifdef BB_FEATURE_USE_INITTAB
529 FILE* file; 547 FILE* file;
530 char buf[256]; 548 char buf[256], buf1[256];
531 char *p, *q, *r; 549 char *p, *q, *r, *s;
532 const struct initActionType *a = actions; 550 const struct initActionType *a = actions;
533 int foundIt; 551 int foundIt;
534 552
@@ -536,7 +554,7 @@ void parse_inittab(void)
536 file = fopen(INITTAB, "r"); 554 file = fopen(INITTAB, "r");
537 if (file == NULL) { 555 if (file == NULL) {
538 /* No inittab file -- set up some default behavior */ 556 /* No inittab file -- set up some default behavior */
539 557#endif
540 /* Askfirst shell on tty1 */ 558 /* Askfirst shell on tty1 */
541 new_initAction( &(actions[3]), SHELL, console ); 559 new_initAction( &(actions[3]), SHELL, console );
542 /* Askfirst shell on tty2 */ 560 /* Askfirst shell on tty2 */
@@ -546,6 +564,7 @@ void parse_inittab(void)
546 new_initAction( &(actions[0]), INIT_SCRIPT, console ); 564 new_initAction( &(actions[0]), INIT_SCRIPT, console );
547 565
548 return; 566 return;
567#ifdef BB_FEATURE_USE_INITTAB
549 } 568 }
550 569
551 while ( fgets(buf, 255, file) != NULL) { 570 while ( fgets(buf, 255, file) != NULL) {
@@ -558,15 +577,22 @@ void parse_inittab(void)
558 if (q != NULL) 577 if (q != NULL)
559 *q='\0'; 578 *q='\0';
560 579
561 /* Skip past the ID field and the runlevel 580 /* Keep a copy around for posterity's sake (and error msgs) */
562 * field (both are ignored) */ 581 strcpy(buf1, buf);
582
583 /* Grab the ID field */
584 s=p;
563 p = strchr( p, ':'); 585 p = strchr( p, ':');
586 if ( p != NULL || *(p+1) != '\0' ) {
587 *p='\0';
588 ++p;
589 }
564 590
565 /* Now peal off the process field from the end 591 /* Now peal off the process field from the end
566 * of the string */ 592 * of the string */
567 q = strrchr( p, ':'); 593 q = strrchr( p, ':');
568 if ( q == NULL || *(q+1) == '\0' ) { 594 if ( q == NULL || *(q+1) == '\0' ) {
569 fprintf(stderr, "Bad inittab entry: %s\n", buf); 595 fprintf(stderr, "Bad inittab entry: %s\n", buf1);
570 continue; 596 continue;
571 } else { 597 } else {
572 *q='\0'; 598 *q='\0';
@@ -576,7 +602,7 @@ void parse_inittab(void)
576 /* Now peal off the action field */ 602 /* Now peal off the action field */
577 r = strrchr( p, ':'); 603 r = strrchr( p, ':');
578 if ( r == NULL || *(r+1) == '\0') { 604 if ( r == NULL || *(r+1) == '\0') {
579 fprintf(stderr, "Bad inittab entry: %s\n", buf); 605 fprintf(stderr, "Bad inittab entry: %s\n", buf1);
580 continue; 606 continue;
581 } else { 607 } else {
582 ++r; 608 ++r;
@@ -586,7 +612,7 @@ void parse_inittab(void)
586 a = actions; 612 a = actions;
587 while (a->name != 0) { 613 while (a->name != 0) {
588 if (strcmp(a->name, r) == 0) { 614 if (strcmp(a->name, r) == 0) {
589 new_initAction( a, q, NULL); 615 new_initAction( a, q, s);
590 foundIt=TRUE; 616 foundIt=TRUE;
591 } 617 }
592 a++; 618 a++;
@@ -595,13 +621,13 @@ void parse_inittab(void)
595 continue; 621 continue;
596 else { 622 else {
597 /* Choke on an unknown action */ 623 /* Choke on an unknown action */
598 fprintf(stderr, "Bad inittab entry: %s\n", buf); 624 fprintf(stderr, "Bad inittab entry: %s\n", buf1);
599 } 625 }
600 } 626 }
601 return; 627 return;
628#endif
602} 629}
603 630
604
605extern int init_main(int argc, char **argv) 631extern int init_main(int argc, char **argv)
606{ 632{
607 initAction *a; 633 initAction *a;
@@ -675,6 +701,11 @@ extern int init_main(int argc, char **argv)
675 new_initAction( &(actions[3]), SHELL, console); 701 new_initAction( &(actions[3]), SHELL, console);
676 } else { 702 } else {
677 /* Not in single user mode -- see what inittab says */ 703 /* Not in single user mode -- see what inittab says */
704
705 /* NOTE that if BB_FEATURE_USE_INITTAB is NOT defined,
706 * then parse_inittab() simply adds in some default
707 * actions(i.e runs INIT_SCRIPT and then starts a pair
708 * of "askfirst" shells */
678 parse_inittab(); 709 parse_inittab();
679 } 710 }
680 711