[英]Programmatically read linux kernel parameters
I am modifying a Linux driver and I'd like to programmatically read the parameters passed to kernel... in other words, my driver should act in a different way if a specific parameter is passed to Linux kernel at boot... 我正在修改Linux驱动程序,我想以编程方式读取传递给内核的参数...换句话说,如果在启动时将特定参数传递给Linux内核,我的驱动程序应以不同的方式运行...
How can I do that? 我怎样才能做到这一点?
Have I to read them from /proc/cmdline
and then program my logic? 我是否要从
/proc/cmdline
读取它们然后/proc/cmdline
我的逻辑? Or is there an API to be called for reading and parsing kernel parameters? 或者是否有一个API用于读取和解析内核参数?
Use __setup() macro. 使用__setup()宏。 See for example
__setup("ip=", ip_auto_config_setup);
参见例如
__setup("ip=", ip_auto_config_setup);
in net/ipv4/ipconfig.c 在net / ipv4 / ipconfig.c中
Linux boot time command line is copied into a global variable called saved_command_line . Linux启动时命令行被复制到名为saved_command_line的全局变量中。 It is defined in init/main.c.
它在init / main.c中定义。
Just read the variable in your module. 只需阅读模块中的变量即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.