Oops+seg fault in kernel thread

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

I ´m coding a kernel thread and i have a problem when i try to unload my module.

When i rmmod my LKM , i received oops. Anybody can help me fix it ?

Thanks

 

<!--StartFragment-->#include <linux/version.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/unistd.h>
#include <linux/mm.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/highmem.h>
#include <linux/string.h>
#include <asm/uaccess.h>
#include <asm/errno.h>
#include <asm/mman.h>
#include <asm/page.h>
#include <asm/pgalloc.h>
#include <asm/processor.h>

#define KT_NAME "lock_task"

char task_image[32][20] = {{"init"},{"keventd"},{"ksoftirqd_CPU0"},{"kswapd"},{"khubd"},{"bdflush"},{"kupdated"},{"syslogd"},{"klogd"},{"crond"},{"atd"},{"rinetd"},{"mdrecoveryd"},{"sshd"},{"CHECK_STACK"},
    {"proftpd"},{"sftp-server"},{"bash"},{"insmod"},{"lock_task"},{"ls"},{"su"},{"ntop"},{"agetty"},{"ps"},{"rmmod"},{"cd"},{"cat"},{"rc.bandlimit"},{"mkdir"}};


struct mydata
{
struct semaphore comm_sema, work_sema;
struct task_struct *thread;
};


int show_all_process(void *data)
{
    struct task_struct *p = NULL;
    int aux, aux2;
   
    struct mydata *md = (struct mydata *)data;

    current->session = 1;
    current->pgrp = 1;
   
   
    siginitsetinv(&current->blocked, sigmask(SIGKILL)|sigmask(SIGINT)|sigmask(SIGTERM));
    current->fs->umask = 0;
   
    /*daemonize();*/
    sprintf(current->comm,KT_NAME);

    md->thread = current;
   
    up(&md->comm_sema);
   
    for(;;)
{

schedule_timeout(10*HZ);

if(signal_pending(current))
{
down(&md->work_sema);
break;
}
   
    for_each_task(p)
    {

if(p != NULL)
        {

aux2 = 0;
   
    for(aux = 0; aux < 32; aux++)
    {
    if(strstr(task_image[aux],p->comm) != NULL)
    aux2++;
    }
   
    if(aux2 == 0)
    {
    printk(KERN_CRIT"%s : %s\n",KT_NAME,p->comm);
    }
}

    }
}   
    
    
     md->thread = NULL;
    
     up(&md->comm_sema);
    
    
    return 0;
}


static int __init start_lock()
{
    int kth;
    struct mydata md;
   
       
        printk(KERN_CRIT"LOCK TASK : loading...\n");

init_MUTEX_LOCKED(&md.comm_sema);
init_MUTEX_LOCKED(&md.work_sema);

kth = kernel_thread(show_all_process,&md,CLONE_SIGHAND);

if (!kth)
  {
       printk(KERN_CRIT"Cannot create kernel thread\n");
   return 0;
  }

up(&md.work_sema);

schedule_timeout(20*HZ);
   
    return 0;
}


static void __exit exit_lock()
{
    int ret;   
    struct mydata md;

    printk(KERN_CRIT"Unload lock_task ...\n");
   
    ret = send_sig(SIGTERM,md.thread, 1);
   
    schedule_timeout(20*HZ);
   
    down(&md.comm_sema);
   
}

module_init(start_lock);
module_exit(exit_lock);



________________________________________________
Powered by Forum Provider version 2.2
-- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux