cleanup debug level handover
authorJohn Crispin <blogic@openwrt.org>
Fri, 22 Nov 2013 12:13:54 +0000 (13:13 +0100)
committerJohn Crispin <blogic@openwrt.org>
Fri, 22 Nov 2013 14:04:07 +0000 (15:04 +0100)
Signed-off-by: John Crispin <blogic@openwrt.org>
initd/preinit.c
procd.c

index c5f7ada..fb94527 100644 (file)
@@ -31,11 +31,28 @@ static struct uloop_process preinit_proc;
 static struct uloop_process plugd_proc;
 
 static void
 static struct uloop_process plugd_proc;
 
 static void
+check_dbglvl(void)
+{
+       FILE *fp = fopen("/tmp/debug_level", "r");
+       int lvl = 0;
+
+       if (!fp)
+               return;
+       fscanf(fp, "%d", &lvl);
+       fclose(fp);
+       unlink("/tmp/debug_level");
+
+       if (lvl > 0 && lvl < 5)
+               debug = lvl;
+}
+
+static void
 spawn_procd(struct uloop_process *proc, int ret)
 {
        char *wdt_fd = watchdog_fd();
 spawn_procd(struct uloop_process *proc, int ret)
 {
        char *wdt_fd = watchdog_fd();
-       char *argv[] = { "/sbin/procd", "-d", "0", NULL };
+       char *argv[] = { "/sbin/procd", NULL};
        struct stat s;
        struct stat s;
+       char dbg[2];
 
        if (plugd_proc.pid > 0)
                kill(plugd_proc.pid, SIGKILL);
 
        if (plugd_proc.pid > 0)
                kill(plugd_proc.pid, SIGKILL);
@@ -49,10 +66,12 @@ spawn_procd(struct uloop_process *proc, int ret)
        DEBUG(2, "Exec to real procd now\n");
        if (wdt_fd)
                setenv("WDTFD", wdt_fd, 1);
        DEBUG(2, "Exec to real procd now\n");
        if (wdt_fd)
                setenv("WDTFD", wdt_fd, 1);
-       if (debug)
-               snprintf(argv[2], 2, "%d", debug & 0xf);
-       else
-               argv[1] = NULL;
+       check_dbglvl();
+       if (debug > 0) {
+               snprintf(dbg, 2, "%d", debug);
+               setenv("DBGLVL", dbg, 1);
+       }
+
        execvp(argv[0], argv);
 }
 
        execvp(argv[0], argv);
 }
 
diff --git a/procd.c b/procd.c
index 6fb0a72..ad80284 100644 (file)
--- a/procd.c
+++ b/procd.c
@@ -40,6 +40,12 @@ static int usage(const char *prog)
 int main(int argc, char **argv)
 {
        int ch;
 int main(int argc, char **argv)
 {
        int ch;
+       char *dbglvl = getenv("DBGLVL");
+
+       if (dbglvl) {
+               debug = atoi(dbglvl);
+               unsetenv("DBGLVL");
+       }
 
        while ((ch = getopt(argc, argv, "d:s:h:")) != -1) {
                switch (ch) {
 
        while ((ch = getopt(argc, argv, "d:s:h:")) != -1) {
                switch (ch) {