From fdead062cd6cf0a55e87031b2e4d259b160617ba Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Wed, 1 Jul 2020 13:08:41 +0200 Subject: [PATCH] Support reading --debug et al from process command line Up until now Finit has only read /proc/cmdline to determine debug level, single user mode, etc. This patch is one in a series to make enable it to run also in containers. Signed-off-by: Joachim Nilsson --- src/conf.c | 35 +++++++++++++++++++++-------------- src/conf.h | 2 +- src/finit.c | 12 ++++++------ 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/conf.c b/src/conf.c index 52d2b563..ab8fafa1 100644 --- a/src/conf.c +++ b/src/conf.c @@ -59,12 +59,31 @@ static TAILQ_HEAD(head, conf_change) conf_change_list = TAILQ_HEAD_INITIALIZER(c static int parse_conf(char *file); static void drop_changes(void); -void conf_parse_cmdline(void) +static void parse_arg(char *arg, int *dbg) +{ + /* Catches finit_debug (deprecated), --debug, and debug */ + if (strstr(arg, "debug")) + *dbg = 1; + + if (string_compare(arg, "rescue") || string_compare(arg, "recover")) + rescue = 1; + + if (string_compare(arg, "single") || string_compare(arg, "S")) + single = 1; + + if (string_compare(arg, "splash")) + splash = 1; +} + +void conf_parse_cmdline(int argc, char *argv[]) { int dbg = 0; FILE *fp; char line[LINE_SIZE], *cmdline, *tok; + for (int i = 1; i < argc; i++) + parse_arg(argv[i], &dbg); + fp = fopen("/proc/cmdline", "r"); if (!fp) goto done; @@ -79,19 +98,7 @@ void conf_parse_cmdline(void) while ((tok = strtok(cmdline, " \t"))) { cmdline = NULL; - - /* Catches finit_debug (deprecated), --debug, and debug */ - if (strstr(tok, "debug")) - dbg = 1; - - if (string_compare(tok, "rescue") || string_compare(tok, "recover")) - rescue = 1; - - if (string_compare(tok, "single") || string_compare(tok, "S")) - single = 1; - - if (string_compare(tok, "splash")) - splash = 1; + parse_arg(tok, &dbg); } fclose(fp); diff --git a/src/conf.h b/src/conf.h index 5db2a91b..badda87a 100644 --- a/src/conf.h +++ b/src/conf.h @@ -40,7 +40,7 @@ int conf_any_change (void); int conf_changed (char *file); int conf_monitor (uev_ctx_t *ctx); -void conf_parse_cmdline (void); +void conf_parse_cmdline (int argc, char *argv[]); int conf_parse_runlevels (char *runlevels); void conf_parse_cond (svc_t *svc, char *cond); diff --git a/src/finit.c b/src/finit.c index efa5f3a9..6012b1d9 100644 --- a/src/finit.c +++ b/src/finit.c @@ -292,6 +292,12 @@ int main(int argc, char *argv[]) if (getpid() != 1) return client(argc, argv); + /* + * Parse kernel command line (debug, rescue, splash, etc.) + * Also calls log_init() to set correct log level + */ + conf_parse_cmdline(argc, argv); + /* * Hide command line arguments from ps (in particular for * forked children that don't execv()). This is an ugly @@ -320,12 +326,6 @@ int main(int argc, char *argv[]) chdir("/"); umask(0); - /* - * Parse kernel command line (debug, rescue, splash, etc.) - * Also calls log_init() to set correct log level - */ - conf_parse_cmdline(); - /* Set up canvas */ if (!rescue && !log_is_debug()) screen_init();