X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fprocd.git;a=blobdiff_plain;f=initd%2Fpreinit.c;h=729978ea2f2af790653baaee5ae788f05a88a177;hp=fb94527d50c002043d8500d17ebae61886e412c7;hb=4004b68fe57dd72197b8a00b0756cc7f978ad88a;hpb=dc3988c38546c37a02030af8201048272caa7ded diff --git a/initd/preinit.c b/initd/preinit.c index fb94527..729978e 100644 --- a/initd/preinit.c +++ b/initd/preinit.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -38,7 +39,8 @@ check_dbglvl(void) if (!fp) return; - fscanf(fp, "%d", &lvl); + if (fscanf(fp, "%d", &lvl) == EOF) + ERROR("failed to read debug level\n"); fclose(fp); unlink("/tmp/debug_level"); @@ -63,6 +65,7 @@ spawn_procd(struct uloop_process *proc, int ret) unsetenv("INITRAMFS"); unsetenv("PREINIT"); + unlink("/tmp/.preinit"); DEBUG(2, "Exec to real procd now\n"); if (wdt_fd) setenv("WDTFD", wdt_fd, 1); @@ -86,6 +89,7 @@ preinit(void) { char *init[] = { "/bin/sh", "/etc/preinit", NULL }; char *plug[] = { "/sbin/procd", "-h", "/etc/hotplug-preinit.json", NULL }; + int fd; LOG("- preinit -\n"); @@ -104,6 +108,13 @@ preinit(void) setenv("PREINIT", "1", 1); + fd = creat("/tmp/.preinit", 0600); + + if (fd < 0) + ERROR("Failed to create sentinel file\n"); + else + close(fd); + preinit_proc.cb = spawn_procd; preinit_proc.pid = fork(); if (!preinit_proc.pid) {