mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 10:15:57 +01:00
Workqueue attempt, but fails to insmod, already loaded??
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
obj-m += debugfs.o fops.o hello.o hello2.o
|
||||
obj-m += $(addsuffix .o, $(notdir $(basename $(wildcard $(BR2_EXTERNAL_KERNEL_MODULE_PATH)/*.c))))
|
||||
ccflags-y := -Wno-declaration-after-statement -std=gnu99
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
36
kernel_module/workqueue_cheat.c
Normal file
36
kernel_module/workqueue_cheat.c
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
/*
|
||||
Usage:
|
||||
|
||||
insmod /workqueue.ko
|
||||
# dmesg => worker
|
||||
rmmod workqueue
|
||||
|
||||
Creates a separate thread. So init_module can return, but some work will still get done.
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/workqueue.h>
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
static struct workqueue_struct *queue;
|
||||
|
||||
static void worker_func(struct work_struct *work)
|
||||
{
|
||||
printk(KERN_INFO "worker\n");
|
||||
}
|
||||
|
||||
int init_module(void)
|
||||
{
|
||||
DECLARE_WORK(work, worker_func);
|
||||
queue = create_singlethread_workqueue("myworkqueue");
|
||||
queue_work(queue, &work);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cleanup_module(void)
|
||||
{
|
||||
destroy_workqueue(queue);
|
||||
}
|
||||
Reference in New Issue
Block a user