diff mbox series

[OpenWrt-Devel] procd: add daemon mode and remove pid 1 check

Message ID 20190802090656.14343-1-mail@aparcar.org
State Superseded
Delegated to: John Crispin
Headers show
Series [OpenWrt-Devel] procd: add daemon mode and remove pid 1 check | expand

Commit Message

Paul Spooren Aug. 2, 2019, 9:06 a.m. UTC
Add arg -D to start procd in daemon mode. This allows running procd
directly, not only via /init. Useful for CI environments to start
services like ubus and netifd without needing the whole init process.

To make this work procd also spawns services when running on a different
pid than 1, normal when started via terminal. Before it would only try
to connect to an existing ubus instance.

The -D arg handling was kindly created (with < 60 seconds RTT) by John,
I just created the patch and removed pid checking.

CC: John Crispin <john@phrozen.org>
Signed-off-by: Paul Spooren <mail@aparcar.org>
---
 procd.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/procd.c b/procd.c
index 3de6208..10b974b 100644
--- a/procd.c
+++ b/procd.c
@@ -50,7 +50,7 @@  int main(int argc, char **argv)
 		unsetenv("DBGLVL");
 	}
 
-	while ((ch = getopt(argc, argv, "d:s:h:S")) != -1) {
+	while ((ch = getopt(argc, argv, "d:s:h:SD")) != -1) {
 		switch (ch) {
 		case 'h':
 			return hotplug_run(optarg);
@@ -63,6 +63,9 @@  int main(int argc, char **argv)
 		case 'S':
 			ulog_channels = ULOG_STDIO;
 			break;
+		case 'D':
+			daemon(1, 1);
+			break;
 		default:
 			return usage(argv[0]);
 		}
@@ -74,10 +77,7 @@  int main(int argc, char **argv)
 	setsid();
 	uloop_init();
 	procd_signal();
-	if (getpid() != 1)
-		procd_connect_ubus();
-	else
-		procd_state_next();
+	procd_state_next();
 	uloop_run();
 	uloop_done();