mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 10:15:57 +01:00
Workqueue works! QEMU CLI mode with -n for panic
This commit is contained in:
@@ -7,7 +7,7 @@ Usage:
|
||||
|
||||
Creates a separate thread. So init_module can return, but some work will still get done.
|
||||
|
||||
TODO why can't call this workqueue.ko?
|
||||
Can't call this just workqueue.c because there is already a built-in with that name:
|
||||
https://unix.stackexchange.com/questions/364956/how-can-insmod-fail-with-kernel-module-is-already-loaded-even-is-lsmod-does-not
|
||||
*/
|
||||
|
||||
@@ -19,14 +19,15 @@ MODULE_LICENSE("GPL");
|
||||
|
||||
static struct workqueue_struct *queue;
|
||||
|
||||
static void worker_func(struct work_struct *work)
|
||||
static void work_func(struct work_struct *work)
|
||||
{
|
||||
printk(KERN_INFO "worker\n");
|
||||
}
|
||||
|
||||
DECLARE_WORK(work, work_func);
|
||||
|
||||
int init_module(void)
|
||||
{
|
||||
DECLARE_WORK(work, worker_func);
|
||||
queue = create_singlethread_workqueue("myworkqueue");
|
||||
queue_work(queue, &work);
|
||||
return 0;
|
||||
@@ -34,5 +35,9 @@ int init_module(void)
|
||||
|
||||
void cleanup_module(void)
|
||||
{
|
||||
/* TODO why is this needed? Why flush_workqueue doesn't work? (re-insmod panics)
|
||||
* http://stackoverflow.com/questions/37216038/whats-the-difference-between-flush-delayed-work-and-cancel-delayed-work-sync */
|
||||
/*flush_workqueue(queue);*/
|
||||
cancel_work_sync(&work);
|
||||
destroy_workqueue(queue);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user