diff options
author | jilles <jilles@FreeBSD.org> | 2013-05-01 22:42:42 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2013-05-01 22:42:42 +0000 |
commit | 16772c421df1aaea1f268ea43b53e1b21a40be99 (patch) | |
tree | 69471087fd1663f8e867f7e487ae78525a10941b /sys/kern | |
parent | a7b320131e8beb106b450826aa74a2797328cd8b (diff) | |
download | FreeBSD-src-16772c421df1aaea1f268ea43b53e1b21a40be99.zip FreeBSD-src-16772c421df1aaea1f268ea43b53e1b21a40be99.tar.gz |
Add pipe2() system call.
The pipe2() function is similar to pipe() but allows setting FD_CLOEXEC and
O_NONBLOCK (on both sides) as part of the function.
If p points to two writable ints, pipe2(p, 0) is equivalent to pipe(p).
If the pointer is not valid, behaviour differs: pipe2() writes into the
array from the kernel like socketpair() does, while pipe() writes into the
array from an architecture-specific assembler wrapper.
Reviewed by: kan, kib
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/capabilities.conf | 1 | ||||
-rw-r--r-- | sys/kern/sys_pipe.c | 18 | ||||
-rw-r--r-- | sys/kern/syscalls.master | 1 |
3 files changed, 20 insertions, 0 deletions
diff --git a/sys/kern/capabilities.conf b/sys/kern/capabilities.conf index 0b64503..d2fa51c 100644 --- a/sys/kern/capabilities.conf +++ b/sys/kern/capabilities.conf @@ -490,6 +490,7 @@ pdkill ## Allow pipe(2). ## pipe +pipe2 ## ## Allow poll(2), which will be scoped by capability rights. diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c index 90c3022..493fee5e 100644 --- a/sys/kern/sys_pipe.c +++ b/sys/kern/sys_pipe.c @@ -477,6 +477,24 @@ sys_pipe(struct thread *td, struct pipe_args *uap) return (0); } +int +sys_pipe2(struct thread *td, struct pipe2_args *uap) +{ + int error, fildes[2]; + + if (uap->flags & ~(O_CLOEXEC | O_NONBLOCK)) + return (EINVAL); + error = kern_pipe2(td, fildes, uap->flags); + if (error) + return (error); + error = copyout(fildes, uap->fildes, 2 * sizeof(int)); + if (error) { + (void)kern_close(td, fildes[0]); + (void)kern_close(td, fildes[1]); + } + return (error); +} + /* * Allocate kva for pipe circular buffer, the space is pageable * This routine will 'realloc' the size of a pipe safely, if it fails diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master index 922db30..8668943 100644 --- a/sys/kern/syscalls.master +++ b/sys/kern/syscalls.master @@ -976,5 +976,6 @@ struct sockaddr * __restrict name, \ __socklen_t * __restrict anamelen, \ int flags); } +542 AUE_PIPE STD { int pipe2(int *fildes, int flags); } ; Please copy any additions and changes to the following compatability tables: ; sys/compat/freebsd32/syscalls.master |