aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>1999-12-30 09:25:17 +0000
committerErik Andersen <andersen@codepoet.org>1999-12-30 09:25:17 +0000
commit9c88cac5cbfb2ff70f800ee5bb3289e925aaa65f (patch)
tree995ccacfa08c819278c8b7448f8167376adabcf3
parent1266a13e1f687d34052ae7e2469048d035633e58 (diff)
downloadbusybox-w32-9c88cac5cbfb2ff70f800ee5bb3289e925aaa65f.tar.gz
busybox-w32-9c88cac5cbfb2ff70f800ee5bb3289e925aaa65f.tar.bz2
busybox-w32-9c88cac5cbfb2ff70f800ee5bb3289e925aaa65f.zip
First pass inittab parser written
-Erik
-rw-r--r--init.c75
-rw-r--r--init/init.c75
2 files changed, 150 insertions, 0 deletions
diff --git a/init.c b/init.c
index 561b5fd52..b71c9f74e 100644
--- a/init.c
+++ b/init.c
@@ -62,10 +62,13 @@
62#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */ 62#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
63#define GETTY "/sbin/getty" /* Default location of getty */ 63#define GETTY "/sbin/getty" /* Default location of getty */
64#define SHELL "/bin/sh" /* Default shell */ 64#define SHELL "/bin/sh" /* Default shell */
65#define INITTAB "/etc/inittab" /* inittab file location */
65#ifndef BB_INIT_SCRIPT 66#ifndef BB_INIT_SCRIPT
66#define BB_INIT_SCRIPT "/etc/init.d/rcS" /* Initscript. */ 67#define BB_INIT_SCRIPT "/etc/init.d/rcS" /* Initscript. */
67#endif 68#endif
68 69
70#if 1
71
69#define LOG 0x1 72#define LOG 0x1
70#define CONSOLE 0x2 73#define CONSOLE 0x2
71static char *console = _PATH_CONSOLE; 74static char *console = _PATH_CONSOLE;
@@ -609,3 +612,75 @@ extern int init_main(int argc, char **argv)
609 sleep(1); 612 sleep(1);
610 } 613 }
611} 614}
615
616#else
617
618
619void parse_inittab(void)
620{
621 FILE* file;
622 char buf[256];
623 char action[256]="";
624 char process[256]="";
625 char *p, *q;
626
627
628 if ((file = fopen(INITTAB, "r")) < 0) {
629 /* No inittab file -- set up some default behavior */
630
631 /* FIXME */
632 return;
633 }
634
635 while ( fgets(buf, 255, file) != NULL) {
636 for(p = buf; *p == ' ' || *p == '\t'; p++);
637 if (*p == '#' || *p == '\n') continue;
638
639 /* Trim the trailing \n */
640 q = strrchr( p, '\n');
641 if (q != NULL)
642 *q='\0';
643
644 /* Skip past the ID field and the runlevel
645 * field (both are ignored) */
646 p = strchr( p, ':');
647
648 /* Now peal off the process field from the end
649 * of the string */
650 q = strrchr( p, ':');
651 if ( q == NULL || q+1 == NULL)
652 goto choke;
653 *q='\0';
654 strcpy( process, ++q);
655 fprintf(stderr, "process=%s\n", process);
656
657
658 /* Now peal off the action field */
659 q = strrchr( p, ':');
660 if ( q == NULL || q+1 == NULL)
661 goto choke;
662 strcpy( action, ++q);
663 fprintf(stderr, "action=%s\n", action);
664
665
666 /* Ok, now do the right thing */
667
668 }
669 return;
670
671choke:
672 //message(CONSOLE, "Bad entry:");
673 fprintf(stderr, "Bad inittab entry: %s", buf);
674 while (1) sleep(1);
675
676}
677
678
679extern int init_main(int argc, char **argv)
680{
681 parse_inittab();
682 exit( TRUE);
683}
684
685
686#endif
diff --git a/init/init.c b/init/init.c
index 561b5fd52..b71c9f74e 100644
--- a/init/init.c
+++ b/init/init.c
@@ -62,10 +62,13 @@
62#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */ 62#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
63#define GETTY "/sbin/getty" /* Default location of getty */ 63#define GETTY "/sbin/getty" /* Default location of getty */
64#define SHELL "/bin/sh" /* Default shell */ 64#define SHELL "/bin/sh" /* Default shell */
65#define INITTAB "/etc/inittab" /* inittab file location */
65#ifndef BB_INIT_SCRIPT 66#ifndef BB_INIT_SCRIPT
66#define BB_INIT_SCRIPT "/etc/init.d/rcS" /* Initscript. */ 67#define BB_INIT_SCRIPT "/etc/init.d/rcS" /* Initscript. */
67#endif 68#endif
68 69
70#if 1
71
69#define LOG 0x1 72#define LOG 0x1
70#define CONSOLE 0x2 73#define CONSOLE 0x2
71static char *console = _PATH_CONSOLE; 74static char *console = _PATH_CONSOLE;
@@ -609,3 +612,75 @@ extern int init_main(int argc, char **argv)
609 sleep(1); 612 sleep(1);
610 } 613 }
611} 614}
615
616#else
617
618
619void parse_inittab(void)
620{
621 FILE* file;
622 char buf[256];
623 char action[256]="";
624 char process[256]="";
625 char *p, *q;
626
627
628 if ((file = fopen(INITTAB, "r")) < 0) {
629 /* No inittab file -- set up some default behavior */
630
631 /* FIXME */
632 return;
633 }
634
635 while ( fgets(buf, 255, file) != NULL) {
636 for(p = buf; *p == ' ' || *p == '\t'; p++);
637 if (*p == '#' || *p == '\n') continue;
638
639 /* Trim the trailing \n */
640 q = strrchr( p, '\n');
641 if (q != NULL)
642 *q='\0';
643
644 /* Skip past the ID field and the runlevel
645 * field (both are ignored) */
646 p = strchr( p, ':');
647
648 /* Now peal off the process field from the end
649 * of the string */
650 q = strrchr( p, ':');
651 if ( q == NULL || q+1 == NULL)
652 goto choke;
653 *q='\0';
654 strcpy( process, ++q);
655 fprintf(stderr, "process=%s\n", process);
656
657
658 /* Now peal off the action field */
659 q = strrchr( p, ':');
660 if ( q == NULL || q+1 == NULL)
661 goto choke;
662 strcpy( action, ++q);
663 fprintf(stderr, "action=%s\n", action);
664
665
666 /* Ok, now do the right thing */
667
668 }
669 return;
670
671choke:
672 //message(CONSOLE, "Bad entry:");
673 fprintf(stderr, "Bad inittab entry: %s", buf);
674 while (1) sleep(1);
675
676}
677
678
679extern int init_main(int argc, char **argv)
680{
681 parse_inittab();
682 exit( TRUE);
683}
684
685
686#endif