发新话题
打印

[转载]工具 除去令人讨厌的模块

[转载]工具 除去令人讨厌的模块

信息来源:www.linuxforum.net

在开发的时候,大家总会碰到有些有问题的模块,加载以后,不能卸载,需要重新启动才行.(虽然可以
改个名字,但有时这会引起问题) 这个工具就是解决这个问题的.
当你确信强行卸载它是安全的,那么就用它吧.
复制内容到剪贴板
代码:
//force_del_mod ver 0.1
//coded by madsys 04.12.1 only for removing yuk module -- the mod u want to remove butu cant
//greet coolq
//tested on 2.6.9 (only for 2.6 kernel)

//NOTE: it's dangerous to use it if u dont know what u r doing

#define LINUX26

#if CONFIG_SMP==1
#define __SMP__
#endif

#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include <linux/modversions.h>
#endif


#include <linux/init.h>
#include <linux/vermagic.h>
#include <linux/kernel.h>
#include <linux/compiler.h>

#include <linux/unistd.h>
#include <linux/string.h>
#include <linux/sched.h>
#include <linux/fs.h>
#include <linux/wait.h>
#include <linux/timer.h>
#include <linux/slab.h>

#include <linux/smp.h>
#include <linux/smp_lock.h>

#include <linux/time.h>
#include <linux/file.h>
#include <linux/proc_fs.h>
#include <linux/dirent.h>
#include <linux/capability.h>
#include <linux/signal.h>
#include <linux/errno.h>
#include <asm/uaccess.h>
#include <asm/unistd.h>
#include <linux/fcntl.h>
#include <linux/spinlock.h>


static int errno;

static char *mod_name = NULL;
module_param(mod_name, charp, 0);
_syscall2(long, delete_module, const char *, name_user, unsigned int, flags)

int init_module(void)
{
   struct module *mod_head, *mod;
   struct list_head *p;
   int i;
   
   if (!mod_name)
   {
      printk("plz specify the mod_name\n");
      return -1;
   }
   
   mod_head = &__this_module;
   list_for_each(p, mod_head->list.prev){
      mod = list_entry(p, struct module, list);
      if(strcmp(mod->name, mod_name) == 0)
      {
        INIT_LIST_HEAD(&mod->modules_which_use_me);
        for (i = 0; i < NR_CPUS; i++)
            local_read(&mod->ref[i].count) = 0;
        mod->state = MODULE_STATE_LIVE;

        set_fs(get_ds());
        delete_module(mod->name, 1|O_TRUNC);
        set_fs(USER_DS);
        printk("done: %d.\n", errno);
        
        return -1;
      }
   }

   printk("cant find the module!\n");
   
   return -1;
}


MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("forcedly remove the specific module");
曾几何时,有人对我说:装B遭雷劈。我说:去你妈的。于是,这个人又对我说:如果再说脏话,上帝会惩罚你的。我说:我操上帝。结论:彪悍的人生不需要上帝。

TOP

发新话题