summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorVisa Hankala <visa@cvs.openbsd.org>2018-11-12 16:33:09 +0000
committerVisa Hankala <visa@cvs.openbsd.org>2018-11-12 16:33:09 +0000
commit427fb677906e634c82163da5d7ccae2c3d749cc1 (patch)
tree4661f8a03af8d54ee141b963a391b9e77e756f41 /sys
parentd95f6596166f8f28842b0e22af1190777e32a925 (diff)
Utilize sigio with pipes. This makes fcntl(fd, F_SETOWN, arg) correctly
handle arg as a process ID if the value is positive and as a process group ID if the value is negative. In addition, now the signal sending checks privileges. OK mpi@
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/sys_pipe.c16
-rw-r--r--sys/sys/pipe.h6
2 files changed, 12 insertions, 10 deletions
diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c
index 7709a64cf4e..a2cf2bbccb4 100644
--- a/sys/kern/sys_pipe.c
+++ b/sys/kern/sys_pipe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sys_pipe.c,v 1.85 2018/08/20 16:00:22 mpi Exp $ */
+/* $OpenBSD: sys_pipe.c,v 1.86 2018/11/12 16:33:08 visa Exp $ */
/*
* Copyright (c) 1996 John S. Dyson
@@ -252,6 +252,7 @@ pipe_create(struct pipe *cpipe)
cpipe->pipe_state = 0;
cpipe->pipe_peer = NULL;
cpipe->pipe_busy = 0;
+ sigio_init(&cpipe->pipe_sigio);
error = pipespace(cpipe, PIPE_SIZE);
if (error != 0)
@@ -260,7 +261,6 @@ pipe_create(struct pipe *cpipe)
getnanotime(&cpipe->pipe_ctime);
cpipe->pipe_atime = cpipe->pipe_ctime;
cpipe->pipe_mtime = cpipe->pipe_ctime;
- cpipe->pipe_pgid = NO_PID;
return (0);
}
@@ -303,8 +303,8 @@ pipeselwakeup(struct pipe *cpipe)
selwakeup(&cpipe->pipe_sel);
} else
KNOTE(&cpipe->pipe_sel.si_note, 0);
- if ((cpipe->pipe_state & PIPE_ASYNC) && cpipe->pipe_pgid != NO_PID)
- gsignal(cpipe->pipe_pgid, SIGIO);
+ if (cpipe->pipe_state & PIPE_ASYNC)
+ pgsigio(&cpipe->pipe_sigio, SIGIO, 0);
}
int
@@ -673,15 +673,14 @@ pipe_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p)
case TIOCSPGRP:
/* FALLTHROUGH */
case SIOCSPGRP:
- mpipe->pipe_pgid = *(int *)data;
- return (0);
+ return (sigio_setown(&mpipe->pipe_sigio, *(int *)data));
case SIOCGPGRP:
- *(int *)data = mpipe->pipe_pgid;
+ *(int *)data = sigio_getown(&mpipe->pipe_sigio);
return (0);
case TIOCGPGRP:
- *(int *)data = -mpipe->pipe_pgid;
+ *(int *)data = -sigio_getown(&mpipe->pipe_sigio);
break;
}
@@ -788,6 +787,7 @@ pipeclose(struct pipe *cpipe)
struct pipe *ppipe;
if (cpipe) {
pipeselwakeup(cpipe);
+ sigio_free(&cpipe->pipe_sigio);
/*
* If the other side is blocked, wake it up saying that
diff --git a/sys/sys/pipe.h b/sys/sys/pipe.h
index c08523faaa5..77740666222 100644
--- a/sys/sys/pipe.h
+++ b/sys/sys/pipe.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pipe.h,v 1.15 2013/03/25 17:21:35 deraadt Exp $ */
+/* $OpenBSD: pipe.h,v 1.16 2018/11/12 16:33:08 visa Exp $ */
/*
* Copyright (c) 1996 John S. Dyson
@@ -29,6 +29,8 @@
#include <sys/selinfo.h> /* for struct selinfo */
#endif /* _KERNEL */
+#include <sys/sigio.h> /* for struct sigio_ref */
+
/*
* Pipe buffer size, keep moderate in value, pipes take kva space.
*/
@@ -75,7 +77,7 @@ struct pipe {
struct timespec pipe_atime; /* time of last access */
struct timespec pipe_mtime; /* time of last modify */
struct timespec pipe_ctime; /* time of status change */
- int pipe_pgid; /* process/group for async I/O */
+ struct sigio_ref pipe_sigio; /* async I/O registration */
struct pipe *pipe_peer; /* link with other direction */
u_int pipe_state; /* pipe status info */
int pipe_busy; /* busy flag, mostly to handle rundown sanely */