Reputation: 1317
I'm trying to create a proc entry. My init_module function is as below
int init_module()
{
printk(KERN_INFO "proc2:Module Loaded\n");
proc_entry=proc_create_data(proc_name,0644,NULL,&fops,NULL);
if(proc_entry==NULL)
{
printk(KERN_INFO "proc2:Error registering proc entry");
}
else
{
printk(KERN_INFO "proc2:Proc Entry Created");
}
return 0;
}
following is cleanup method
void cleanup_module()
{
printk(KERN_INFO "proc2:module unloaded");
remove_proc_entry(proc_name,proc_entry);
}
rest of program include variable definition and callback functions.
when i compile this program it compiles well.
when i use insmod
it doesn't reply me prompt.
lsmod
lists my module and shows used by one (don't know what).
dmesg
shows none of the above printk messages.
can you tell me what's wrong here?
Upvotes: 17
Views: 35130
Reputation: 722
In addition to Wayne's Answer, the kernel source says
This macro expands to dynamic_pr_debug() if CONFIG_DYNAMIC_DEBUG is set. Otherwise, if DEBUG is defined, it's equivalent to a printk with KERN_DEBUG loglevel. If DEBUG is not defined it does nothing.
Which means you'd need to either define DEBUG
or use dynamic debug.
I was able to successfully load the module with debug printk via
$ sudo insmod module-name.ko dyndbg
Upvotes: 1
Reputation: 39
Even after using echo "7" > /proc/sys/kernel/printk
, printk
didn't worked for me.
https://lwn.net/Articles/487437/ says about modified or more enhanced version of printk
called pr_**
api's (pr_info
,pr_emerg
).
I used pr_info
instead of printk
and it solved my problem.
Upvotes: 3
Reputation: 651
Try echo "7" > /proc/sys/kernel/printk
to enable all console log levels.
The numbers are corresponding to below:
#define KERN_EMERG "<0>" /* system is unusable*/
#define KERN_ALERT "<1>" /* action must be taken immediately*/
#define KERN_CRIT "<2>" /* critical conditions*/
#define KERN_ERR "<3>" /* error conditions*/
#define KERN_WARNING "<4>" /* warning conditions*/
#define KERN_NOTICE "<5>" /* normal but significant condition*/
#define KERN_INFO "<6>" /* informational*/
#define KERN_DEBUG "<7>" /* debug-level messages*/
The default number is 4, which allows console to show messages only at least in KERN_WARNING
.
That's why you cannot see log in KERN_INFO
level.
Upvotes: 26