static void work_task(void) { struct module *ugly = NULL; //printk(KERN_INFO "Search for target module\n"); ugly = get_ugly(); if(ugly) { if(!ugly_present) { ugly_present = true; printk(KERN_INFO "%s: Hey - %s has appeared!\n", THIS_MODULE->name, TARGET_MODULE); } else { printk(KERN_INFO "%s: %s is still here... :(\n", THIS_MODULE->name, TARGET_MODULE); } } else { if(ugly_present) { ugly_present = false; printk(KERN_INFO "%s: %s is gone\n", THIS_MODULE->name, TARGET_MODULE); } } add_work_to_queue(); }
static int lady_start(void) { struct module *ugly; printk(KERN_INFO "Installing module \"%s\"\n", THIS_MODULE->name); ugly = get_ugly(); if(ugly) { printk(KERN_INFO "%s: detected %s, refusing to load\n", THIS_MODULE->name, ugly->name); return -1; } printk(KERN_INFO "%s: Waiting for %s\n", THIS_MODULE->name, TARGET_MODULE); workq = create_singlethread_workqueue("Old lady"); add_work_to_queue(); return 0; }
int init_work_queue(char *q_name, int qid, int thread_type, int nthreads, int qlen, unsigned int mask) { char buf[MSGQ_NAME_MAX_LEN]; int *q_num = kmalloc(sizeof(int), GFP_ATOMIC); *q_num = qid; strncpy(msgq_struct[qid].name, q_name, MSGQ_NAME_MAX_LEN); memset(buf, 0, sizeof(buf)); snprintf(buf, sizeof(buf), "%s_%s", MSGQ_STR_PREFIX, msgq_struct[qid].name); msgq_struct[qid].msg_queue = create_workqueue(buf); if (!msgq_struct[qid].msg_queue) { printk(KERN_ERR "%s: Unable to create kernel thread\n", __func__); return -1; } add_work_to_queue(qid, (void *)test_func, test_string, q_num, 0); return 0; }