2 * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version 2.1
7 * as published by the Free Software Foundation
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #include <sys/types.h>
17 #include <sys/mount.h>
26 static struct uloop_process preinit;
28 static void spawn_procd(struct uloop_process *proc, int ret)
30 char *wdt_fd = watchdog_fd();
31 char *argv[] = { "/sbin/procd", NULL };
34 if (!stat("/tmp/sysupgrade", &s))
38 unsetenv("INITRAMFS");
40 DEBUG(1, "Exec to real procd now\n");
42 setenv("WDTFD", wdt_fd, 1);
43 execvp(argv[0], argv);
46 void procd_preinit(void)
48 char *argv[] = { "/bin/sh", "/etc/preinit", NULL };
52 setenv("PREINIT", "1", 1);
53 preinit.cb = spawn_procd;
56 execvp(argv[0], argv);
57 ERROR("Failed to start preinit\n");
61 if (preinit.pid <= 0) {
62 ERROR("Failed to start new preinit instance\n");
66 uloop_process_add(&preinit);
67 DEBUG(2, "Launched preinit instance, pid=%d\n", (int) preinit.pid);