xref: /minix3/minix/kernel/system/do_kill.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc /* The kernel call that is implemented in this file:
2*433d6423SLionel Sambuc  *	m_type: SYS_KILL
3*433d6423SLionel Sambuc  *
4*433d6423SLionel Sambuc  * The parameters for this kernel call are:
5*433d6423SLionel Sambuc  *	m_sigcalls.endpt  	# process to signal/ pending
6*433d6423SLionel Sambuc  *	m_sigcalls.sig		# signal number to send to process
7*433d6423SLionel Sambuc  */
8*433d6423SLionel Sambuc 
9*433d6423SLionel Sambuc #include "kernel/system.h"
10*433d6423SLionel Sambuc #include <signal.h>
11*433d6423SLionel Sambuc 
12*433d6423SLionel Sambuc #if USE_KILL
13*433d6423SLionel Sambuc 
14*433d6423SLionel Sambuc /*===========================================================================*
15*433d6423SLionel Sambuc  *			          do_kill				     *
16*433d6423SLionel Sambuc  *===========================================================================*/
do_kill(struct proc * caller,message * m_ptr)17*433d6423SLionel Sambuc int do_kill(struct proc * caller, message * m_ptr)
18*433d6423SLionel Sambuc {
19*433d6423SLionel Sambuc /* Handle sys_kill(). Cause a signal to be sent to a process. Any request
20*433d6423SLionel Sambuc  * is added to the map of pending signals and the signal manager
21*433d6423SLionel Sambuc  * associated to the process is informed about the new signal. The signal
22*433d6423SLionel Sambuc  * is then delivered using POSIX signal handlers for user processes, or
23*433d6423SLionel Sambuc  * translated into an IPC message for system services.
24*433d6423SLionel Sambuc  */
25*433d6423SLionel Sambuc   proc_nr_t proc_nr, proc_nr_e;
26*433d6423SLionel Sambuc   int sig_nr = m_ptr->m_sigcalls.sig;
27*433d6423SLionel Sambuc 
28*433d6423SLionel Sambuc   proc_nr_e = (proc_nr_t)m_ptr->m_sigcalls.endpt;
29*433d6423SLionel Sambuc 
30*433d6423SLionel Sambuc   if (!isokendpt(proc_nr_e, &proc_nr)) return(EINVAL);
31*433d6423SLionel Sambuc   if (sig_nr >= _NSIG) return(EINVAL);
32*433d6423SLionel Sambuc   if (iskerneln(proc_nr)) return(EPERM);
33*433d6423SLionel Sambuc 
34*433d6423SLionel Sambuc   /* Set pending signal to be processed by the signal manager. */
35*433d6423SLionel Sambuc   cause_sig(proc_nr, sig_nr);
36*433d6423SLionel Sambuc 
37*433d6423SLionel Sambuc   return(OK);
38*433d6423SLionel Sambuc }
39*433d6423SLionel Sambuc 
40*433d6423SLionel Sambuc #endif /* USE_KILL */
41*433d6423SLionel Sambuc 
42