Thanks. I read the variables directly and it works fine. Now I have another questions: Is there a way to dump data which I collected by reading the variables to a file in a kernel timer callback function without using printk ? Regards, Markus -----Original Message----- From: Tom Bradley [mailto:tojabr@tojabr.com] Sent: Dienstag, 25. November 2003 18:28 To: Obermeier Markus ICM MP PD TS; kernelnewbies@nl.linux.org Subject: Re: system calls in kernel timer callback functions You are trying to use functions intended for user space inside the kernel. You should never use any of the sys_* functions because most of them require a user context to interact with. Additionally, all the /proc files are are calls to the kernel to output some variables. You are already in the kernel so you can, if they are not static, just read those variables. Tom On Tuesday 25 November 2003 10:01 am, Obermeier Markus ICM MP PD TS wrote: > Hi, > > I have developped a small kernel module. It schedules a regular timer > calling the timeout function. In this timeout function I would like to > open the file /proc/net/dev from proc-filesystem. If I do, the kernel > crashes. Please see the program code below. > > How do I make system calls in timer callback function. > > Please can somebody give me a glue. > > Regards, > Markus > > >--------------------------------------------------------------------------- >--------- /* hello.c - Demonstrating the module_init() and module_exit() > macros. This is the * preferred over using init_module() and > cleanup_module(). > */ > #include <linux/module.h> // Needed by all modules > #include <linux/kernel.h> // Needed for KERN_ALERT > #include <linux/init.h> // Needed for the macros > > #include <linux/timer.h> > #include <linux/sched.h> > #include <linux/syscall.h> > #include <linux/fcntl.h> > > static struct timer_list list; > static unsigned long last_call; > static unsigned long num; > static long fd; > #define MAX_BUF 512 > static char buf[MAX_BUF]; > > static void hello_timeout(unsigned long ptr) { > printk(KERN_ALERT "Timeout %u\n",num); > if (last_call) del_timer(&list); > else { > num++; > init_timer(&list); > list.function = hello_timeout; > list.data = 0; > list.expires = jiffies + HZ; > add_timer(&list); > if ((fd=sys_open("/proc/net/dev",O_RDONLY, 0x444)) == 0) { > last_call = 0x1; > } else { > sys_read(fd, buf, MAX_BUF - 1); > buf[MAX_BUF-1] = '\0'; > printk (KERN_ALERT "Buf: %s\n",buf); > sys_close(fd); > } > } > } > > static int hello_init(void) > { > printk(KERN_ALERT "Hello, world\n"); > init_timer(&list); > list.function = hello_timeout; > list.data = 0; > list.expires = jiffies + HZ; > add_timer(&list); > return 0; > } > > > static void hello_exit(void) > { > printk(KERN_ALERT "Goodbye, world\n"); > del_timer(&list); > last_call = 0x1; > } > > > module_init(hello_init); > module_exit(hello_exit); > > > -- > Kernelnewbies: Help each other learn about the Linux kernel. > Archive: http://mail.nl.linux.org/kernelnewbies/ > FAQ: http://kernelnewbies.org/faq/ -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/