aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Whitcroft <apw@canonical.com>2010-06-17 10:46:47 +0100
committerJohn Rigby <john.rigby@linaro.org>2012-06-25 15:02:10 -0600
commit61b4401831b42da2017f34d1d7190ea270fe221f (patch)
tree72cc86bd917c54ae60710b91f0db13ea6deea8d4
parentc4e4c09b0eb4ef937b0fcd9b2a3e3fdb02538800 (diff)
UBUNTU: SAUCE: add option to hand off all kernel parameters to init
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 <apw@canonical.com> Signed-off-by: Leann Ogasawara <leann.ogasawara@canonical.com>
-rw-r--r--include/linux/dynamic_debug.h10
-rw-r--r--include/linux/moduleparam.h4
-rw-r--r--init/Kconfig7
-rw-r--r--init/main.c37
-rw-r--r--kernel/params.c20
-rw-r--r--lib/dynamic_debug.c2
6 files changed, 59 insertions, 21 deletions
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index c18257b0fa7..75949f6b6ab 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -45,7 +45,7 @@ extern __printf(2, 3)
int __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...);
extern int ddebug_dyndbg_module_param_cb(char *param, char *val,
- const char *modname);
+ const char *modname, int all);
struct device;
@@ -106,7 +106,7 @@ static inline int ddebug_remove_module(const char *mod)
}
static inline int ddebug_dyndbg_module_param_cb(char *param, char *val,
- const char *modname)
+ const char *modname, int all)
{
if (strstr(param, "dyndbg")) {
/* avoid pr_warn(), which wants pr_fmt() fully defined */
@@ -114,7 +114,11 @@ static inline int ddebug_dyndbg_module_param_cb(char *param, char *val,
"CONFIG_DYNAMIC_DEBUG builds\n");
return 0; /* allow and ignore */
}
- return -EINVAL;
+
+ if (!all)
+ return -EINVAL;
+
+ return 0;
}
#define dynamic_pr_debug(fmt, ...) \
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index d6a58065c09..827f76fdbd8 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -320,8 +320,8 @@ extern int parse_args(const char *name,
unsigned num,
s16 level_min,
s16 level_max,
- int (*unknown)(char *param, char *val,
- const char *doing));
+ int (*handle_arg)(char *param, char *val,
+ const char *doing, int known));
/* Called by module remove. */
#ifdef CONFIG_SYSFS
diff --git a/init/Kconfig b/init/Kconfig
index 8f46d1aae7d..2ad6a994c1b 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -79,6 +79,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 b0751f0bfe0..1118f3a159f 100644
--- a/init/main.c
+++ b/init/main.c
@@ -112,6 +112,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. */
@@ -226,7 +231,7 @@ static int __init loglevel(char *str)
early_param("loglevel", loglevel);
/* Change NUL term back to "=", to make "param" the whole string. */
-static int __init repair_env_string(char *param, char *val, const char *unused)
+static int __init repair_env_string(char *param, char *val, const char *unused, int known)
{
if (val) {
/* param=val or param="val"? */
@@ -243,19 +248,20 @@ static int __init repair_env_string(char *param, char *val, const char *unused)
}
/*
- * 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, const char *unused)
+static int __init pass_bootoption(char *param, char *val, const char *unused, int all)
{
- repair_env_string(param, val, unused);
+ repair_env_string(param, val, unused, all);
/* 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)
@@ -286,6 +292,16 @@ static int __init unknown_bootoption(char *param, char *val, const char *unused)
}
return 0;
}
+static int __init pass_unknown_bootoptions(char *param, char *val, const char *unused, int known)
+{
+ if (known)
+ return 0;
+ return pass_bootoption(param, val, unused, 0);
+}
+static int __init pass_all_bootoptions(char *param, char *val, const char *unused, int known)
+{
+ return pass_bootoption(param, val, unused, 1);
+}
static int __init init_setup(char *str)
{
@@ -385,10 +401,13 @@ static noinline void __init_refok rest_init(void)
}
/* Check for early params. */
-static int __init do_early_param(char *param, char *val, const char *unused)
+static int __init do_early_param(char *param, char *val, const char *unused, int known)
{
const struct obs_kernel_param *p;
+ if (known)
+ return 0;
+
for (p = __setup_start; p < __setup_end; p++) {
if ((p->early && parameq(param, p->str)) ||
(strcmp(param, "console") == 0 &&
@@ -508,7 +527,7 @@ asmlinkage void __init start_kernel(void)
parse_early_param();
parse_args("Booting kernel", static_command_line, __start___param,
__stop___param - __start___param,
- -1, -1, &unknown_bootoption);
+ -1, -1, &INIT_PASS_FUNCTION);
jump_label_init();
diff --git a/kernel/params.c b/kernel/params.c
index ed35345be53..8b8b3144793 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -90,8 +90,8 @@ static int parse_one(char *param,
unsigned num_params,
s16 min_level,
s16 max_level,
- int (*handle_unknown)(char *param, char *val,
- const char *doing))
+ int (*handle_arg)(char *param, char *val,
+ const char *doing, int known))
{
unsigned int i;
int err;
@@ -106,6 +106,14 @@ static int parse_one(char *param,
if (!val && params[i].ops->set != param_set_bool
&& params[i].ops->set != param_set_bint)
return -EINVAL;
+ if (handle_arg) {
+ int ret;
+ pr_debug("Valid argument: calling %p\n",
+ handle_arg);
+ ret = handle_arg(param, val, doing, 1);
+ if (ret)
+ return ret;
+ }
pr_debug("handling %s with %p\n", param,
params[i].ops->set);
mutex_lock(&param_lock);
@@ -115,9 +123,9 @@ static int parse_one(char *param,
}
}
- if (handle_unknown) {
+ if (handle_arg) {
pr_debug("doing %s: %s='%s'\n", doing, param, val);
- return handle_unknown(param, val, doing);
+ return handle_arg(param, val, doing, 0);
}
pr_debug("Unknown argument '%s'\n", param);
@@ -183,7 +191,7 @@ int parse_args(const char *doing,
unsigned num,
s16 min_level,
s16 max_level,
- int (*unknown)(char *param, char *val, const char *doing))
+ int (*handle_arg)(char *param, char *val, const char *doing, int arg))
{
char *param, *val;
@@ -200,7 +208,7 @@ int parse_args(const char *doing,
args = next_arg(args, &param, &val);
irq_was_disabled = irqs_disabled();
ret = parse_one(param, val, doing, params, num,
- min_level, max_level, unknown);
+ min_level, max_level, handle_arg);
if (irq_was_disabled && !irqs_disabled())
pr_warn("%s: option '%s' enabled irq's!\n",
doing, param);
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 7ca29a0a301..fa196a00bf5 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -900,7 +900,7 @@ static int ddebug_dyndbg_boot_param_cb(char *param, char *val,
* passes them to load_module(). This callback gets unknown params,
* processes dyndbg params, rejects others.
*/
-int ddebug_dyndbg_module_param_cb(char *param, char *val, const char *module)
+int ddebug_dyndbg_module_param_cb(char *param, char *val, const char *module, int all)
{
vpr_info("module: %s %s=\"%s\"\n", module, param, val);
return ddebug_dyndbg_param_cb(param, val, module, -ENOENT);