Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 17 Mar 2005 13:49:03 -0800
From:      John-Mark Gurney <gurney_j@resnet.uoregon.edu>
To:        Aziz KEZZOU <opensource.enthousiat@gmail.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: How to send a signal from inside the kernel?
Message-ID:  <20050317214903.GL89312@funkthat.com>
In-Reply-To: <37e1316605031711555c47c8ca@mail.gmail.com>
References:  <37e13166050317093477de8f7a@mail.gmail.com> <20050317181200.GK89312@funkthat.com> <37e1316605031711555c47c8ca@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Aziz KEZZOU wrote this message on Thu, Mar 17, 2005 at 14:55 -0500:
> > Aziz KEZZOU wrote this message on Thu, Mar 17, 2005 at 12:34 -0500:
> > > Hi all,
> > > I would like to send a signal (e.g SIGUSR1) to a user process from
> > > inside the kernel (kld module).
> > > Can any one tell me how to do it ?
> > > I tried the following code inspired from sys/kern/kern_sig.c :
> > > ==============================================================
> > > #include <sys/types.h>
> > > #include <sys/signal.h>
> > >
> > > int process_pid;
> > > struct kill_args {
> > >       int     pid;
> > >       int     signum;
> > > };
> > >
> > > void send_SIGUSR1() {
> > >   struct kill_args uap;
> > >   uap.pid = process_pid;
> > >   uap.signum = SIGUSR1;
> > >   kill((struct thread *)0, &uap);
> > > }
> > > ===============================================================
> > >
> > > but that causes a page fault in kernel mode (ie. Kernel panic :-)
> > >
> > > Any help is appreciated, thanks.
> > 
> > Take a look at psignal(9)...  You'll need to look up the struct proc
> > for psignal with pfind(9)...   and then PROC_UNLOCK the struct proc
> > after you've used psignal...
> > 
> > so:
> > struct proc *p;
> > 
> > p = pfind(pid);
> > if (p != NULL) {
> >         psignal(p, SIGUSR1);
> >         PROC_UNLOCK(p);
> > }
> > 
> > I haven't tried the code above, but that should do what you want...
> 
> It works, thanks a lot !!
> Here are the headers needed in case someone reads this thread:
> 
> #include <unistd.h> /*needed only for NULL, can be removed*/

This header (unistd.h) shouldn't be included in kernel code...

> #include <sys/types.h>
> #include <sys/param.h>

style(9) says:
     Kernel include files (i.e. sys/*.h) come first; normally, include
     <sys/types.h> OR <sys/param.h>, but not both.

It also looks like sys/param.h is suppose to define NULL since it
includes _null.h (on -current) or defines it directly (on RELENG_4)...  

so you could should just include sys/param.h, and ditch sys/types.h
and unistd.h and it should work...

> #include <sys/lock.h>
> #include <sys/mutex.h>
> #include <sys/proc.h> 

-- 
  John-Mark Gurney				Voice: +1 415 225 5579

     "All that I will do, has been done, All that I have, has not."



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050317214903.GL89312>