diff options
author | Ed Schouten <ed@FreeBSD.org> | 2015-07-29 17:18:27 +0000 |
---|---|---|
committer | Ed Schouten <ed@FreeBSD.org> | 2015-07-29 17:18:27 +0000 |
commit | 8328babdd0716967a63a23af9dee2e122bb291dc (patch) | |
tree | b3859e39cb480af3103e9c6bf3bf05ce156893d7 /sys/kern/sys_pipe.c | |
parent | e555b4309c337304587b7fda6ebda106d6854758 (diff) | |
download | src-8328babdd0716967a63a23af9dee2e122bb291dc.tar.gz src-8328babdd0716967a63a23af9dee2e122bb291dc.zip |
Make pipes in CloudABI work.
Summary:
Pipes in CloudABI are unidirectional. The reason for this is that
CloudABI attempts to provide a uniform runtime environment across
different flavours of UNIX.
Instead of implementing a custom pipe that is unidirectional, we can
simply reuse Capsicum permission bits to support this. This is nice,
because CloudABI already attempts to restrict permission bits to
correspond with the operations that apply to a certain file descriptor.
Replace kern_pipe() and kern_pipe2() by a single kern_pipe() that takes
a pair of filecaps. These filecaps are passed to the newly introduced
falloc_caps() function that creates the descriptors with rights in
place.
Test Plan:
CloudABI pipes seem to be created with proper rights in place:
https://github.com/NuxiNL/cloudlibc/blob/master/src/libc/unistd/pipe_test.c#L44
Reviewers: jilles, mjg
Reviewed By: mjg
Subscribers: imp
Differential Revision: https://reviews.freebsd.org/D3236
Notes
Notes:
svn path=/head/; revision=286021
Diffstat (limited to 'sys/kern/sys_pipe.c')
-rw-r--r-- | sys/kern/sys_pipe.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c index 70e76ad39952..a81c9dee055f 100644 --- a/sys/kern/sys_pipe.c +++ b/sys/kern/sys_pipe.c @@ -397,14 +397,8 @@ pipe_dtor(struct pipe *dpipe) * the zone pick up the pieces via pipeclose(). */ int -kern_pipe(struct thread *td, int fildes[2]) -{ - - return (kern_pipe2(td, fildes, 0)); -} - -int -kern_pipe2(struct thread *td, int fildes[2], int flags) +kern_pipe(struct thread *td, int fildes[2], int flags, struct filecaps *fcaps1, + struct filecaps *fcaps2) { struct file *rf, *wf; struct pipe *rpipe, *wpipe; @@ -414,13 +408,13 @@ kern_pipe2(struct thread *td, int fildes[2], int flags) pipe_paircreate(td, &pp); rpipe = &pp->pp_rpipe; wpipe = &pp->pp_wpipe; - error = falloc(td, &rf, &fd, flags); + error = falloc_caps(td, &rf, &fd, flags, fcaps1); if (error) { pipeclose(rpipe); pipeclose(wpipe); return (error); } - /* An extra reference on `rf' has been held for us by falloc(). */ + /* An extra reference on `rf' has been held for us by falloc_caps(). */ fildes[0] = fd; fflags = FREAD | FWRITE; @@ -434,7 +428,7 @@ kern_pipe2(struct thread *td, int fildes[2], int flags) * side while we are blocked trying to allocate the write side. */ finit(rf, fflags, DTYPE_PIPE, rpipe, &pipeops); - error = falloc(td, &wf, &fd, flags); + error = falloc_caps(td, &wf, &fd, flags, fcaps2); if (error) { fdclose(td, rf, fildes[0]); fdrop(rf, td); @@ -442,7 +436,7 @@ kern_pipe2(struct thread *td, int fildes[2], int flags) pipeclose(wpipe); return (error); } - /* An extra reference on `wf' has been held for us by falloc(). */ + /* An extra reference on `wf' has been held for us by falloc_caps(). */ finit(wf, fflags, DTYPE_PIPE, wpipe, &pipeops); fdrop(wf, td); fildes[1] = fd; @@ -458,7 +452,7 @@ sys_pipe(struct thread *td, struct pipe_args *uap) int error; int fildes[2]; - error = kern_pipe(td, fildes); + error = kern_pipe(td, fildes, 0, NULL, NULL); if (error) return (error); @@ -475,7 +469,7 @@ sys_pipe2(struct thread *td, struct pipe2_args *uap) if (uap->flags & ~(O_CLOEXEC | O_NONBLOCK)) return (EINVAL); - error = kern_pipe2(td, fildes, uap->flags); + error = kern_pipe(td, fildes, uap->flags, NULL, NULL); if (error) return (error); error = copyout(fildes, uap->fildes, 2 * sizeof(int)); |