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

Paul Spooren mail at aparcar.org
Fri Aug 2 17:58:27 EDT 2019


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 at phrozen.org>
Signed-off-by: Paul Spooren <mail at aparcar.org>
---
v2: added usage/help message

 procd.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/procd.c b/procd.c
index 3de6208..aaef4fe 100644
--- a/procd.c
+++ b/procd.c
@@ -35,6 +35,7 @@ static int usage(const char *prog)
 		"	-h <path>	run as hotplug daemon\n"
 		"	-d <level>	Enable debug messages\n"
 		"	-S		Print messages to stdout\n"
+		"	-D		Run procd as daemon process\n"
 		"\n", prog);
 	return 1;
 }
@@ -50,7 +51,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 +64,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 +78,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();
 
-- 
2.20.1


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list