Simple Hello World error - Linux

This is a discussion on Simple Hello World error - Linux ; Hey everyone, I am running Linux kernel 2.6.17.8 with ubuntu. I wrote a simple HelloWorld program, and it is not displaying the init call on /var/log/kern.log Here's the hello.c file: #include #include #include MODULE_LICENSE("Dual BSD/GPL"); static int __init hello_init(void) { ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Simple Hello World error

  1. Simple Hello World error

    Hey everyone,

    I am running Linux kernel 2.6.17.8 with ubuntu.

    I wrote a simple HelloWorld program, and it is not displaying the init
    call on /var/log/kern.log

    Here's the hello.c file:
    #include
    #include
    #include

    MODULE_LICENSE("Dual BSD/GPL");

    static int __init hello_init(void)
    {
    printk(KERN_ALERT "Hello, world\n");
    return 0;
    }

    static void __exit hello_exit(void)
    {
    printk(KERN_ALERT "Goodbye, cruel world\n");
    }

    module_init(hello_init);
    module_exit(hello_exit);


    Here's the Makefile:
    # If KERNELRELEASE is defined, we've been invoked from the
    # kernel build system and can use its language

    ifneq ($(KERNELRELEASE),)
    obj-m := HelloWorld.o

    # Otherwise we were called directly from the command
    # line , invoke the kernel build system.
    else
    KERNELDIR ?= /lib/modules/$(shell uname -r)/build
    PWD := $(shell pwd)

    default:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

    endif

    ----
    sudo insmod ./hello.ko will not display anything in the log
    sudo rmmod hello will display the exit statement


  2. Re: Simple Hello World error


    elliotng.ee@gmail.com wrote:

    > Hey everyone,
    >
    > I am running Linux kernel 2.6.17.8 with ubuntu.
    >
    > I wrote a simple HelloWorld program, and it is not displaying the init
    > call on /var/log/kern.log
    >
    > Here's the hello.c file:
    > #include
    > #include
    > #include
    >
    > MODULE_LICENSE("Dual BSD/GPL");
    >
    > static int __init hello_init(void)
    > {
    > printk(KERN_ALERT "Hello, world\n");
    > return 0;
    > }
    >
    > static void __exit hello_exit(void)
    > {
    > printk(KERN_ALERT "Goodbye, cruel world\n");
    > }
    >
    > module_init(hello_init);
    > module_exit(hello_exit);
    >
    >
    > Here's the Makefile:
    > # If KERNELRELEASE is defined, we've been invoked from the
    > # kernel build system and can use its language
    >
    > ifneq ($(KERNELRELEASE),)
    > obj-m := HelloWorld.o
    >
    > # Otherwise we were called directly from the command
    > # line , invoke the kernel build system.
    > else
    > KERNELDIR ?= /lib/modules/$(shell uname -r)/build
    > PWD := $(shell pwd)
    >
    > default:
    > $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
    >
    > endif
    >
    > ----
    > sudo insmod ./hello.ko will not display anything in the log
    > sudo rmmod hello will display the exit statement


    It seems your klogd is having problem
    Are you able to see other messages in /var/log/kern.log. Check your
    /etc/syslog.conf for whether all kern.* messages are sent to
    /var/log/kern.log.

    Check also wheather its running "/etc/init.d/klogd status"


  3. Re: Simple Hello World error

    elliotng.ee@gmail.com wrote:
    [the code]
    > static int __init hello_init(void)
    > {
    > printk(KERN_ALERT "Hello, world\n");
    > return 0;
    > }
    >
    > static void __exit hello_exit(void)
    > {
    > printk(KERN_ALERT "Goodbye, cruel world\n");
    > }

    [the puzzle]
    > sudo insmod ./hello.ko will not display anything in the log
    > sudo rmmod hello will display the exit statement


    The printk calls are functionally identical, and the module seems to be
    fine. So why would the "Hello, world\n" disappear?

    One possibility---and I may be grasping at straws---is that an
    immediately prior printk was issued somewhere with an improperly
    terminated message:

    printk(KERN_DEBUG "No newline here");
    /* ... then later ... */
    printk(KERN_ALERT "Hello, world\n");

    This would cause the message to be folded into the previous one. Now
    imagine that you are working from the console, and KERN_DEBUG is above
    the console log level. The effect would be that since your Hello, world
    is tacked onto the tail KERN_DEBUG message, it is not shown. Do this
    and then repeat your experiment, from the system console:

    echo 8 > /proc/sys/kernel/printk

    Now you can see all the printk traffic on the console.

    Now as far as the logger is concerned, it sees all messages regardless
    of the console loglevel, but what it does with them is controled by
    /etc/syslog.conf. What does that file look like? Use the "kern.*" to
    direct them all to a file.

    When you can see everything, those kind of misformatted printk messages
    become obvious. You see stuff like

    No newline here<1>Hello, world

    The <1> is your KERN_ALERT, turning into ordinary characters.

    Just a hypothesis!


+ Reply to Thread