(Forced commit, to clarify previous commit of ksiginfo/signal queue code.)

I've added a structure, kernel-private, to represent a pending or in-delivery
signal, called `ksiginfo'.  It is roughly analogous to the basic information
that is exported by the POSIX interface 'siginfo_t', but more basic.  I've
added functions to allocate these structures, and further to wrap all signal
operations using them.

Once the operations are wrapped, I've added a TailQ (see queue(3)) of these
structures to 'struct proc', and all pending signals are in that TailQ.  When
a signal is being delivered, it is dequeued from the list.  Once I finish
the spreading of ksiginfo throughout the tree, the dequeued structure will be
delivered to the process in question, whereas currently and normally, the
signal number is what is used.
This commit is contained in:
Juli Mallett 2002-10-01 00:07:28 +00:00
parent fc256ea463
commit 226e1171e1
3 changed files with 28 additions and 4 deletions

View File

@ -1227,8 +1227,11 @@ trapsignal(p, sig, code)
u_long code;
{
register struct sigacts *ps = p->p_sigacts;
struct ksiginfo *ksi;
PROC_LOCK(p);
ksiginfo_alloc(&ksi, sig);
ksi->ksi_code = code;
if ((p->p_flag & P_TRACED) == 0 && SIGISMEMBER(p->p_sigcatch, sig) &&
!SIGISMEMBER(p->p_sigmask, sig)) {
p->p_stats->p_ru.ru_nsignals++;
@ -1237,8 +1240,8 @@ trapsignal(p, sig, code)
ktrpsig(sig, ps->ps_sigact[_SIG_IDX(sig)],
&p->p_sigmask, code);
#endif
(*p->p_sysent->sv_sendsig)(ps->ps_sigact[_SIG_IDX(sig)], sig,
&p->p_sigmask, code);
(*p->p_sysent->sv_sendsig)(ps->ps_sigact[_SIG_IDX(sig)], ksi,
&p->p_sigmask);
SIGSETOR(p->p_sigmask, ps->ps_catchmask[_SIG_IDX(sig)]);
if (!SIGISMEMBER(ps->ps_signodefer, sig))
SIGADDSET(p->p_sigmask, sig);
@ -1799,6 +1802,7 @@ postsig(sig)
{
struct thread *td = curthread;
register struct proc *p = td->td_proc;
struct ksiginfo *ksi;
struct sigacts *ps;
sig_t action;
sigset_t returnmask;
@ -1808,7 +1812,7 @@ postsig(sig)
PROC_LOCK_ASSERT(p, MA_OWNED);
ps = p->p_sigacts;
signal_delete(p, NULL, sig);
ksiginfo_dequeue(&ksi, p, sig);
action = ps->ps_sigact[_SIG_IDX(sig)];
#ifdef KTRACE
if (KTRPOINT(td, KTR_PSIG))
@ -1822,6 +1826,7 @@ postsig(sig)
* Default action, where the default is to kill
* the process. (Other cases were ignored above.)
*/
ksiginfo_destroy(&ksi);
sigexit(td, sig);
/* NOTREACHED */
} else {
@ -1870,7 +1875,7 @@ postsig(sig)
if (p->p_flag & P_KSES)
if (signal_upcall(p, sig))
return;
(*p->p_sysent->sv_sendsig)(action, sig, &returnmask, code);
(*p->p_sysent->sv_sendsig)(action, ksi, &returnmask);
}
}

View File

@ -117,6 +117,23 @@ out:
return (error);
}
int
ksiginfo_to_siginfo_t(struct ksiginfo *ksi, siginfo_t *si)
{
int error;
error = 0;
si->si_addr = ksi->ksi_addr;
si->si_code = ksi->ksi_code;
si->si_errno = ksi->ksi_errno;
si->si_signo = ksi->ksi_errno;
si->si_status = ksi->ksi_status;
si->si_uid = ksi->ksi_ruid;
si->si_pid = ksi->ksi_pid;
return (error);
}
int
ksiginfo_to_sigset_t(struct proc *p, sigset_t *setp)
{

View File

@ -36,6 +36,7 @@
#endif
#include <sys/malloc.h>
#include <sys/signal.h>
/*
* Structures and prototypes for working with the in-kernel representation
@ -66,6 +67,7 @@ __BEGIN_DECLS;
int ksiginfo_alloc(struct ksiginfo **, int);
int ksiginfo_dequeue(struct ksiginfo **, struct proc *, int);
int ksiginfo_destroy(struct ksiginfo **);
int ksiginfo_to_siginfo_t(struct ksiginfo *, siginfo_t *);
int ksiginfo_to_sigset_t(struct proc *, sigset_t *);
int signal_add(struct proc *, struct ksiginfo *, int);
int signal_delete(struct proc *, struct ksiginfo *, int);