diff options
| author | christos <christos@NetBSD.org> | 2011-06-26 16:42:39 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2011-06-26 16:42:39 +0000 |
| commit | bbeb5403be5330b145ad01ccdbfa305d3bf8a76d (patch) | |
| tree | d1be829e69cabc22b138aada13975946ca6ac102 /lib/libc/sys | |
| parent | 8b2572853f09a752d637652a9e7abb15ea88c254 (diff) | |
* Arrange for interfaces that create new file descriptors to be able to
set close-on-exec on creation (http://udrepper.livejournal.com/20407.html).
- Add F_DUPFD_CLOEXEC to fcntl(2).
- Add MSG_CMSG_CLOEXEC to recvmsg(2) for unix file descriptor passing.
- Add dup3(2) syscall with a flags argument for O_CLOEXEC, O_NONBLOCK.
- Add pipe2(2) syscall with a flags argument for O_CLOEXEC, O_NONBLOCK.
- Add flags SOCK_CLOEXEC, SOCK_NONBLOCK to the socket type parameter
for socket(2) and socketpair(2).
- Add new paccept(2) syscall that takes an additional sigset_t to alter
the sigmask temporarily and a flags argument to set SOCK_CLOEXEC,
SOCK_NONBLOCK.
- Add new mode character 'e' to fopen(3) and popen(3) to open pipes
and file descriptors for close on exec.
- Add new kqueue1(2) syscall with a new flags argument to open the
kqueue file descriptor with O_CLOEXEC, O_NONBLOCK.
* Fix the system calls that take socklen_t arguments to actually do so.
* Don't include userland header files (signal.h) from system header files
(rump_syscallargs.h).
* Bump libc version for the new syscalls.
Diffstat (limited to 'lib/libc/sys')
| -rw-r--r-- | lib/libc/sys/Makefile.inc | 14 | ||||
| -rw-r--r-- | lib/libc/sys/accept.2 | 46 | ||||
| -rw-r--r-- | lib/libc/sys/dup.2 | 31 | ||||
| -rw-r--r-- | lib/libc/sys/fcntl.2 | 9 | ||||
| -rw-r--r-- | lib/libc/sys/kqueue.2 | 23 | ||||
| -rw-r--r-- | lib/libc/sys/pipe.2 | 30 | ||||
| -rw-r--r-- | lib/libc/sys/recv.2 | 7 | ||||
| -rw-r--r-- | lib/libc/sys/socket.2 | 12 | ||||
| -rw-r--r-- | lib/libc/sys/socketpair.2 | 12 |
9 files changed, 156 insertions, 28 deletions
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index d68043f055e..56554af7c47 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.205 2011/03/06 17:08:15 bouyer Exp $ +# $NetBSD: Makefile.inc,v 1.206 2011/06/26 16:42:41 christos Exp $ # @(#)Makefile.inc 8.3 (Berkeley) 10/24/94 # sys sources @@ -77,7 +77,7 @@ ASM= access.S acct.S \ bind.S \ chdir.S chflags.S chmod.S chown.S chroot.S __clock_getres50.S \ __clock_gettime50.S \ - dup.S dup2.S \ + dup.S dup2.S dup3.S \ extattrctl.S \ extattr_delete_fd.S extattr_delete_file.S \ extattr_delete_link.S extattr_get_fd.S extattr_get_file.S \ @@ -92,7 +92,7 @@ ASM= access.S acct.S \ getpriority.S getrlimit.S __getrusage50.S getsid.S \ getsockname.S getsockopt.S __gettimeofday50.S \ ioctl.S \ - kqueue.S ktrace.S \ + kqueue.S kqueue1.S ktrace.S \ _ksem_close.S _ksem_destroy.S _ksem_getvalue.S _ksem_init.S \ _ksem_post.S _ksem_trywait.S _ksem_unlink.S _ksem_wait.S \ _ksem_open.S \ @@ -107,8 +107,9 @@ ASM= access.S acct.S \ mlock.S mlockall.S modctl.S __mount50.S mprotect.S \ __msgctl50.S msgget.S munlock.S munlockall.S munmap.S \ nfssvc.S __ntp_gettime50.S \ - pathconf.S pmc_get_info.S pmc_control.S __posix_chown.S \ - __posix_fchown.S __posix_lchown.S __posix_rename.S profil.S \ + paccept.S pathconf.S pipe2.S pmc_get_info.S pmc_control.S \ + __posix_chown.S __posix_fchown.S __posix_lchown.S \ + __posix_rename.S profil.S \ __quotactl50.S \ rasctl.S reboot.S recvfrom.S recvmsg.S rename.S revoke.S \ rmdir.S \ @@ -242,6 +243,7 @@ MLINKS+=_exit.2 _Exit.2 MLINKS+=brk.2 sbrk.2 MLINKS+=clone.2 __clone.2 MLINKS+=dup.2 dup2.2 +MLINKS+=dup.2 dup3.2 MLINKS+=chdir.2 fchdir.2 MLINKS+=chflags.2 fchflags.2 chflags.2 lchflags.2 MLINKS+=chmod.2 fchmod.2 chmod.2 lchmod.2 @@ -308,3 +310,5 @@ MLINKS+=truncate.2 ftruncate.2 MLINKS+=utimes.2 futimes.2 utimes.2 lutimes.2 MLINKS+=wait.2 wait3.2 wait.2 wait4.2 wait.2 waitpid.2 MLINKS+=write.2 writev.2 write.2 pwrite.2 write.2 pwritev.2 +MLINKS+=pipe.2 pipe2.2 +MLINKS+=accept.2 paccept.2 diff --git a/lib/libc/sys/accept.2 b/lib/libc/sys/accept.2 index 9c7ea975d5b..d9b02af6cdd 100644 --- a/lib/libc/sys/accept.2 +++ b/lib/libc/sys/accept.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: accept.2,v 1.26 2011/06/02 01:04:18 yamt Exp $ +.\" $NetBSD: accept.2,v 1.27 2011/06/26 16:42:41 christos Exp $ .\" .\" Copyright (c) 1983, 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -33,7 +33,8 @@ .Dt ACCEPT 2 .Os .Sh NAME -.Nm accept +.Nm accept , +.Nm paccept .Nd accept a connection on a socket .Sh LIBRARY .Lb libc @@ -41,6 +42,8 @@ .In sys/socket.h .Ft int .Fn accept "int s" "struct sockaddr * restrict addr" "socklen_t * restrict addrlen" +.Ft int +.Fn paccept "int s" "struct sockaddr * restrict addr" "socklen_t * restrict addrlen" "const sigset_t * restrict sigmask" "int flags" .Sh DESCRIPTION The argument .Fa s @@ -131,12 +134,41 @@ by issuing a call with providing only the control information, or by calling .Xr setsockopt 2 . +.Pp +The +.Fn paccept +function behaves exactly like +.Fn accept , +but it also allows to set the following +.Fa flags +on the returned file descriptor: +.Bl -column SOCK_NONBLOCK -offset indent +.It Dv SOCK_CLOEXEC +Set the close on exec property. +.It Dv SOCK_NONBLOCK +Sets non-blocking I/O. +.El +.Pp +It can also temporarily replace the signal mask of the calling thread if +.Fa sigmask +is a non-null pointer, then the +.Fn paccept +function shall replace the signal mask of the caller by the set of +signals pointed to by +.Fa sigmask +before waiting for a connection, and shall restore the signal mask +of the calling thread before returning. .Sh RETURN VALUES -The call returns \-1 on error. -If it succeeds, it returns a non-negative +The +.Fn accept +and +.Fn paccept calls return \-1 on error. +If they succeed, they return a non-negative integer that is a descriptor for the accepted socket. .Sh COMPATIBILITY -This implementation makes the new file descriptor inherit file flags +The +.Fn accept +implementation makes the new file descriptor inherit file flags (like .Dv O_NONBLOCK ) from the listening socket. @@ -192,3 +224,7 @@ The .Fn accept function appeared in .Bx 4.2 . +The +.Fn pselect +function is inspired from Linux and appeared in +.Nx 6.0 . diff --git a/lib/libc/sys/dup.2 b/lib/libc/sys/dup.2 index 6cf0d51849a..2edfb4e7151 100644 --- a/lib/libc/sys/dup.2 +++ b/lib/libc/sys/dup.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: dup.2,v 1.21 2009/01/11 02:46:30 christos Exp $ +.\" $NetBSD: dup.2,v 1.22 2011/06/26 16:42:41 christos Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,12 +29,13 @@ .\" .\" @(#)dup.2 8.1 (Berkeley) 6/4/93 .\" -.Dd December 2, 2008 +.Dd June 24, 2011 .Dt DUP 2 .Os .Sh NAME .Nm dup , -.Nm dup2 +.Nm dup2 , +.Nm dup3 .Nd duplicate an existing file descriptor .Sh LIBRARY .Lb libc @@ -44,6 +45,8 @@ .Fn dup "int oldd" .Ft int .Fn dup2 "int oldd" "int newd" +.Ft int +.Fn dup3 "int oldd" "int newd" "int flags" .Sh DESCRIPTION .Fn dup duplicates an existing object descriptor and returns its value to @@ -100,6 +103,20 @@ If and .Fa oldd are the same, the call has no effect. +.Pp +.Fn dup3 +behaves exactly like +.Fn dup2 +only it allows extra +.Fa flags +to be set on the returned file descriptor. +The following flags are valid: +.Bl -column O_NONBLOCK -offset indent +.It Dv O_CLOEXEC +Set the close on exec property. +.It Dv O_NONBLOCK +Sets non-blocking I/O. +.El .Sh RETURN VALUES The value \-1 is returned if an error occurs in either call. The external variable @@ -107,8 +124,9 @@ The external variable indicates the cause of the error. .Sh ERRORS .Fn dup -and .Fn dup2 +and +.Fn dup3 fail if: .Bl -tag -width Er .It Bq Er EBADF @@ -136,3 +154,8 @@ and .Fn dup2 functions conform to .St -p1003.1-90 . +.Sh HISTORY +The +.Fn dup3 +function is inspired from Linux and appeared in +.Nx 6.0 . diff --git a/lib/libc/sys/fcntl.2 b/lib/libc/sys/fcntl.2 index a22fe0496f6..c9bc29f4f15 100644 --- a/lib/libc/sys/fcntl.2 +++ b/lib/libc/sys/fcntl.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: fcntl.2,v 1.37 2010/05/17 12:16:43 jruoho Exp $ +.\" $NetBSD: fcntl.2,v 1.38 2011/06/26 16:42:41 christos Exp $ .\" .\" Copyright (c) 1983, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)fcntl.2 8.2 (Berkeley) 1/12/94 .\" -.Dd May 17, 2010 +.Dd June 25, 2011 .Dt FCNTL 2 .Os .Sh NAME @@ -55,7 +55,7 @@ and is technically a pointer to void, but it is interpreted as an int by some commands and ignored by others. .Pp Commands are: -.Bl -tag -width F_GETOWNX +.Bl -tag -width F_DUPFD_CLOEXEC .It Dv F_DUPFD Return a new descriptor as follows: .Pp @@ -80,6 +80,9 @@ is cleared to remain open across .Xr execve 2 system calls. .El +.It Dv F_DUPFD_CLOEXEC +Same as F_DUPFD, but sets the close-on-exec property on the file descriptor +created. .It Dv F_GETFD Get the close-on-exec flag associated with the file descriptor .Fa fd diff --git a/lib/libc/sys/kqueue.2 b/lib/libc/sys/kqueue.2 index 37e263bd11b..cbda791346d 100644 --- a/lib/libc/sys/kqueue.2 +++ b/lib/libc/sys/kqueue.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: kqueue.2,v 1.30 2011/05/24 02:31:11 ryo Exp $ +.\" $NetBSD: kqueue.2,v 1.31 2011/06/26 16:42:41 christos Exp $ .\" .\" Copyright (c) 2000 Jonathan Lemon .\" All rights reserved. @@ -32,11 +32,12 @@ .\" .\" $FreeBSD: src/lib/libc/sys/kqueue.2,v 1.22 2001/06/27 19:55:57 dd Exp $ .\" -.Dd April 13, 2010 +.Dd June 24, 2011 .Dt KQUEUE 2 .Os .Sh NAME .Nm kqueue , +.Nm kqueue1 , .Nm kevent .Nd kernel event notification mechanism .Sh LIBRARY @@ -47,6 +48,8 @@ .Ft int .Fn kqueue "void" .Ft int +.Fn kqueue1 "int flags" +.Ft int .Fn kevent "int kq" "const struct kevent *changelist" "size_t nchanges" "struct kevent *eventlist" "size_t nevents" "const struct timespec *timeout" .Fn EV_SET "\*[Am]kev" ident filter flags fflags data udata .Sh DESCRIPTION @@ -78,6 +81,18 @@ on a file descriptor will remove any kevents that reference the descriptor. .Pp .Fn kqueue creates a new kernel event queue and returns a descriptor. +.Pp +The +.Fn kqueue1 +also allows to set the following +.Fa flags +on the returned file descriptor: +.Bl -column O_NONBLOCK -offset indent +.It Dv O_CLOEXEC +Set the close on exec property. +.It Dv O_NONBLOCK +Sets non-blocking I/O. +.El The queue is not inherited by a child created with .Xr fork 2 . .\" However, if @@ -617,3 +632,7 @@ functions first appeared in .Fx 4.1 , and then in .Nx 2.0 . +The +.Fn kqueue1 +function first appeared in +.Nx 6.0 . diff --git a/lib/libc/sys/pipe.2 b/lib/libc/sys/pipe.2 index 98dac5a51c6..e11af9e39d6 100644 --- a/lib/libc/sys/pipe.2 +++ b/lib/libc/sys/pipe.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: pipe.2,v 1.22 2004/05/13 10:20:58 wiz Exp $ +.\" $NetBSD: pipe.2,v 1.23 2011/06/26 16:42:41 christos Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)pipe.2 8.1 (Berkeley) 6/4/93 .\" -.Dd July 17, 1994 +.Dd June 24, 2011 .Dt PIPE 2 .Os .Sh NAME @@ -41,6 +41,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 @@ -78,6 +80,22 @@ signal. Widowing a pipe is the only way to deliver end-of-file to a reader: after the reader consumes any buffered data, reading a widowed pipe returns a zero count. +.Pp +The +.Fn pipe2 +function +behaves exactly like +.Fn pipe +only it allows extra +.Fa flags +to be set on the returned file descriptor. +The following flags are valid: +.Bl -column O_NONBLOCK -offset indent +.It Dv O_CLOEXEC +Set the close on exec property. +.It Dv O_NONBLOCK +Sets non-blocking I/O. +.El .Sh RETURN VALUES On successful creation of the pipe, zero is returned. Otherwise, a value of \-1 is returned and the variable @@ -87,7 +105,9 @@ error. .Sh ERRORS The .Fn pipe -call will fail if: +and +.Fn pipe2 +calls will fail if: .Bl -tag -width Er .It Bq Er EMFILE Too many descriptors are active. @@ -117,3 +137,7 @@ A .Fn pipe function call appeared in .At v6 . +The +.Fn pipe2 +function is inspired from Linux and appeared in +.Nx 6.0 . diff --git a/lib/libc/sys/recv.2 b/lib/libc/sys/recv.2 index 134cdb17dce..5152788c39c 100644 --- a/lib/libc/sys/recv.2 +++ b/lib/libc/sys/recv.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: recv.2,v 1.27 2006/04/23 19:06:59 wiz Exp $ +.\" $NetBSD: recv.2,v 1.28 2011/06/26 16:42:41 christos Exp $ .\" .\" Copyright (c) 1983, 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)recv.2 8.3 (Berkeley) 2/21/94 .\" -.Dd April 23, 2006 +.Dd June 24, 2011 .Dt RECV 2 .Os .Sh NAME @@ -116,7 +116,8 @@ The argument to a recv call is formed by .Em or Ap ing one or more of the values: -.Bl -column MSG_WAITALL -offset indent +.Bl -column MSG_CMSG_CLOEXEC -offset indent +.It Dv MSG_CMSG_CLOEXEC Ta set the close on exec property for passed file descriptors .It Dv MSG_OOB Ta process out-of-band data .It Dv MSG_PEEK Ta peek at incoming message .It Dv MSG_WAITALL Ta wait for full request or error diff --git a/lib/libc/sys/socket.2 b/lib/libc/sys/socket.2 index e13148b630d..f1966908900 100644 --- a/lib/libc/sys/socket.2 +++ b/lib/libc/sys/socket.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: socket.2,v 1.36 2007/09/06 09:32:52 jnemeth Exp $ +.\" $NetBSD: socket.2,v 1.37 2011/06/26 16:42:41 christos Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -78,6 +78,16 @@ SOCK_SEQPACKET SOCK_RDM .Ed .Pp +The following flags can be or'ed to the type to condition the returned +file descriptor: +The following flags are valid: +.Bl -column SOCK_NONBLOCK -offset indent +.It Dv SOCK_CLOEXEC +Set the close on exec property. +.It Dv SOCK_NONBLOCK +Sets non-blocking I/O. +.El +.Pp A .Dv SOCK_STREAM type provides sequenced, reliable, diff --git a/lib/libc/sys/socketpair.2 b/lib/libc/sys/socketpair.2 index ac64b0cf932..b7ec20a11a1 100644 --- a/lib/libc/sys/socketpair.2 +++ b/lib/libc/sys/socketpair.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: socketpair.2,v 1.21 2009/12/20 02:16:40 wiz Exp $ +.\" $NetBSD: socketpair.2,v 1.22 2011/06/26 16:42:41 christos Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)socketpair.2 8.1 (Berkeley) 6/4/93 .\" -.Dd December 20, 2009 +.Dd June 24, 2011 .Dt SOCKETPAIR 2 .Os .Sh NAME @@ -57,6 +57,13 @@ are returned in and .Fa sv Ns [1] . The two sockets are indistinguishable. +.Pp +The +.Fa type +and +.Fa protocol +argument values are described in +.Xr socket 2 . .Sh RETURN VALUES A 0 is returned if the call succeeds, \-1 if it fails. .Sh ERRORS @@ -81,6 +88,7 @@ The specified protocol is not supported on this machine. .Sh SEE ALSO .Xr pipe 2 , .Xr read 2 , +.Xr socket 2 , .Xr write 2 .Sh HISTORY The |
