summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormatthew <matthew@openbsd.org>2014-07-12 21:21:19 +0000
committermatthew <matthew@openbsd.org>2014-07-12 21:21:19 +0000
commitf6022b25f901b35b6563820a75aae00925b68635 (patch)
tree1f2906161c9d8cf567276ae1451a962e76ff8952
parentRemove this sentence: (diff)
downloadwireguard-openbsd-f6022b25f901b35b6563820a75aae00925b68635.tar.xz
wireguard-openbsd-f6022b25f901b35b6563820a75aae00925b68635.zip
Refactor out dosigsuspend() function
Discussed with guenther and kettenis
-rw-r--r--sys/kern/kern_sig.c27
-rw-r--r--sys/kern/sys_generic.c16
-rw-r--r--sys/sys/proc.h3
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 $ */
/*
@@ -472,6 +472,20 @@ sys_sigpending(struct proc *p, void *v, register_t *retval)
}
/*
+ * 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:
* libc stub passes mask, not pointer, to save a copyin.
@@ -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)