From owner-freebsd-hackers@FreeBSD.ORG Thu Mar 17 21:49:05 2005 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3D3A716A4CE for ; Thu, 17 Mar 2005 21:49:05 +0000 (GMT) Received: from mail28.sea5.speakeasy.net (mail28.sea5.speakeasy.net [69.17.117.30]) by mx1.FreeBSD.org (Postfix) with ESMTP id B024543D5C for ; Thu, 17 Mar 2005 21:49:04 +0000 (GMT) (envelope-from jmg@hydrogen.funkthat.com) Received: (qmail 9158 invoked from network); 17 Mar 2005 21:49:04 -0000 Received: from gate.funkthat.com (HELO hydrogen.funkthat.com) ([69.17.45.168]) (envelope-sender ) by mail28.sea5.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 17 Mar 2005 21:49:04 -0000 Received: from hydrogen.funkthat.com (xgpkda@localhost.funkthat.com [127.0.0.1])j2HLn3GH037002; Thu, 17 Mar 2005 13:49:03 -0800 (PST) (envelope-from jmg@hydrogen.funkthat.com) Received: (from jmg@localhost) by hydrogen.funkthat.com (8.12.10/8.12.10/Submit) id j2HLn38R037001; Thu, 17 Mar 2005 13:49:03 -0800 (PST) Date: Thu, 17 Mar 2005 13:49:03 -0800 From: John-Mark Gurney To: Aziz KEZZOU Message-ID: <20050317214903.GL89312@funkthat.com> Mail-Followup-To: Aziz KEZZOU , freebsd-hackers@freebsd.org References: <37e13166050317093477de8f7a@mail.gmail.com> <20050317181200.GK89312@funkthat.com> <37e1316605031711555c47c8ca@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <37e1316605031711555c47c8ca@mail.gmail.com> User-Agent: Mutt/1.4.1i X-Operating-System: FreeBSD 4.2-RELEASE i386 X-PGP-Fingerprint: B7 EC EF F8 AE ED A7 31 96 7A 22 B3 D8 56 36 F4 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html cc: freebsd-hackers@freebsd.org Subject: Re: How to send a signal from inside the kernel? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: John-Mark Gurney List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Mar 2005 21:49:05 -0000 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 > > > #include > > > > > > 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 /*needed only for NULL, can be removed*/ This header (unistd.h) shouldn't be included in kernel code... > #include > #include style(9) says: Kernel include files (i.e. sys/*.h) come first; normally, include OR , 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 > #include > #include -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."