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 <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2020-07-01 13:08:41 +02:00
1 parent df54f5a59c
commit fdead062cd
3 files changed
+28 -21

No files matched your search

+21 -14
View File
@@ -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);