Revert "Honour tty field in /etc/inittab"
[project/procd.git] / inittab.c
index d73e0b87758a21a4153c00ce3c839b40f84bda9b..2d9a1e08d25faaddbfdd6297b560a85f2e3530ad 100644 (file)
--- a/inittab.c
+++ b/inittab.c
 #include <stdlib.h>
 #include <unistd.h>
 #include <regex.h>
+#include <ctype.h>
 
 #include <libubox/utils.h>
 #include <libubox/list.h>
 
+#include "utils/utils.h"
 #include "procd.h"
 #include "rcS.h"
 
@@ -72,7 +74,7 @@ static void fork_worker(struct init_action *a)
        }
 
        if (a->proc.pid > 0) {
-               DEBUG(2, "Launched new %s action, pid=%d\n",
+               DEBUG(4, "Launched new %s action, pid=%d\n",
                                        a->handler->name,
                                        (int) a->proc.pid);
                uloop_process_add(&a->proc);
@@ -83,7 +85,7 @@ static void child_exit(struct uloop_process *proc, int ret)
 {
        struct init_action *a = container_of(proc, struct init_action, proc);
 
-       DEBUG(2, "pid:%d\n", proc->pid);
+       DEBUG(4, "pid:%d\n", proc->pid);
         uloop_timeout_set(&a->tout, a->respawn);
 }
 
@@ -116,7 +118,7 @@ static void askfirst(struct init_action *a)
        i = stat(a->id, &s);
        chdir("/");
        if (i || (console && !strcmp(console, a->id))) {
-               DEBUG(2, "Skipping %s\n", a->id);
+               DEBUG(4, "Skipping %s\n", a->id);
                return;
        }
 
@@ -134,30 +136,20 @@ static void askfirst(struct init_action *a)
 static void askconsole(struct init_action *a)
 {
        struct stat s;
-       char line[256], *tty;
-       int i, r, fd = open("/proc/cmdline", O_RDONLY);
-       regex_t pat_cmdline;
-       regmatch_t matches[2];
-
-       if (fd < 0)
-               return;
-
-       r = read(fd, line, sizeof(line) - 1);
-       line[r] = '\0';
-       close(fd);
-
-       regcomp(&pat_cmdline, "console=([a-zA-Z0-9]*)", REG_EXTENDED);
-       if (regexec(&pat_cmdline, line, 2, matches, 0))
-               goto err_out;
-       line[matches[1].rm_eo] = '\0';
-       tty = &line[matches[1].rm_so];
+       char line[256], *tty, *split;
+       int i;
 
+       tty = get_cmdline_val("console", line, sizeof(line));
+       split=strchr(tty, ',');
+       if (split != NULL)
+               split = '\0';
+       
        chdir("/dev");
        i = stat(tty, &s);
        chdir("/");
        if (i) {
-               DEBUG(2, "skipping %s\n", tty);
-               goto err_out;
+               DEBUG(4, "skipping %s\n", tty);
+               return;
        }
        console = strdup(tty);
 
@@ -170,9 +162,6 @@ static void askconsole(struct init_action *a)
 
        a->proc.cb = child_exit;
        fork_worker(a);
-
-err_out:
-       regfree(&pat_cmdline);
 }
 
 static void rcrespawn(struct init_action *a)
@@ -249,7 +238,7 @@ void procd_inittab(void)
                return;
        }
 
-       regcomp(&pat_inittab, "([a-zA-Z0-9]*):([a-zA-Z0-9]*):([a-zA-Z0-9]*):([a-zA-Z0-9/[.-.]. ]*)", REG_EXTENDED);
+       regcomp(&pat_inittab, "([a-zA-Z0-9]*):([a-zA-Z0-9]*):([a-zA-Z0-9]*):(.*)", REG_EXTENDED);
        line = malloc(LINE_LEN);
        a = malloc(sizeof(struct init_action));
        memset(a, 0, sizeof(struct init_action));
@@ -258,6 +247,11 @@ void procd_inittab(void)
                char *tags[TAG_PROCESS + 1];
                char *tok;
                int i;
+               int len = strlen(line);
+
+               while (isspace(line[len - 1]))
+                       len--;
+               line[len] = 0;
 
                if (*line == '#')
                        continue;
@@ -265,7 +259,7 @@ void procd_inittab(void)
                if (regexec(&pat_inittab, line, 5, matches, 0))
                        continue;
 
-               DEBUG(2, "Parsing inittab - %s", line);
+               DEBUG(4, "Parsing inittab - %s", line);
 
                for (i = TAG_ID; i <= TAG_PROCESS; i++) {
                        line[matches[i].rm_eo] = '\0';
@@ -273,7 +267,7 @@ void procd_inittab(void)
                };
 
                tok = strtok(tags[TAG_PROCESS], " ");
-               for (i = 0; i < (MAX_ARGS - i - 1) && tok; i++) {
+               for (i = 0; i < (MAX_ARGS - 1) && tok; i++) {
                        a->argv[i] = tok;
                        tok = strtok(NULL, " ");
                }