Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 326
Pratik Sampat Avatar asked Jul 27 '26 13:07

Pratik Sampat


1 Answers

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 e.g. GRUB.

  • If you really need to use the very same kernel (e.g. 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 (i.e. from any kind of persistent storage) -- but for debugging purposes, I would suggest going for the first option.

like image 88
Acorn Avatar answered Jul 29 '26 05:07

Acorn