diff -r b71655eca5e2 -r 40efa79d27dd examples/kerneltest/kernel_module.c --- a/examples/kerneltest/kernel_module.c Tue May 27 17:43:33 2008 +0200 +++ b/examples/kerneltest/kernel_module.c Mon Jun 02 08:52:06 2008 +0200 @@ -17,6 +17,9 @@ static DECLARE_MUTEX (canftest_mutex); static int canftest_stopped = 1; +int thread_start (void* data); +int thread_stop (void* data); + // handler processing write() requests from user-space ssize_t canftest_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos) @@ -30,15 +33,33 @@ // process integer as command switch (cmd) { case CMD_START: + if (!canftest_stopped) break; + thread_start_p = kthread_create (thread_start, NULL, "canftest_start"); + + if (PTR_ERR(thread_start_p) == -ENOMEM) { + printk(KERN_WARNING "canftest: error creating start thread\n"); + return -ENOMEM; + } + wake_up_process (thread_start_p); break; + case CMD_STOP: if (canftest_stopped) break; + thread_stop_p = kthread_create (thread_stop, NULL, "canftest_stop"); + + if (PTR_ERR(thread_stop_p) == -ENOMEM) { + printk(KERN_WARNING "canftest: error creating stop thread\n"); + return -ENOMEM; + } + wake_up_process (thread_stop_p); break; + // ignore new line character case 10: break; + default: printk("canftest: bad command %d\n", cmd); break; @@ -114,14 +135,6 @@ return ret; } - thread_start_p = kthread_create (thread_start, NULL, "canftest_start"); - thread_stop_p = kthread_create (thread_stop, NULL, "canftest_stop"); - - if (PTR_ERR(thread_start_p) == -ENOMEM || PTR_ERR(thread_stop_p) == -ENOMEM) { - printk(KERN_WARNING "canftest: error creating threads\n"); - return -ENOMEM; - } - return 0; }