[OpenWrt-Devel,5/7] procd: add start-console support

Message ID eb003874d4d7a1db7778c02e5e5447cf27e5e1ab.1546385477.git.mhei@heimpold.de
State New
Headers show
Series
  • procd: console hotplugging support
Related show

Commit Message

Michael Heimpold Jan. 1, 2019, 11:44 p.m.
This adds a hotplug function to (re-)start inittab entries with askfirst or respawn.

At the moment the devices used with these actions must be present during boot
otherwise such lines are skipped.

However, this prevents having inittab entries with consoles for e.g. USB gadget
devices which only appear after kernel module loading and after configuring them
with configfs.

While it was possible to only scan the inittab for the desired item to start,
I assume the inittab to be short and re-running the whole list will be negligible.

Signed-off-by: Michael Heimpold <mhei@heimpold.de>
---
 plug/hotplug.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Patch

diff --git a/plug/hotplug.c b/plug/hotplug.c
index 80e6e4d..6b5960a 100644
--- a/plug/hotplug.c
+++ b/plug/hotplug.c
@@ -297,12 +297,27 @@  send_to_kernel:
 	exit(-1);
 }
 
+static void handle_start_console(struct blob_attr *msg, struct blob_attr *data)
+{
+	char *dev = blobmsg_get_string(blobmsg_data(data));
+
+	DEBUG(2, "Start console request for %s\n", dev);
+
+	procd_inittab_run("respawn");
+	procd_inittab_run("askfirst");
+
+	DEBUG(2, "Done starting console for %s\n", dev);
+
+	exit(-1);
+}
+
 enum {
 	HANDLER_MKDEV = 0,
 	HANDLER_RM,
 	HANDLER_EXEC,
 	HANDLER_BUTTON,
 	HANDLER_FW,
+	HANDLER_START_CONSOLE,
 };
 
 static struct cmd_handler {
@@ -336,6 +351,10 @@  static struct cmd_handler {
 		.name = "load-firmware",
 		.handler = handle_firmware,
 	},
+	[HANDLER_START_CONSOLE] = {
+		.name = "start-console",
+		.handler = handle_start_console,
+	},
 };
 
 static void queue_next(void)