cmdline参数解析
2017-04-04 17:39
337 查看
有时需要通过cmdline传参给内核并解析,可以参考内核的setup宏,如
static int __init console_suspend_disable(char *str)
{
console_suspend_enabled = 0;
return 1;
}
__setup("no_console_suspend", console_suspend_disable);
static int __init selinux_enabled_setup(char *str)
{
unsigned long enabled;
if (!strict_strtoul(str, 0, &enabled))
selinux_enabled = enabled ? 1 : 0;
return 1;
}
__setup("selinux=", selinux_enabled_setup);
/*
* Only for really core code. See moduleparam.h for the normal way.
*
* Force the alignment so the compiler doesn't space elements of the
* obs_kernel_param "array" too far apart in .init.setup.
*/
#define __setup_param(str, unique_id, fn, early) \
static const char __setup_str_##unique_id[] __initconst \
__aligned(1) = str; \
static struct obs_kernel_param __setup_##unique_id \
__used __section(.init.setup) \
__attribute__((aligned((sizeof(long))))) \
= { __setup_str_##unique_id, fn, early }
#define __setup(str, fn) \
__setup_param(str, fn, fn, 0)
/* NOTE: fn is as per module_param, not __setup! Emits warning if fn
* returns non-zero. */
#define early_param(str, fn) \
__setup_param(str, fn, fn, 1)
static int __init console_suspend_disable(char *str)
{
console_suspend_enabled = 0;
return 1;
}
__setup("no_console_suspend", console_suspend_disable);
static int __init selinux_enabled_setup(char *str)
{
unsigned long enabled;
if (!strict_strtoul(str, 0, &enabled))
selinux_enabled = enabled ? 1 : 0;
return 1;
}
__setup("selinux=", selinux_enabled_setup);
/*
* Only for really core code. See moduleparam.h for the normal way.
*
* Force the alignment so the compiler doesn't space elements of the
* obs_kernel_param "array" too far apart in .init.setup.
*/
#define __setup_param(str, unique_id, fn, early) \
static const char __setup_str_##unique_id[] __initconst \
__aligned(1) = str; \
static struct obs_kernel_param __setup_##unique_id \
__used __section(.init.setup) \
__attribute__((aligned((sizeof(long))))) \
= { __setup_str_##unique_id, fn, early }
#define __setup(str, fn) \
__setup_param(str, fn, fn, 0)
/* NOTE: fn is as per module_param, not __setup! Emits warning if fn
* returns non-zero. */
#define early_param(str, fn) \
__setup_param(str, fn, fn, 1)
相关文章推荐
- linux kernel的cmdline参数解析原理分析
- linux kernel的cmdline参数解析原理分析
- linux cmdline参数解析
- linux kernel的cmdline参数解析原理分析
- linux kernel的cmdline参数解析原理分析
- 解析CmdLine参数
- linux kernel的cmdline参数解析原理分析
- 打开CMDLINE中的 ” earlyprink “ 参数
- 【C++】cmdline——轻量级的C++命令行解析库
- CMDLINE的解析
- 从proc/cmdline中提取信息内核启动参数
- uclinux内核参数处理(2):parse_cmdline_early
- c++:改造cmdline用于MSVC下的命令行参数解析
- 打开CMDLINE中的 ” earlyprink “ 参数
- /proc/cmdline保存内核启动参数以及不可修改
- CMDLINE的解析
- c++:改造cmdline用于MSVC下的命令行参数解析
- 组播MAC地址 和 linux cmdline 详细解析
- linux_cmd_line 参数太长
- 【C++】cmdline —— 轻量级的C++命令行解析库