summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormpi <mpi@openbsd.org>2020-09-09 16:29:14 +0000
committermpi <mpi@openbsd.org>2020-09-09 16:29:14 +0000
commit26c3009c2ad8fe4b0fcc8f777208dbb4ca83cce2 (patch)
treeeaaf0b5894b1aabf9d482b38d1e77de31d51e411
parentMake ogx(4)'s outbound bpf(4) tap actually work (diff)
downloadwireguard-openbsd-26c3009c2ad8fe4b0fcc8f777208dbb4ca83cce2.tar.xz
wireguard-openbsd-26c3009c2ad8fe4b0fcc8f777208dbb4ca83cce2.zip
Introduce a helper to check if a signal is ignored or masked by a thread.
ok claudio@, pirofti@
-rw-r--r--sys/kern/kern_sig.c18
-rw-r--r--sys/kern/tty.c11
-rw-r--r--sys/kern/tty_pty.c5
-rw-r--r--sys/sys/signalvar.h3
4 files changed, 25 insertions, 12 deletions
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index 1900d9044c6..6ccd55453ca 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sig.c,v 1.260 2020/08/26 03:16:53 visa Exp $ */
+/* $OpenBSD: kern_sig.c,v 1.261 2020/09/09 16:29:14 mpi Exp $ */
/* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */
/*
@@ -1486,6 +1486,22 @@ sigexit(struct proc *p, int signum)
/* NOTREACHED */
}
+/*
+ * Return 1 if `sig', a given signal, is ignored or masked for `p', a given
+ * thread, and 0 otherwise.
+ */
+int
+sigismasked(struct proc *p, int sig)
+{
+ struct process *pr = p->p_p;
+
+ if ((pr->ps_sigacts->ps_sigignore & sigmask(sig)) ||
+ (p->p_sigmask & sigmask(sig)))
+ return 1;
+
+ return 0;
+}
+
int nosuidcoredump = 1;
struct coredump_iostate {
diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index 9975c349e8b..efd8bbf5cb9 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.163 2020/07/22 17:39:50 deraadt Exp $ */
+/* $OpenBSD: tty.c,v 1.164 2020/09/09 16:29:14 mpi Exp $ */
/* $NetBSD: tty.c,v 1.68.4.2 1996/06/06 16:04:52 thorpej Exp $ */
/*-
@@ -744,8 +744,7 @@ ttioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct proc *p)
case TIOCSWINSZ:
while (isbackground(pr, tp) &&
(pr->ps_flags & PS_PPWAIT) == 0 &&
- (pr->ps_sigacts->ps_sigignore & sigmask(SIGTTOU)) == 0 &&
- (p->p_sigmask & sigmask(SIGTTOU)) == 0) {
+ !sigismasked(p, SIGTTOU)) {
if (pr->ps_pgrp->pg_jobc == 0)
return (EIO);
pgsignal(pr->ps_pgrp, SIGTTOU, 1);
@@ -1498,8 +1497,7 @@ loop: lflag = tp->t_lflag;
* Hang process if it's in the background.
*/
if (isbackground(pr, tp)) {
- if ((pr->ps_sigacts->ps_sigignore & sigmask(SIGTTIN)) ||
- (p->p_sigmask & sigmask(SIGTTIN)) ||
+ if (sigismasked(p, SIGTTIN) ||
pr->ps_flags & PS_PPWAIT || pr->ps_pgrp->pg_jobc == 0) {
error = EIO;
goto out;
@@ -1749,8 +1747,7 @@ loop:
pr = p->p_p;
if (isbackground(pr, tp) &&
ISSET(tp->t_lflag, TOSTOP) && (pr->ps_flags & PS_PPWAIT) == 0 &&
- (pr->ps_sigacts->ps_sigignore & sigmask(SIGTTOU)) == 0 &&
- (p->p_sigmask & sigmask(SIGTTOU)) == 0) {
+ !sigismasked(p, SIGTTOU)) {
if (pr->ps_pgrp->pg_jobc == 0) {
error = EIO;
goto out;
diff --git a/sys/kern/tty_pty.c b/sys/kern/tty_pty.c
index 32cec54fb74..abbda6d56ba 100644
--- a/sys/kern/tty_pty.c
+++ b/sys/kern/tty_pty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty_pty.c,v 1.103 2020/07/20 14:34:16 deraadt Exp $ */
+/* $OpenBSD: tty_pty.c,v 1.104 2020/09/09 16:29:14 mpi Exp $ */
/* $NetBSD: tty_pty.c,v 1.33.4.1 1996/06/02 09:08:11 mrg Exp $ */
/*
@@ -289,8 +289,7 @@ ptsread(dev_t dev, struct uio *uio, int flag)
again:
if (pti->pt_flags & PF_REMOTE) {
while (isbackground(pr, tp)) {
- if ((pr->ps_sigacts->ps_sigignore & sigmask(SIGTTIN)) ||
- (p->p_sigmask & sigmask(SIGTTIN)) ||
+ if (sigismasked(p, SIGTTIN) ||
pr->ps_pgrp->pg_jobc == 0 ||
pr->ps_flags & PS_PPWAIT)
return (EIO);
diff --git a/sys/sys/signalvar.h b/sys/sys/signalvar.h
index f46bbbc43be..a4c3c9f95eb 100644
--- a/sys/sys/signalvar.h
+++ b/sys/sys/signalvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: signalvar.h,v 1.41 2020/05/10 00:56:06 guenther Exp $ */
+/* $OpenBSD: signalvar.h,v 1.42 2020/09/09 16:29:14 mpi Exp $ */
/* $NetBSD: signalvar.h,v 1.17 1996/04/22 01:23:31 christos Exp $ */
/*
@@ -126,6 +126,7 @@ void siginit(struct process *);
void trapsignal(struct proc *p, int sig, u_long code, int type,
union sigval val);
void sigexit(struct proc *, int);
+int sigismasked(struct proc *, int);
int sigonstack(size_t);
void setsigvec(struct proc *, int, struct sigaction *);
int killpg1(struct proc *, int, int, int);