cmdline参数解析

    xiaoxiao2021-03-25  69

       有时需要通过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)

    转载请注明原文地址: https://ju.6miu.com/read-13758.html

    最新回复(0)