From f6022b25f901b35b6563820a75aae00925b68635 Mon Sep 17 00:00:00 2001 From: matthew Date: Sat, 12 Jul 2014 21:21:19 +0000 Subject: [PATCH] Refactor out dosigsuspend() function Discussed with guenther and kettenis --- sys/kern/kern_sig.c | 27 ++++++++++++++++----------- sys/kern/sys_generic.c | 16 +++++----------- sys/sys/proc.h | 3 ++- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 0c6294f6b5e..28ebd811904 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sig.c,v 1.170 2014/07/11 08:18:31 guenther Exp $ */ +/* $OpenBSD: kern_sig.c,v 1.171 2014/07/12 21:21:19 matthew Exp $ */ /* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */ /* @@ -471,6 +471,20 @@ sys_sigpending(struct proc *p, void *v, register_t *retval) return (0); } +/* + * Temporarily replace calling proc's signal mask for the duration of a + * system call. Original signal mask will be restored by userret(). + */ +void +dosigsuspend(struct proc *p, sigset_t newmask) +{ + KASSERT(p == curproc); + + p->p_oldmask = p->p_sigmask; + atomic_setbits_int(&p->p_flag, P_SIGSUSPEND); + p->p_sigmask = newmask; +} + /* * Suspend process until signal, providing mask to be set * in the meantime. Note nonstandard calling convention: @@ -486,16 +500,7 @@ sys_sigsuspend(struct proc *p, void *v, register_t *retval) struct process *pr = p->p_p; struct sigacts *ps = pr->ps_sigacts; - /* - * When returning from sigpause, we want - * the old mask to be restored after the - * signal handler has finished. Thus, we - * save it here and mark the sigacts structure - * to indicate this. - */ - p->p_oldmask = p->p_sigmask; - atomic_setbits_int(&p->p_flag, P_SIGSUSPEND); - p->p_sigmask = SCARG(uap, mask) &~ sigcantmask; + dosigsuspend(p, SCARG(uap, mask) &~ sigcantmask); while (tsleep(ps, PPAUSE|PCATCH, "pause", 0) == 0) /* void */; /* always return EINTR rather than ERESTART... */ diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index b94b7dd4f8f..63d2ccb58d2 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys_generic.c,v 1.89 2014/07/12 18:43:32 tedu Exp $ */ +/* $OpenBSD: sys_generic.c,v 1.90 2014/07/12 21:21:19 matthew Exp $ */ /* $NetBSD: sys_generic.c,v 1.24 1996/03/29 00:25:32 cgd Exp $ */ /* @@ -657,11 +657,8 @@ dopselect(struct proc *p, int nd, fd_set *in, fd_set *ou, fd_set *ex, } timo = 0; - if (sigmask) { - p->p_oldmask = p->p_sigmask; - atomic_setbits_int(&p->p_flag, P_SIGSUSPEND); - p->p_sigmask = *sigmask &~ sigcantmask; - } + if (sigmask) + dosigsuspend(p, *sigmask &~ sigcantmask); retry: ncoll = nselcoll; @@ -965,11 +962,8 @@ doppoll(struct proc *p, struct pollfd *fds, u_int nfds, } timo = 0; - if (sigmask) { - p->p_oldmask = p->p_sigmask; - atomic_setbits_int(&p->p_flag, P_SIGSUSPEND); - p->p_sigmask = *sigmask &~ sigcantmask; - } + if (sigmask) + dosigsuspend(p, *sigmask &~ sigcantmask); retry: ncoll = nselcoll; diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 9ed61707e4c..d7c3224701e 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.h,v 1.188 2014/07/11 08:18:31 guenther Exp $ */ +/* $OpenBSD: proc.h,v 1.189 2014/07/12 21:21:19 matthew Exp $ */ /* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */ /*- @@ -494,6 +494,7 @@ int fork1(struct proc *, int, void *, pid_t *, void (*)(void *), void *, register_t *, struct proc **); int groupmember(gid_t, struct ucred *); void dorefreshcreds(struct process *, struct proc *); +void dosigsuspend(struct proc *, sigset_t); static inline void refreshcreds(struct proc *p) -- 2.20.1