From owner-svn-src-head@FreeBSD.ORG Wed May 1 22:42:44 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 75A0214C; Wed, 1 May 2013 22:42:44 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 668441734; Wed, 1 May 2013 22:42:44 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r41Mgiul047989; Wed, 1 May 2013 22:42:44 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r41MggOO047980; Wed, 1 May 2013 22:42:42 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201305012242.r41MggOO047980@svn.freebsd.org> From: Jilles Tjoelker Date: Wed, 1 May 2013 22:42:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r250159 - in head: include lib/libc/sys sys/compat/freebsd32 sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 May 2013 22:42:44 -0000 Author: jilles Date: Wed May 1 22:42:42 2013 New Revision: 250159 URL: http://svnweb.freebsd.org/changeset/base/250159 Log: 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 Modified: head/include/unistd.h head/lib/libc/sys/Makefile.inc head/lib/libc/sys/Symbol.map head/lib/libc/sys/pipe.2 head/sys/compat/freebsd32/syscalls.master head/sys/kern/capabilities.conf head/sys/kern/sys_pipe.c head/sys/kern/syscalls.master Modified: head/include/unistd.h ============================================================================== --- head/include/unistd.h Wed May 1 22:16:29 2013 (r250158) +++ head/include/unistd.h Wed May 1 22:42:42 2013 (r250159) @@ -533,6 +533,7 @@ char *mktemp(char *); #endif int nfssvc(int, void *); int nlm_syscall(int, int, int, char **); +int pipe2(int *, int); int profil(char *, size_t, vm_offset_t, int); int rcmd(char **, int, const char *, const char *, const char *, int *); int rcmd_af(char **, int, const char *, Modified: head/lib/libc/sys/Makefile.inc ============================================================================== --- head/lib/libc/sys/Makefile.inc Wed May 1 22:16:29 2013 (r250158) +++ head/lib/libc/sys/Makefile.inc Wed May 1 22:42:42 2013 (r250159) @@ -352,6 +352,7 @@ MLINKS+=pathconf.2 lpathconf.2 MLINKS+=pdfork.2 pdgetpid.2\ pdfork.2 pdkill.2 \ pdfork.2 pdwait4.2 +MLINKS+=pipe.2 pipe2.2 MLINKS+=read.2 pread.2 \ read.2 preadv.2 \ read.2 readv.2 Modified: head/lib/libc/sys/Symbol.map ============================================================================== --- head/lib/libc/sys/Symbol.map Wed May 1 22:16:29 2013 (r250158) +++ head/lib/libc/sys/Symbol.map Wed May 1 22:42:42 2013 (r250159) @@ -393,6 +393,7 @@ FBSD_1.3 { ffclock_getcounter; ffclock_getestimate; ffclock_setestimate; + pipe2; posix_fadvise; wait6; }; Modified: head/lib/libc/sys/pipe.2 ============================================================================== --- head/lib/libc/sys/pipe.2 Wed May 1 22:16:29 2013 (r250158) +++ head/lib/libc/sys/pipe.2 Wed May 1 22:42:42 2013 (r250159) @@ -28,7 +28,7 @@ .\" @(#)pipe.2 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd January 30, 2006 +.Dd March 31, 2013 .Dt PIPE 2 .Os .Sh NAME @@ -40,6 +40,8 @@ .In unistd.h .Ft int .Fn pipe "int fildes[2]" +.Ft int +.Fn pipe2 "int fildes[2]" "int flags" .Sh DESCRIPTION The .Fn pipe @@ -50,6 +52,29 @@ which is an object allowing bidirectional data flow, and allocates a pair of file descriptors. .Pp +The +.Fn pipe2 +system call allows control over the attributes of the file descriptors +via the +.Fa flags +argument. +Values for +.Fa flags +are constructed by a bitwise-inclusive OR of flags from the following +list, defined in +.In fcntl.h : +.Bl -tag -width ".Dv O_NONBLOCK" +.It Dv O_CLOEXEC +Set the close-on-exec flag for the new file descriptors. +.It Dv O_NONBLOCK +Set the non-blocking flag for the ends of the pipe. +.El +.Pp +If the +.Fa flags +argument is 0, the behavior is identical to a call to +.Fn pipe . +.Pp By convention, the first descriptor is normally used as the .Em read end of the pipe, @@ -88,7 +113,9 @@ pipe in one direction. .Sh ERRORS The .Fn pipe -system call will fail if: +and +.Fn pipe2 +system calls will fail if: .Bl -tag -width Er .It Bq Er EMFILE Too many descriptors are active. @@ -97,6 +124,16 @@ The system file table is full. .It Bq Er ENOMEM Not enough kernel memory to establish a pipe. .El +.Pp +The +.Fn pipe2 +system call will also fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Fa flags +argument is invalid. +.El .Sh SEE ALSO .Xr sh 1 , .Xr fork 2 , @@ -111,3 +148,8 @@ function appeared in .Pp Bidirectional pipes were first used on .At V.4 . +.Pp +The +.Fn pipe2 +function appeared in +.Fx 10.0 . Modified: head/sys/compat/freebsd32/syscalls.master ============================================================================== --- head/sys/compat/freebsd32/syscalls.master Wed May 1 22:16:29 2013 (r250158) +++ head/sys/compat/freebsd32/syscalls.master Wed May 1 22:42:42 2013 (r250159) @@ -1026,3 +1026,4 @@ struct sockaddr * __restrict name, \ __socklen_t * __restrict anamelen, \ int flags); } +542 AUE_PIPE NOPROTO { int pipe2(int *fildes, int flags); } Modified: head/sys/kern/capabilities.conf ============================================================================== --- head/sys/kern/capabilities.conf Wed May 1 22:16:29 2013 (r250158) +++ head/sys/kern/capabilities.conf Wed May 1 22:42:42 2013 (r250159) @@ -490,6 +490,7 @@ pdkill ## Allow pipe(2). ## pipe +pipe2 ## ## Allow poll(2), which will be scoped by capability rights. Modified: head/sys/kern/sys_pipe.c ============================================================================== --- head/sys/kern/sys_pipe.c Wed May 1 22:16:29 2013 (r250158) +++ head/sys/kern/sys_pipe.c Wed May 1 22:42:42 2013 (r250159) @@ -477,6 +477,24 @@ sys_pipe(struct thread *td, struct pipe_ 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 Modified: head/sys/kern/syscalls.master ============================================================================== --- head/sys/kern/syscalls.master Wed May 1 22:16:29 2013 (r250158) +++ head/sys/kern/syscalls.master Wed May 1 22:42:42 2013 (r250159) @@ -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