Skip to content

Commit 1319916

Browse files
mhiramatrostedt
authored andcommitted
bootconfig: init: Allow admin to use bootconfig for init command line
Since the current kernel command line is too short to describe long and many options for init (e.g. systemd command line options), this allows admin to use boot config for init command line. All init command line under "init." keywords will be passed to init. For example, init.systemd { unified_cgroup_hierarchy = 1 debug_shell default_timeout_start_sec = 60 } Link: http://lkml.kernel.org/r/157867229521.17873.654222294326542349.stgit@devnote2 Signed-off-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 51887d0 commit 1319916

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

init/main.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ char *saved_command_line;
139139
static char *static_command_line;
140140
/* Untouched extra command line */
141141
static char *extra_command_line;
142+
/* Extra init arguments */
143+
static char *extra_init_args;
142144

143145
static char *execute_command;
144146
static char *ramdisk_execute_command;
@@ -372,6 +374,8 @@ static void __init setup_boot_config(void)
372374
pr_info("Load boot config: %d bytes\n", size);
373375
/* keys starting with "kernel." are passed via cmdline */
374376
extra_command_line = xbc_make_cmdline("kernel");
377+
/* Also, "init." keys are init arguments */
378+
extra_init_args = xbc_make_cmdline("init");
375379
}
376380
}
377381
#else
@@ -507,16 +511,18 @@ static inline void smp_prepare_cpus(unsigned int maxcpus) { }
507511
*/
508512
static void __init setup_command_line(char *command_line)
509513
{
510-
size_t len, xlen = 0;
514+
size_t len, xlen = 0, ilen = 0;
511515

512516
if (extra_command_line)
513517
xlen = strlen(extra_command_line);
518+
if (extra_init_args)
519+
ilen = strlen(extra_init_args) + 4; /* for " -- " */
514520

515521
len = xlen + strlen(boot_command_line) + 1;
516522

517-
saved_command_line = memblock_alloc(len, SMP_CACHE_BYTES);
523+
saved_command_line = memblock_alloc(len + ilen, SMP_CACHE_BYTES);
518524
if (!saved_command_line)
519-
panic("%s: Failed to allocate %zu bytes\n", __func__, len);
525+
panic("%s: Failed to allocate %zu bytes\n", __func__, len + ilen);
520526

521527
static_command_line = memblock_alloc(len, SMP_CACHE_BYTES);
522528
if (!static_command_line)
@@ -533,6 +539,22 @@ static void __init setup_command_line(char *command_line)
533539
}
534540
strcpy(saved_command_line + xlen, boot_command_line);
535541
strcpy(static_command_line + xlen, command_line);
542+
543+
if (ilen) {
544+
/*
545+
* Append supplemental init boot args to saved_command_line
546+
* so that user can check what command line options passed
547+
* to init.
548+
*/
549+
len = strlen(saved_command_line);
550+
if (!strstr(boot_command_line, " -- ")) {
551+
strcpy(saved_command_line + len, " -- ");
552+
len += 4;
553+
} else
554+
saved_command_line[len++] = ' ';
555+
556+
strcpy(saved_command_line + len, extra_init_args);
557+
}
536558
}
537559

538560
/*
@@ -759,6 +781,9 @@ asmlinkage __visible void __init start_kernel(void)
759781
if (!IS_ERR_OR_NULL(after_dashes))
760782
parse_args("Setting init args", after_dashes, NULL, 0, -1, -1,
761783
NULL, set_init_arg);
784+
if (extra_init_args)
785+
parse_args("Setting extra init args", extra_init_args,
786+
NULL, 0, -1, -1, NULL, set_init_arg);
762787

763788
/*
764789
* These use large bootmem allocations and must precede

0 commit comments

Comments
 (0)