aboutsummaryrefslogtreecommitdiff
path: root/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'init.c')
-rw-r--r--init.c59
1 files changed, 32 insertions, 27 deletions
diff --git a/init.c b/init.c
index 38e913121..0e126104b 100644
--- a/init.c
+++ b/init.c
@@ -745,7 +745,7 @@ void parse_inittab(void)
745#ifdef BB_FEATURE_USE_INITTAB 745#ifdef BB_FEATURE_USE_INITTAB
746 FILE *file; 746 FILE *file;
747 char buf[256], lineAsRead[256], tmpConsole[256]; 747 char buf[256], lineAsRead[256], tmpConsole[256];
748 char *p, *q, *r, *s; 748 char *id, *runlev, *action, *process, *eol;
749 const struct initActionType *a = actions; 749 const struct initActionType *a = actions;
750 int foundIt; 750 int foundIt;
751 751
@@ -772,64 +772,69 @@ void parse_inittab(void)
772 772
773 while (fgets(buf, 255, file) != NULL) { 773 while (fgets(buf, 255, file) != NULL) {
774 foundIt = FALSE; 774 foundIt = FALSE;
775 for (p = buf; *p == ' ' || *p == '\t'; p++); 775 /* Skip leading spaces */
776 if (*p == '#' || *p == '\n') 776 for (id = buf; *id == ' ' || *id == '\t'; id++);
777
778 /* Skip the line if it's a comment */
779 if (*id == '#' || *id == '\n')
777 continue; 780 continue;
778 781
779 /* Trim the trailing \n */ 782 /* Trim the trailing \n */
780 q = strrchr(p, '\n'); 783 eol = strrchr(id, '\n');
781 if (q != NULL) 784 if (eol != NULL)
782 *q = '\0'; 785 *eol = '\0';
783 786
784 /* Keep a copy around for posterity's sake (and error msgs) */ 787 /* Keep a copy around for posterity's sake (and error msgs) */
785 strcpy(lineAsRead, buf); 788 strcpy(lineAsRead, buf);
786 789
787 /* Grab the ID field */ 790 /* Separate the ID field from the runlevels */
788 s = p; 791 runlev = strchr(id, ':');
789 p = strchr(p, ':'); 792 if (runlev == NULL || *(runlev + 1) == '\0') {
790 if (p != NULL || *(p + 1) != '\0') { 793 message(LOG | CONSOLE, "Bad inittab entry: %s\n", lineAsRead);
791 *p = '\0'; 794 continue;
792 ++p; 795 } else {
796 *runlev = '\0';
797 ++runlev;
793 } 798 }
794 799
795 /* Now peel off the process field from the end 800 /* Separate the runlevels from the action */
796 * of the string */ 801 action = strchr(runlev, ':');
797 q = strrchr(p, ':'); 802 if (action == NULL || *(action + 1) == '\0') {
798 if (q == NULL || *(q + 1) == '\0') {
799 message(LOG | CONSOLE, "Bad inittab entry: %s\n", lineAsRead); 803 message(LOG | CONSOLE, "Bad inittab entry: %s\n", lineAsRead);
800 continue; 804 continue;
801 } else { 805 } else {
802 *q = '\0'; 806 *action = '\0';
803 ++q; 807 ++action;
804 } 808 }
805 809
806 /* Now peel off the action field */ 810 /* Separate the action from the process */
807 r = strrchr(p, ':'); 811 process = strchr(action, ':');
808 if (r == NULL || *(r + 1) == '\0') { 812 if (process == NULL || *(process + 1) == '\0') {
809 message(LOG | CONSOLE, "Bad inittab entry: %s\n", lineAsRead); 813 message(LOG | CONSOLE, "Bad inittab entry: %s\n", lineAsRead);
810 continue; 814 continue;
811 } else { 815 } else {
812 ++r; 816 *process = '\0';
817 ++process;
813 } 818 }
814 819
815 /* Ok, now process it */ 820 /* Ok, now process it */
816 a = actions; 821 a = actions;
817 while (a->name != 0) { 822 while (a->name != 0) {
818 if (strcmp(a->name, r) == 0) { 823 if (strcmp(a->name, action) == 0) {
819 if (*s != '\0') { 824 if (*id != '\0') {
820 struct stat statBuf; 825 struct stat statBuf;
821 826
822 strcpy(tmpConsole, "/dev/"); 827 strcpy(tmpConsole, "/dev/");
823 strncat(tmpConsole, s, 200); 828 strncat(tmpConsole, id, 200);
824 if (stat(tmpConsole, &statBuf) != 0) { 829 if (stat(tmpConsole, &statBuf) != 0) {
825 message(LOG | CONSOLE, 830 message(LOG | CONSOLE,
826 "device '%s' does not exist. Did you read the directions?\n", 831 "device '%s' does not exist. Did you read the directions?\n",
827 tmpConsole); 832 tmpConsole);
828 break; 833 break;
829 } 834 }
830 s = tmpConsole; 835 id = tmpConsole;
831 } 836 }
832 new_initAction(a->action, q, s); 837 new_initAction(a->action, process, id);
833 foundIt = TRUE; 838 foundIt = TRUE;
834 } 839 }
835 a++; 840 a++;