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

Re: insmod: /lib/modules/2.2.17/block/xd.o: init_module: Device or resource busy



Edouard G. Parmelan wrote:

> Georges Mariano wrote:
> 
> > (ne peut on pas avoir plus que le pid ??)
> 
> Si, bien plus, dans cette première version, tu as le pid (917) et le
> programme (wc).  Il fallait que je parte chez mon kiné, donc je n'en ai
> pas fais plus :-) Je vais regarder pour avoir plus d'info, comme le
> chemin complet du programme ala /proc/<pid>/exe.

Voila, avec le chemin complet :-)  pour le reste, à vous de jouer ...
-- 
Edouard G. Parmelan
http://egp.free.fr
/*
 * Copyright (C) 2000 Edouard G. Parmelan
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 * USA.
 */

#include <linux/module.h>
#include <linux/fs.h>
#include <linux/sched.h>
#include <linux/mm.h>

static int major = 13;

MODULE_AUTHOR("Edouard G. Parmelan <egp@free.fr>");
MODULE_PARM(major, "i");
MODULE_PARM_DESC(major, "major number");


static int trace_open (struct inode *inode, struct file *file)
{
    struct task_struct *tsk = current;
    char buf[1024];
    char *prog;

    /* lookup executable of this process */
    prog = tsk->comm;
    if (tsk->mm) {
	struct vm_area_struct *vma = tsk->mm->mmap;
	struct dentry *dentry = NULL;

	while (vma) {
	    if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file) {
		prog = d_path (vma->vm_file->f_dentry, buf, sizeof (buf));
		break;
	    }
	}
    }
    
    printk (KERN_INFO "trace: process %d %s open block-major-%d minor %d\n",
	    tsk->pid, prog, MAJOR(inode->i_rdev), MINOR(inode->i_rdev));

    return -ENODEV;
}

static struct file_operations trace_fops = {
    open: trace_open
};

int init_module(void)
{
    int error;

    if (register_blkdev (major, "trace", &trace_fops)) {
	printk (KERN_ERR "trace: Unable to get major number %d\n", major);
	return -1;
    }
    printk (KERN_INFO "trace: log activated for major number %d\n", major);

    return 0;
}

void cleanup_module (void)
{
    unregister_blkdev (major, "trace");
}

/*
 * Local variables:
 * compile-command: "gcc -DMODULE -D__KERNEL__ -I/usr/src/linux-2.2/include -c trace.c"
 * End:
 */

Reply to: