LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-02-2011, 03:24 AM   #1
derchris
LQ Newbie
 
Registered: Feb 2011
Posts: 27

Rep: Reputation: 0
Writing to console from Kernel module


Hey guys,

I'm currently doing a tutorial for writing kernel modules. Right now I'm still at the very beginning, i.e. writing my helloworld stuff.
But what I like to do now is to write stuff onto the console, and I don't get it. According to my tutorials I can print stuff on the console using the printk()-function as long as the priority-level of the macro used in printk() is lower than the console_loglevel (how can I find that value out btw?).
But it doesn't work for me. Even if I use KERN_EMERG it still gets only logged, but not printed on the console and I thought KERN_EMERG get always printed...

FWIW, here's my code:
Code:
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kernel.h>
#include <linux/init.h>

static int a = 1;
static int b = 2;
module_param(a, int, 0);
module_param(b, int, 0);
static char *mystring = "nix";
module_param(mystring, charp, 0);

static int myStarter(void) {
    int c = a + b;
    printk(KERN_INFO "hallo welt init!\n");
    printk(KERN_EMERG "c = %d\n", c);
    return 0;
}

static void goodBye(void) {
    int i;
    for(i=0; i<b; ++i)
        printk(KERN_ALERT "Schleife: %d von %d", i+1, b);
    printk(KERN_INFO "dying... o im dying\n");
}

module_init(myStarter);
module_exit(goodBye);
Edit:
As I already posted my code, maybe someone can help me with another problem here:
If I call
Code:
insmod hello a=3 b=6 mystring="somestring"
Everything works fine. But as soon as there are any blanks in mystring, e.g.
Code:
insmod hello a=3 b=6 mystring="some blankish string"
I always get
Code:
insmod: error inserting 'hello.ko': -1 Unknown symbol in module
Why do I get this error and how can I insert string with blanks?

Last edited by derchris; 03-02-2011 at 03:35 AM.
 
Old 03-02-2011, 10:14 PM   #2
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,680
Blog Entries: 29

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
and you have already hit out Google with the following keywords:
Quote:
tldp kernel module command line arguments
?
 
Old 03-03-2011, 04:15 AM   #3
derchris
LQ Newbie
 
Registered: Feb 2011
Posts: 27

Original Poster
Rep: Reputation: 0
Yep, tlpg was the tutorial I made. There it was said that printk()-messages get printed out on the console as long as the priority value is lower (which actually means has a higher priority than) console_loglevel. But even with KERN_EMERG - the highest priority - I do not get written anything on my console
 
Old 03-03-2011, 04:28 AM   #4
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,680
Blog Entries: 29

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
I haven't worked with kernel modules for long now, but the only difference at glance I am finding in your and this module: http://tldp.org/LDP/lkmpg/2.4/html/x354.htm is
1. MODULE_PARM_DESC missing in yours
and
2. MODULE_PARM taking 3 parameters in yours, and isn't that case sensitive?
 
Old 03-03-2011, 04:51 AM   #5
derchris
LQ Newbie
 
Registered: Feb 2011
Posts: 27

Original Poster
Rep: Reputation: 0
http://lxr.linux.no/#linux+v2.6.37.2...uleparam.h#L75

As far as I know from what I read the MODULE_PARM doesn't exist anymore and was replaced with module_param.
I just made a quick test and inserted the MODULE_PARM_DESC (which is still available) but it didn't change anything with my problem. But I think that this is nothing surprising, as it is just a description
 
Old 03-03-2011, 05:01 AM   #6
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,680
Blog Entries: 29

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
You are right, that article was of 2.4 and this is of 2.6: http://tldp.org/LDP/lkmpg/2.6/html/x323.html

and in the example string too, which is very lenghthy they haven't inserted any spaces.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
linux kernel module re-writing bony Programming 1 03-20-2010 12:10 PM
How to print a message from kernel module to terminal console or tty console yogesh_bansal Linux - Newbie 2 02-27-2009 10:10 AM
Kernel Module Writing itz2000 Programming 6 10-05-2007 04:54 PM
need help in writing Makefile for module in 2.6 kernel videsh Programming 1 01-19-2006 08:35 AM
need help in writing Makefile for module in 2.6 kernel videsh Linux - Software 3 01-19-2006 08:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration