diff --git a/configure.ac b/configure.ac index 0e3dff9e..ebafbfc4 100644 --- a/configure.ac +++ b/configure.ac @@ -52,6 +52,10 @@ AC_ARG_ENABLE(auto_reload, AS_HELP_STRING([--enable-auto-reload], [Automatic reload on any .conf change]),,[ enable_auto_reload=no]) +AC_ARG_ENABLE(kernel_cmdline, + AS_HELP_STRING([--enable-kernel-cmdline], [Parse init args from /proc/cmdline (don't use!)]),,[ + enable_kernel_cmdline=no]) + AC_ARG_ENABLE(redirect, AS_HELP_STRING([--disable-redirect], [Disable redirection of service output to /dev/null]),,[ enable_redirect=yes]) @@ -124,6 +128,9 @@ AC_ARG_WITH(watchdog, AS_IF([test "x$enable_auto_reload" = "xyes"], [ AC_DEFINE(AUTO_RELOAD, 1, [Finit automatically does `initctl reload` on any .conf change])]) +AS_IF([test "x$enable_kernel_cmdline" = "xyes"], [ + AC_DEFINE(KERNEL_CMDLINE, 1, [Dumpster diving after init args from /proc/cmdline])]) + AS_IF([test "x$enable_redirect" = "xyes"], [ AC_DEFINE(REDIRECT_OUTPUT, 1, [Enable redirection of service output to /dev/null])]) diff --git a/doc/build.md b/doc/build.md index 0a6c49b1..c131a267 100644 --- a/doc/build.md +++ b/doc/build.md @@ -53,6 +53,10 @@ Below are a few of the main switches to configure: built-ins (.o files) and all external libraries, except the C library will be linked statically. +* `--enable-kernel-cmdline`: Enable Finit pre-4.1 parsing of init args from + `/proc/cmdline`, this is not recommended since Finit may be running as the + init for container apps that can see the host's `/proc` filesystem + * `--enable-alsa-utils-plugin`: Enable the optional `alsa-utils.so` sound plugin. * `--enable-dbus-plugin`: Enable the optional D-Bus `dbus.so` plugin. diff --git a/doc/cmdline.md b/doc/cmdline.md index 865cf9c9..3551a81a 100644 --- a/doc/cmdline.md +++ b/doc/cmdline.md @@ -6,6 +6,8 @@ passed on the Linux kernel command line. Not limited to Finit. The `bool` setting is one of `on, off, true false, 1, 0`. +> **NOTE:** remember to use `--` to separate kernel parameters from +> parameters to init. E.g., `init=/sbin/finit -- finit.debug rescue` * `debug`: Enable kernel debug. Debug messages are printed to the console until Finit starts up. diff --git a/src/conf.c b/src/conf.c index 861caf00..f55f330c 100644 --- a/src/conf.c +++ b/src/conf.c @@ -145,24 +145,27 @@ static void parse_arg(char *arg) single = 1; } -void conf_parse_cmdline(int argc, char *argv[]) +#ifdef KERNEL_CMDLINE +/* + * Parse /proc/cmdline to find args for init. Don't use this! + * + * Instead, rely on the kernel to give Finit its arguments as + * regular argc + argv[]. Only use this if the system you run + * on has a broken initramfs system that cannot forward args + * to Finit properly. + */ +static void parse_kernel_cmdline(void) { - int dbg = 0; - FILE *fp; char line[LINE_SIZE], *cmdline, *tok; - - for (int i = 1; i < argc; i++) - parse_arg(argv[i]); - - hide_args(argc, argv); + FILE *fp; fp = fopen("/proc/cmdline", "r"); if (!fp) - goto done; + return; if (!fgets(line, sizeof(line), fp)) { fclose(fp); - goto done; + return; } cmdline = chomp(line); @@ -173,8 +176,24 @@ void conf_parse_cmdline(int argc, char *argv[]) parse_arg(tok); } fclose(fp); +} +#else +#define parse_kernel_cmdline() +#endif + +/* + * Kernel gives us all non-kernel options on our cmdline + */ +void conf_parse_cmdline(int argc, char *argv[]) +{ + int dbg = 0; + + for (int i = 1; i < argc; i++) + parse_arg(argv[i]); + + hide_args(argc, argv); + parse_kernel_cmdline(); -done: log_init(dbg); }