How to ignore messages from printk information?
Recently, I wrote an application, in this application, I call system() function, like:
system("modprobe ipmi_si 2>/dev/null");
But unfortunately, there will display some of messages like:
ipmi_si: Trying 'kcs' at I/O port 0xca2
It may cause my application chaos in screen when application run in character console.
So I want to ignore these messages.
First, I add a line in /etc/sysctl.conf like 'kernel.printk = 0' (actually I don't know how to set it, I just guess it.)
It seems ok, when I reload this file (sysctl -p), and run my application again, no warning message again.
However, I don't think this is a good idea for me, because I just want to ignore these messages when console run my application.
If I set variable in /etc/sysctl.conf, it will impact all of application. right?
So do you have any suggestion about this issue? What can I do with my application to ignore warning messages from kernel?
Can this issue solve in my application with some code?
Any suggestion will be appreciation!
Thanks in advance!!
The message you see is (I guess) the info that ipmi_si sends to stdout. Your system call already redirects stderr (if I understand your code), so you have to add stdout to it.
On the commandline, the command would look something like
&> /dev/null my also be used.
Thanks for your help!
I just execute this command in shell console.
modprobe impi_si >/dev/null 2>&1
and modprobe ipmi_si &>/dev/null
There have 5 messages:
ipmi_si: Trying "kcs" at I/O port 0xca2
ipmi_si: Trying "smic" at I/O port 0xca9
ipmi_si: Trying "bt" at I/O port 0xe4
ipmi_si: Unable to find any System Interface(s)
FATAL: Error inserting ipmi_si(/lib...): No such device
When I used >/dev/null, it just only ignore the last message.
Can I have another way to ignore these messages?
Thanks a lot!
However, now, I find a way to solve my problem.
system("sysctl -w kernel.printk='4 4 1 7'");
Maybe it is not a good method, but it can work.
|All times are GMT -5. The time now is 10:49 PM.|