From patchwork Thu Jun 17 09:46:47 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Whitcroft X-Patchwork-Id: 55999 X-Patchwork-Delegate: leann.ogasawara@canonical.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id 76A42B7D64 for ; Thu, 17 Jun 2010 19:47:01 +1000 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.69) (envelope-from ) id 1OPBgT-0001Ej-Dt; Thu, 17 Jun 2010 10:46:53 +0100 Received: from adelie.canonical.com ([91.189.90.139]) by chlorine.canonical.com with esmtp (Exim 4.69) (envelope-from ) id 1OPBgR-0001Ds-2Z for kernel-team@lists.ubuntu.com; Thu, 17 Jun 2010 10:46:51 +0100 Received: from hutte.canonical.com ([91.189.90.181]) by adelie.canonical.com with esmtp (Exim 4.69 #1 (Debian)) id 1OPBgR-0007yE-12 for ; Thu, 17 Jun 2010 10:46:51 +0100 Received: from [85.210.146.14] (helo=localhost.localdomain) by hutte.canonical.com with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1OPBgQ-0002Fr-PN for kernel-team@lists.ubuntu.com; Thu, 17 Jun 2010 10:46:51 +0100 From: Andy Whitcroft To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/2] UBUNTU: SAUCE: add option to hand off all kernel parameters to init Date: Thu, 17 Jun 2010 10:46:47 +0100 Message-Id: <1276768008-16696-2-git-send-email-apw@canonical.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1276768008-16696-1-git-send-email-apw@canonical.com> References: <1276768008-16696-1-git-send-email-apw@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: kernel-team-bounces@lists.ubuntu.com Errors-To: kernel-team-bounces@lists.ubuntu.com BugLink: http://bugs.launchpad.net/bugs/586386 Some init packages such as upstart find having all of the kernel parameters passed in useful. Currently they have to open up /proc/cmdline and reparse that to obtain this information. Add a kernel configuration option to enable passing of all options. Note, enabling this option will reduce the chances that a fallback from /sbin/init to /bin/bash or /bin/sh will succeed. Though it should be noted that there are commonly unknown options present which would already break this fallback. init=/bin/foo provides explicit control over options which is unaffected by this change. Signed-off-by: Andy Whitcroft --- include/linux/moduleparam.h | 2 +- init/Kconfig | 7 +++++++ init/main.c | 33 ++++++++++++++++++++++++++------- kernel/params.c | 20 ++++++++++++++------ 4 files changed, 48 insertions(+), 14 deletions(-) diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h index 82a9124..c425126 100644 --- a/include/linux/moduleparam.h +++ b/include/linux/moduleparam.h @@ -144,7 +144,7 @@ extern int parse_args(const char *name, char *args, struct kernel_param *params, unsigned num, - int (*unknown)(char *param, char *val)); + int (*handle)(char *param, char *val, int known)); /* Called by module remove. */ #ifdef CONFIG_SYSFS diff --git a/init/Kconfig b/init/Kconfig index ce68380..fc438f8 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -75,6 +75,13 @@ config INIT_ENV_ARG_LIMIT Maximum of each of the number of arguments and environment variables passed to init from the kernel command line. +config INIT_PASS_ALL_PARAMS + bool "Pass all (known and unknown) kernel parameters to init" + default n + help + Pass all kernel command line parameters to init, this includes + those consumed by kernel modules. This is useful for upstart + based systems. If in doubt say N. config CROSS_COMPILE string "Cross-compiler tool prefix" diff --git a/init/main.c b/init/main.c index de016bc..1b1d50e 100644 --- a/init/main.c +++ b/init/main.c @@ -107,6 +107,11 @@ EXPORT_SYMBOL(system_state); */ #define MAX_INIT_ARGS CONFIG_INIT_ENV_ARG_LIMIT #define MAX_INIT_ENVS CONFIG_INIT_ENV_ARG_LIMIT +#ifdef CONFIG_INIT_PASS_ALL_PARAMS +#define INIT_PASS_FUNCTION pass_all_bootoptions +#else +#define INIT_PASS_FUNCTION pass_unknown_bootoptions +#endif extern void time_init(void); /* Default late time init is NULL. archs can override this later. */ @@ -265,10 +270,11 @@ static int __init loglevel(char *str) early_param("loglevel", loglevel); /* - * Unknown boot options get handed to init, unless they look like - * unused parameters (modprobe will find them in /proc/cmdline). + * Select boot options to hand to init. If all is set hand off them all + * otherwise only hand off unused ones which do not apply to modules + * (modprobe will find them in /proc/cmdline). */ -static int __init unknown_bootoption(char *param, char *val) +static int __init pass_bootoption(char *param, char *val, int all) { /* Change NUL term back to "=", to make "param" the whole string. */ if (val) { @@ -284,11 +290,11 @@ static int __init unknown_bootoption(char *param, char *val) } /* Handle obsolete-style parameters */ - if (obsolete_checksetup(param)) + if (obsolete_checksetup(param) && !all) return 0; /* Unused module parameter. */ - if (strchr(param, '.') && (!val || strchr(param, '.') < val)) + if (!all && strchr(param, '.') && (!val || strchr(param, '.') < val)) return 0; if (panic_later) @@ -319,6 +325,16 @@ static int __init unknown_bootoption(char *param, char *val) } return 0; } +static int __init pass_unknown_bootoptions(char *param, char *val, int known) +{ + if (known) + return 0; + return pass_bootoption(param, val, 0); +} +static int __init pass_all_bootoptions(char *param, char *val, int known) +{ + return pass_bootoption(param, val, 1); +} #ifdef CONFIG_DEBUG_PAGEALLOC int __read_mostly debug_pagealloc_enabled = 0; @@ -450,10 +466,13 @@ static noinline void __init_refok rest_init(void) } /* Check for early params. */ -static int __init do_early_param(char *param, char *val) +static int __init do_early_param(char *param, char *val, int known) { struct obs_kernel_param *p; + if (known) + return 0; + for (p = __setup_start; p < __setup_end; p++) { if ((p->early && strcmp(param, p->str) == 0) || (strcmp(param, "console") == 0 && @@ -574,7 +593,7 @@ asmlinkage void __init start_kernel(void) parse_early_param(); parse_args("Booting kernel", static_command_line, __start___param, __stop___param - __start___param, - &unknown_bootoption); + &INIT_PASS_FUNCTION); /* * These use large bootmem allocations and must precede * kmem_cache_init() diff --git a/kernel/params.c b/kernel/params.c index 0b30ecd..0267fd1 100644 --- a/kernel/params.c +++ b/kernel/params.c @@ -51,22 +51,30 @@ static int parse_one(char *param, char *val, struct kernel_param *params, unsigned num_params, - int (*handle_unknown)(char *param, char *val)) + int (*handle_arg)(char *param, char *val, int known)) { unsigned int i; /* Find parameter */ for (i = 0; i < num_params; i++) { if (parameq(param, params[i].name)) { + if (handle_arg) { + int ret; + DEBUGP("Valid argument: calling %p\n", + handle_arg); + ret = handle_arg(param, val, 1); + if (ret) + return ret; + } DEBUGP("They are equal! Calling %p\n", params[i].set); return params[i].set(val, ¶ms[i]); } } - if (handle_unknown) { - DEBUGP("Unknown argument: calling %p\n", handle_unknown); - return handle_unknown(param, val); + if (handle_arg) { + DEBUGP("Unknown argument: calling %p\n", handle_arg); + return handle_arg(param, val, 0); } DEBUGP("Unknown argument `%s'\n", param); @@ -130,7 +138,7 @@ int parse_args(const char *name, char *args, struct kernel_param *params, unsigned num, - int (*unknown)(char *param, char *val)) + int (*handle_arg)(char *param, char *val, int arg)) { char *param, *val; @@ -145,7 +153,7 @@ int parse_args(const char *name, args = next_arg(args, ¶m, &val); irq_was_disabled = irqs_disabled(); - ret = parse_one(param, val, params, num, unknown); + ret = parse_one(param, val, params, num, handle_arg); if (irq_was_disabled && !irqs_disabled()) { printk(KERN_WARNING "parse_args(): option '%s' enabled " "irq's!\n", param);