简体   繁体   中英

Take input from the userspace in the kernel

I'm new to kernel programming and I was making changes in the memory module. The issue is that when I put in printk() statements, at the boot the output is extremely verbose and because the prints are computationally expensive it takes a lot of time to boot. I was thinking of building a toggle for it as when it boots it can ask the user to switch the prints on/off.

I have seen the sscanf() or vsscanf() but that takes input only from the already given string. I also know that it should not be logically allowed to take input like this for the matters of safety but would there be a way to make sure that can be done? Or any other approach that I'm not aware of?

Edit : For clarity what I mean to do is : turning the prints on/off on demand after the kernel is booting/booted.

If you need to configure the behavior of the kernel before it boots, you have two easy ways:

  • Since this is a debugging problem, the easiest and less intrusive option is to configure two kernels (one enabled, one disabled), and let the user select which one to boot in eg GRUB.

  • If you really need to use the very same kernel (eg some users may need it at some moment and you don't want or can't distribute several versions), then use a boot kernel parameter. Take a look at the macros and documentation at https://elixir.bootlin.com/linux/v4.17/source/include/linux/moduleparam.h

Of course, there may be other ways to take input available for you (ie from any kind of persistent storage) -- but for debugging purposes, I would suggest going for the first option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM