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 /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 'sys')
| -rw-r--r-- | sys/compat/svr4/svr4_stream.c | 7 | ||||
| -rw-r--r-- | sys/kern/kern_descrip.c | 8 | ||||
| -rw-r--r-- | sys/kern/kern_event.c | 30 | ||||
| -rw-r--r-- | sys/kern/makesyscalls.sh | 7 | ||||
| -rw-r--r-- | sys/kern/sys_descrip.c | 85 | ||||
| -rw-r--r-- | sys/kern/sys_pipe.c | 10 | ||||
| -rw-r--r-- | sys/kern/syscalls.conf | 4 | ||||
| -rw-r--r-- | sys/kern/uipc_socket.c | 15 | ||||
| -rw-r--r-- | sys/kern/uipc_syscalls.c | 79 | ||||
| -rw-r--r-- | sys/kern/uipc_usrreq.c | 10 | ||||
| -rw-r--r-- | sys/sys/domain.h | 4 | ||||
| -rw-r--r-- | sys/sys/event.h | 3 | ||||
| -rw-r--r-- | sys/sys/fcntl.h | 3 | ||||
| -rw-r--r-- | sys/sys/filedesc.h | 4 | ||||
| -rw-r--r-- | sys/sys/socket.h | 12 | ||||
| -rw-r--r-- | sys/sys/socketvar.h | 5 | ||||
| -rw-r--r-- | sys/sys/un.h | 4 |
17 files changed, 208 insertions, 82 deletions
diff --git a/sys/compat/svr4/svr4_stream.c b/sys/compat/svr4/svr4_stream.c index c94e9dcacfa..bf356760aa9 100644 --- a/sys/compat/svr4/svr4_stream.c +++ b/sys/compat/svr4/svr4_stream.c @@ -1,4 +1,4 @@ -/* $NetBSD: svr4_stream.c,v 1.78 2010/11/19 06:44:38 dholland Exp $ */ +/* $NetBSD: svr4_stream.c,v 1.79 2011/06/26 16:42:41 christos Exp $ */ /*- * Copyright (c) 1994, 2008 The NetBSD Foundation, Inc. @@ -39,7 +39,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: svr4_stream.c,v 1.78 2010/11/19 06:44:38 dholland Exp $"); +__KERNEL_RCSID(0, "$NetBSD: svr4_stream.c,v 1.79 2011/06/26 16:42:41 christos Exp $"); #include <sys/param.h> #include <sys/kernel.h> @@ -1682,7 +1682,8 @@ svr4_sys_getmsg(struct lwp *l, const struct svr4_sys_getmsg_args *uap, register_ * We are after a listen, so we try to accept... */ - error = do_sys_accept(l, SCARG(uap, fd), &name, retval); + error = do_sys_accept(l, SCARG(uap, fd), &name, retval, + NULL, 0, FNONBLOCK); if (error != 0) { DPRINTF(("getmsg: accept failed %d\n", error)); goto out; diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 0703d4e26e2..cdef77eaba9 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_descrip.c,v 1.214 2011/04/24 20:30:38 rmind Exp $ */ +/* $NetBSD: kern_descrip.c,v 1.215 2011/06/26 16:42:41 christos Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.214 2011/04/24 20:30:38 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.215 2011/06/26 16:42:41 christos Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -729,7 +729,7 @@ fd_dup(file_t *fp, int minfd, int *newp, bool exclose) * dup2 operation. */ int -fd_dup2(file_t *fp, unsigned new) +fd_dup2(file_t *fp, unsigned new, int flags) { filedesc_t *fdp = curlwp->l_fd; fdfile_t *ff; @@ -773,6 +773,8 @@ fd_dup2(file_t *fp, unsigned new) fd_used(fdp, new); mutex_exit(&fdp->fd_lock); + dt->dt_ff[new]->ff_exclose = (flags & O_CLOEXEC) != 0; + fp->f_flag |= flags & FNONBLOCK; /* Slot is now allocated. Insert copy of the file. */ fd_affix(curproc, fp, new); if (ff != NULL) { diff --git a/sys/kern/kern_event.c b/sys/kern/kern_event.c index f426a8ce9ce..bdce62a2760 100644 --- a/sys/kern/kern_event.c +++ b/sys/kern/kern_event.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_event.c,v 1.71 2010/09/10 10:23:46 drochner Exp $ */ +/* $NetBSD: kern_event.c,v 1.72 2011/06/26 16:42:42 christos Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -58,7 +58,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.71 2010/09/10 10:23:46 drochner Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.72 2011/06/26 16:42:42 christos Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -714,8 +714,8 @@ seltrue_kqfilter(dev_t dev, struct knote *kn) /* * kqueue(2) system call. */ -int -sys_kqueue(struct lwp *l, const void *v, register_t *retval) +static int +kqueue1(struct lwp *l, int flags, register_t *retval) { struct kqueue *kq; file_t *fp; @@ -723,7 +723,7 @@ sys_kqueue(struct lwp *l, const void *v, register_t *retval) if ((error = fd_allocfile(&fp, &fd)) != 0) return error; - fp->f_flag = FREAD | FWRITE; + fp->f_flag = FREAD | FWRITE | (flags & FNONBLOCK); fp->f_type = DTYPE_KQUEUE; fp->f_ops = &kqueueops; kq = kmem_zalloc(sizeof(*kq), KM_SLEEP); @@ -734,11 +734,31 @@ sys_kqueue(struct lwp *l, const void *v, register_t *retval) fp->f_data = kq; *retval = fd; kq->kq_fdp = curlwp->l_fd; + fd_set_exclose(l, fd, (flags & O_CLOEXEC) != 0); fd_affix(curproc, fp, fd); return error; } /* + * kqueue(2) system call. + */ +int +sys_kqueue(struct lwp *l, const void *v, register_t *retval) +{ + return kqueue1(l, 0, retval); +} + +int +sys_kqueue1(struct lwp *l, const struct sys_kqueue1_args *uap, + register_t *retval) +{ + /* { + syscallarg(int) flags; + } */ + return kqueue1(l, SCARG(uap, flags), retval); +} + +/* * kevent(2) system call. */ int diff --git a/sys/kern/makesyscalls.sh b/sys/kern/makesyscalls.sh index 8c2eb6d889c..0bd6e81e302 100644 --- a/sys/kern/makesyscalls.sh +++ b/sys/kern/makesyscalls.sh @@ -1,5 +1,5 @@ #! /bin/sh - -# $NetBSD: makesyscalls.sh,v 1.118 2011/06/05 14:13:53 njoly Exp $ +# $NetBSD: makesyscalls.sh,v 1.119 2011/06/26 16:42:42 christos Exp $ # # Copyright (c) 1994, 1996, 2000 Christopher G. Demetriou # All rights reserved. @@ -283,8 +283,9 @@ NR == 1 { printf "#error Interface not supported inside kernel\n" > rumpcallshdr printf "#endif /* _KERNEL */\n\n" > rumpcallshdr printf "#include <sys/types.h> /* typedefs */\n" > rumpcallshdr - printf "#include <sys/select.h> /* typedefs */\n\n" > rumpcallshdr - printf "#include <signal.h> /* typedefs */\n\n" > rumpcallshdr + printf "#include <sys/select.h> /* typedefs */\n" > rumpcallshdr + printf "#include <sys/sigtypes.h> /* typedefs */\n" > rumpcallshdr + printf "#include <sys/socket.h> /* typedefs */\n\n" > rumpcallshdr printf "#include <rump/rump_syscalls_compat.h>\n\n" > rumpcallshdr printf "%s", sysarghdrextra > sysarghdr diff --git a/sys/kern/sys_descrip.c b/sys/kern/sys_descrip.c index fdce6c8ed93..37948e79c69 100644 --- a/sys/kern/sys_descrip.c +++ b/sys/kern/sys_descrip.c @@ -1,4 +1,4 @@ -/* $NetBSD: sys_descrip.c,v 1.21 2011/06/12 03:35:56 rmind Exp $ */ +/* $NetBSD: sys_descrip.c,v 1.22 2011/06/26 16:42:42 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sys_descrip.c,v 1.21 2011/06/12 03:35:56 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_descrip.c,v 1.22 2011/06/26 16:42:42 christos Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -122,41 +122,54 @@ sys_dup(struct lwp *l, const struct sys_dup_args *uap, register_t *retval) /* * Duplicate a file descriptor to a particular value. */ -int -sys_dup2(struct lwp *l, const struct sys_dup2_args *uap, register_t *retval) +static int +dodup(struct lwp *l, int from, int to, int flags, register_t *retval) { - /* { - syscallarg(int) from; - syscallarg(int) to; - } */ - int old, new, error; + int error; file_t *fp; - old = SCARG(uap, from); - new = SCARG(uap, to); - - if ((fp = fd_getfile(old)) == NULL) { + if ((fp = fd_getfile(from)) == NULL) return EBADF; - } mutex_enter(&fp->f_lock); fp->f_count++; mutex_exit(&fp->f_lock); - fd_putfile(old); + fd_putfile(from); - if ((u_int)new >= curproc->p_rlimit[RLIMIT_NOFILE].rlim_cur || - (u_int)new >= maxfiles) { + if ((u_int)to >= curproc->p_rlimit[RLIMIT_NOFILE].rlim_cur || + (u_int)to >= maxfiles) error = EBADF; - } else if (old == new) { + else if (from == to) error = 0; - } else { - error = fd_dup2(fp, new); - } + else + error = fd_dup2(fp, to, flags); closef(fp); - *retval = new; + *retval = to; return error; } +int +sys_dup3(struct lwp *l, const struct sys_dup3_args *uap, register_t *retval) +{ + /* { + syscallarg(int) from; + syscallarg(int) to; + syscallarg(int) flags; + } */ + return dodup(l, SCARG(uap, from), SCARG(uap, to), SCARG(uap, flags), + retval); +} + +int +sys_dup2(struct lwp *l, const struct sys_dup2_args *uap, register_t *retval) +{ + /* { + syscallarg(int) from; + syscallarg(int) to; + } */ + return dodup(l, SCARG(uap, from), SCARG(uap, to), 0, retval); +} + /* * fcntl call which is being passed to the file's fs. */ @@ -316,6 +329,7 @@ sys_fcntl(struct lwp *l, const struct sys_fcntl_args *uap, register_t *retval) filedesc_t *fdp; file_t *fp; struct flock fl; + bool cloexec = false; fd = SCARG(uap, fd); cmd = SCARG(uap, cmd); @@ -365,6 +379,9 @@ sys_fcntl(struct lwp *l, const struct sys_fcntl_args *uap, register_t *retval) } switch (cmd) { + case F_DUPFD_CLOEXEC: + cloexec = true; + /*FALLTHROUGH*/ case F_DUPFD: newmin = (long)SCARG(uap, arg); if ((u_int)newmin >= @@ -373,7 +390,7 @@ sys_fcntl(struct lwp *l, const struct sys_fcntl_args *uap, register_t *retval) fd_putfile(fd); return EINVAL; } - error = fd_dup(fp, newmin, &i, false); + error = fd_dup(fp, newmin, &i, cloexec); *retval = i; break; @@ -722,3 +739,25 @@ sys___posix_fadvise50(struct lwp *l, return 0; } + +int +sys_pipe(struct lwp *l, const void *v, register_t *retval) +{ + return pipe1(l, retval, 0); +} + +int +sys_pipe2(struct lwp *l, const struct sys_pipe2_args *uap, register_t *retval) +{ + /* { + syscallarg(int[2]) fildes; + syscallarg(int) flags; + } */ + int fd[2], error; + + if ((error = pipe1(l, retval, SCARG(uap, flags))) != 0) + return error; + fd[0] = retval[0]; + fd[1] = retval[1]; + return copyout(fd, SCARG(uap, fildes), sizeof(fd)); +} diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c index 0a902f917fb..f798f1418d6 100644 --- a/sys/kern/sys_pipe.c +++ b/sys/kern/sys_pipe.c @@ -1,4 +1,4 @@ -/* $NetBSD: sys_pipe.c,v 1.130 2011/04/10 15:45:33 christos Exp $ */ +/* $NetBSD: sys_pipe.c,v 1.131 2011/06/26 16:42:42 christos Exp $ */ /*- * Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -68,7 +68,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.130 2011/04/10 15:45:33 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.131 2011/06/26 16:42:42 christos Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -295,12 +295,6 @@ free2: return (error); } -int -sys_pipe(struct lwp *l, const void *v, register_t *retval) -{ - return pipe1(l, retval, 0); -} - /* * 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.conf b/sys/kern/syscalls.conf index a63a9b5f2ee..61598b3c235 100644 --- a/sys/kern/syscalls.conf +++ b/sys/kern/syscalls.conf @@ -1,10 +1,10 @@ -# $NetBSD: syscalls.conf,v 1.16 2011/01/18 17:33:05 pooka Exp $ +# $NetBSD: syscalls.conf,v 1.17 2011/06/26 16:42:42 christos Exp $ sysnames="syscalls.c" sysnumhdr="../sys/syscall.h" syssw="init_sysent.c" sysarghdr="../sys/syscallargs.h" -sysarghdrextra='#include <sys/mount.h>\n#include <sys/sched.h>\n\n' +sysarghdrextra='#include <sys/mount.h>\n#include <sys/sched.h>\n#include <sys/socket.h>\n\n' sysalign=1 rumpcalls="../rump/librump/rumpkern/rump_syscalls.c" rumpcallshdr="../rump/include/rump/rump_syscalls.h" diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 11a9b426888..fc7aebf176b 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_socket.c,v 1.203 2011/02/01 01:39:20 matt Exp $ */ +/* $NetBSD: uipc_socket.c,v 1.204 2011/06/26 16:42:42 christos Exp $ */ /*- * Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.203 2011/02/01 01:39:20 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.204 2011/06/26 16:42:42 christos Exp $"); #include "opt_compat_netbsd.h" #include "opt_sock_counters.h" @@ -598,10 +598,13 @@ fsocreate(int domain, struct socket **sop, int type, int protocol, struct socket *so; struct file *fp; int fd, error; + int flags = type & SOCK_FLAGS_MASK; + type &= ~SOCK_FLAGS_MASK; if ((error = fd_allocfile(&fp, &fd)) != 0) - return (error); - fp->f_flag = FREAD|FWRITE; + return error; + fd_set_exclose(l, fd, (flags & SOCK_CLOEXEC) != 0); + fp->f_flag = FREAD|FWRITE|((flags & SOCK_NONBLOCK) ? FNONBLOCK : 0); fp->f_type = DTYPE_SOCKET; fp->f_ops = &socketops; error = socreate(domain, &so, type, protocol, l, NULL); @@ -1379,7 +1382,9 @@ soreceive(struct socket *so, struct mbuf **paddr, struct uio *uio, type == SCM_RIGHTS) { sounlock(so); splx(s); - error = (*dom->dom_externalize)(cm, l); + error = (*dom->dom_externalize)(cm, l, + (flags & MSG_CMSG_CLOEXEC) ? + O_CLOEXEC : 0); s = splsoftnet(); solock(so); } diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index 6de306c38f9..a835899c475 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_syscalls.c,v 1.143 2011/04/24 18:46:23 rmind Exp $ */ +/* $NetBSD: uipc_syscalls.c,v 1.144 2011/06/26 16:42:42 christos Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.143 2011/04/24 18:46:23 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.144 2011/06/26 16:42:42 christos Exp $"); #include "opt_pipe.h" @@ -164,7 +164,8 @@ sys_listen(struct lwp *l, const struct sys_listen_args *uap, register_t *retval) } int -do_sys_accept(struct lwp *l, int sock, struct mbuf **name, register_t *new_sock) +do_sys_accept(struct lwp *l, int sock, struct mbuf **name, register_t *new_sock, + const sigset_t *mask, int flags, int clrflags) { file_t *fp, *fp2; struct mbuf *nam; @@ -186,6 +187,10 @@ do_sys_accept(struct lwp *l, int sock, struct mbuf **name, register_t *new_sock) *new_sock = fd; so = fp->f_data; solock(so); + + if (__predict_false(mask)) + sigsuspendsetup(l, mask); + if (!(so->so_proto->pr_flags & PR_LISTEN)) { error = EOPNOTSUPP; goto bad; @@ -224,7 +229,8 @@ do_sys_accept(struct lwp *l, int sock, struct mbuf **name, register_t *new_sock) if (soqremque(so2, 1) == 0) panic("accept"); fp2->f_type = DTYPE_SOCKET; - fp2->f_flag = fp->f_flag; + fp2->f_flag = (fp->f_flag & ~clrflags) | + ((flags & SOCK_NONBLOCK) ? FNONBLOCK : 0); fp2->f_ops = &socketops; fp2->f_data = so2; error = soaccept(so2, nam); @@ -239,16 +245,21 @@ do_sys_accept(struct lwp *l, int sock, struct mbuf **name, register_t *new_sock) closef(fp2); fd_abort(curproc, NULL, fd); } else { + fd_set_exclose(l, fd, (flags & SOCK_CLOEXEC) != 0); fd_affix(curproc, fp2, fd); *name = nam; } fd_putfile(sock); + if (__predict_false(mask)) + sigsuspendteardown(l); return (error); bad: sounlock(so); m_freem(nam); fd_putfile(sock); fd_abort(curproc, fp2, fd); + if (__predict_false(mask)) + sigsuspendteardown(l); return (error); } @@ -263,7 +274,46 @@ sys_accept(struct lwp *l, const struct sys_accept_args *uap, register_t *retval) int error, fd; struct mbuf *name; - error = do_sys_accept(l, SCARG(uap, s), &name, retval); + error = do_sys_accept(l, SCARG(uap, s), &name, retval, NULL, 0, 0); + if (error != 0) + return error; + error = copyout_sockname(SCARG(uap, name), SCARG(uap, anamelen), + MSG_LENUSRSPACE, name); + if (name != NULL) + m_free(name); + if (error != 0) { + fd = (int)*retval; + if (fd_getfile(fd) != NULL) + (void)fd_close(fd); + } + return error; +} + +int +sys_paccept(struct lwp *l, const struct sys_paccept_args *uap, + register_t *retval) +{ + /* { + syscallarg(int) s; + syscallarg(struct sockaddr *) name; + syscallarg(unsigned int *) anamelen; + syscallarg(const sigset_t *) mask; + syscallarg(int) flags; + } */ + int error, fd; + struct mbuf *name; + sigset_t *mask, amask; + + if (SCARG(uap, mask) != NULL) { + error = copyin(SCARG(uap, mask), &amask, sizeof(amask)); + if (error) + return error; + mask = &amask; + } else + mask = NULL; + + error = do_sys_accept(l, SCARG(uap, s), &name, retval, mask, + SCARG(uap, flags), FNONBLOCK); if (error != 0) return error; error = copyout_sockname(SCARG(uap, name), SCARG(uap, anamelen), @@ -364,26 +414,31 @@ sys_socketpair(struct lwp *l, const struct sys_socketpair_args *uap, register_t struct socket *so1, *so2; int fd, error, sv[2]; proc_t *p; + int flags = SCARG(uap, type) & SOCK_FLAGS_MASK; + int type = SCARG(uap, type) & ~SOCK_FLAGS_MASK; + int fnonblock = (flags & SOCK_NONBLOCK) ? FNONBLOCK : 0; p = curproc; - error = socreate(SCARG(uap, domain), &so1, SCARG(uap, type), + error = socreate(SCARG(uap, domain), &so1, type, SCARG(uap, protocol), l, NULL); if (error) return (error); - error = socreate(SCARG(uap, domain), &so2, SCARG(uap, type), + error = socreate(SCARG(uap, domain), &so2, type, SCARG(uap, protocol), l, so1); if (error) goto free1; if ((error = fd_allocfile(&fp1, &fd)) != 0) goto free2; + fd_set_exclose(l, fd, (flags & SOCK_CLOEXEC) != 0); sv[0] = fd; - fp1->f_flag = FREAD|FWRITE; + fp1->f_flag = FREAD|FWRITE|fnonblock; fp1->f_type = DTYPE_SOCKET; fp1->f_ops = &socketops; fp1->f_data = so1; if ((error = fd_allocfile(&fp2, &fd)) != 0) goto free3; - fp2->f_flag = FREAD|FWRITE; + fd_set_exclose(l, fd, (flags & SOCK_CLOEXEC) != 0); + fp2->f_flag = FREAD|FWRITE|fnonblock; fp2->f_type = DTYPE_SOCKET; fp2->f_ops = &socketops; fp2->f_data = so2; @@ -1006,12 +1061,6 @@ pipe1(struct lwp *l, register_t *retval, int flags) (void)soclose(rso); return (error); } - -int -sys_pipe(struct lwp *l, const void *v, register_t *retval) -{ - return pipe1(l, retval, 0); -} #endif /* PIPE_SOCKETPAIR */ /* diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 7b798d257ab..79aaf2ddd12 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_usrreq.c,v 1.135 2011/06/12 03:35:56 rmind Exp $ */ +/* $NetBSD: uipc_usrreq.c,v 1.136 2011/06/26 16:42:43 christos Exp $ */ /*- * Copyright (c) 1998, 2000, 2004, 2008, 2009 The NetBSD Foundation, Inc. @@ -96,7 +96,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.135 2011/06/12 03:35:56 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.136 2011/06/26 16:42:43 christos Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -1233,7 +1233,7 @@ unp_drain(void) #endif int -unp_externalize(struct mbuf *rights, struct lwp *l) +unp_externalize(struct mbuf *rights, struct lwp *l, int flags) { struct cmsghdr *cm = mtod(rights, struct cmsghdr *); struct proc *p = l->l_proc; @@ -1316,9 +1316,11 @@ unp_externalize(struct mbuf *rights, struct lwp *l) */ rp = (file_t **)CMSG_DATA(cm); for (i = 0; i < nfds; i++) { + int fd = fdp[i]; fp = *rp++; atomic_dec_uint(&unp_rights); - fd_affix(p, fp, fdp[i]); + fd_set_exclose(l, fd, (flags & O_CLOEXEC) != 0); + fd_affix(p, fp, fd); mutex_enter(&fp->f_lock); fp->f_msgcount--; mutex_exit(&fp->f_lock); diff --git a/sys/sys/domain.h b/sys/sys/domain.h index 8313b4861e0..f979afc4bea 100644 --- a/sys/sys/domain.h +++ b/sys/sys/domain.h @@ -1,4 +1,4 @@ -/* $NetBSD: domain.h,v 1.30 2011/03/31 19:40:54 dyoung Exp $ */ +/* $NetBSD: domain.h,v 1.31 2011/06/26 16:43:12 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1993 @@ -58,7 +58,7 @@ struct domain { void (*dom_init) /* initialize domain data structures */ (void); int (*dom_externalize) /* externalize access rights */ - (struct mbuf *, struct lwp *); + (struct mbuf *, struct lwp *, int); void (*dom_dispose) /* dispose of internalized rights */ (struct mbuf *); const struct protosw *dom_protosw, *dom_protoswNPROTOSW; diff --git a/sys/sys/event.h b/sys/sys/event.h index 4e8a9b12778..6909fabdb54 100644 --- a/sys/sys/event.h +++ b/sys/sys/event.h @@ -1,4 +1,4 @@ -/* $NetBSD: event.h,v 1.22 2011/04/24 18:46:24 rmind Exp $ */ +/* $NetBSD: event.h,v 1.23 2011/06/26 16:43:12 christos Exp $ */ /*- * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org> @@ -246,6 +246,7 @@ struct timespec; __BEGIN_DECLS #if defined(_NETBSD_SOURCE) int kqueue(void); +int kqueue1(int); #ifndef __LIBC12_SOURCE__ int kevent(int, const struct kevent *, size_t, struct kevent *, size_t, const struct timespec *) __RENAME(__kevent50); diff --git a/sys/sys/fcntl.h b/sys/sys/fcntl.h index b3e7fdea31f..a2df62538a2 100644 --- a/sys/sys/fcntl.h +++ b/sys/sys/fcntl.h @@ -1,4 +1,4 @@ -/* $NetBSD: fcntl.h,v 1.37 2011/04/10 15:45:33 christos Exp $ */ +/* $NetBSD: fcntl.h,v 1.38 2011/06/26 16:43:12 christos Exp $ */ /*- * Copyright (c) 1983, 1990, 1993 @@ -180,6 +180,7 @@ #if defined(_NETBSD_SOURCE) #define F_CLOSEM 10 /* close all fds >= to the one given */ #define F_MAXFD 11 /* return the max open fd */ +#define F_DUPFD_CLOEXEC 12 /* close on exec duplicated fd */ #endif /* file descriptor flags (F_GETFD, F_SETFD) */ diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index 91d8964171d..773b4401bf0 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -1,4 +1,4 @@ -/* $NetBSD: filedesc.h,v 1.60 2011/06/01 21:25:02 alnsn Exp $ */ +/* $NetBSD: filedesc.h,v 1.61 2011/06/26 16:43:12 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -204,7 +204,7 @@ void fd_putvnode(unsigned); void fd_putsock(unsigned); int fd_close(unsigned); int fd_dup(file_t *, int, int *, bool); -int fd_dup2(file_t *, unsigned); +int fd_dup2(file_t *, unsigned, int); int fd_clone(file_t *, unsigned, int, const struct fileops *, void *); void fd_set_exclose(struct lwp *, int, bool); int pipe1(struct lwp *, register_t *, int); diff --git a/sys/sys/socket.h b/sys/sys/socket.h index 26de37e0218..dbfb007a65b 100644 --- a/sys/sys/socket.h +++ b/sys/sys/socket.h @@ -1,4 +1,4 @@ -/* $NetBSD: socket.h,v 1.99 2011/02/01 01:39:21 matt Exp $ */ +/* $NetBSD: socket.h,v 1.100 2011/06/26 16:43:12 christos Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -97,6 +97,7 @@ typedef _BSD_SSIZE_T_ ssize_t; #endif #include <sys/uio.h> +#include <sys/sigtypes.h> /* * Socket types. @@ -107,6 +108,10 @@ typedef _BSD_SSIZE_T_ ssize_t; #define SOCK_RDM 4 /* reliably-delivered message */ #define SOCK_SEQPACKET 5 /* sequenced packet stream */ +#define SOCK_CLOEXEC 0x10000000 /* set close on exec on socket */ +#define SOCK_NONBLOCK 0x20000000 /* set non blocking i/o socket */ +#define SOCK_FLAGS_MASK 0xf0000000 /* flags mask */ + /* * Option flags per-socket. */ @@ -485,6 +490,9 @@ struct msghdr { #define MSG_BCAST 0x0100 /* this message was rcvd using link-level brdcst */ #define MSG_MCAST 0x0200 /* this message was rcvd using link-level mcast */ #define MSG_NOSIGNAL 0x0400 /* do not generate SIGPIPE on EOF */ +#if defined(_NETBSD_SOURCE) +#define MSG_CMSG_CLOEXEC 0x0800 /* close on exec receiving fd */ +#endif /* Extra flags used internally only */ #define MSG_USERFLAGS 0x0ffffff @@ -603,6 +611,8 @@ int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict); int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict); int getsockopt(int, int, int, void *__restrict, socklen_t * __restrict); int listen(int, int); +int paccept(int, struct sockaddr * __restrict, socklen_t * __restrict, + const sigset_t * __restrict, int); ssize_t recv(int, void *, size_t, int); ssize_t recvfrom(int, void *__restrict, size_t, int, struct sockaddr * __restrict, socklen_t * __restrict); diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index 040aae1d057..a0774369a45 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: socketvar.h,v 1.124 2009/12/29 04:23:43 elad Exp $ */ +/* $NetBSD: socketvar.h,v 1.125 2011/06/26 16:43:12 christos Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -350,7 +350,8 @@ int do_sys_recvmsg(struct lwp *, int, struct msghdr *, struct mbuf **, int do_sys_bind(struct lwp *, int, struct mbuf *); int do_sys_connect(struct lwp *, int, struct mbuf *); -int do_sys_accept(struct lwp *, int, struct mbuf **, register_t *); +int do_sys_accept(struct lwp *, int, struct mbuf **, register_t *, + const sigset_t *, int, int); /* * Inline functions for sockets and socket buffering. diff --git a/sys/sys/un.h b/sys/sys/un.h index 0dae3eabeed..0a4aee56eaf 100644 --- a/sys/sys/un.h +++ b/sys/sys/un.h @@ -1,4 +1,4 @@ -/* $NetBSD: un.h,v 1.45 2009/03/11 06:05:30 mrg Exp $ */ +/* $NetBSD: un.h,v 1.46 2011/06/26 16:43:12 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1993 @@ -92,7 +92,7 @@ void unp_discard (struct file *); void unp_disconnect (struct unpcb *); bool unp_drop (struct unpcb *, int); void unp_shutdown (struct unpcb *); -int unp_externalize (struct mbuf *, struct lwp *); +int unp_externalize (struct mbuf *, struct lwp *, int); int unp_internalize (struct mbuf **); void unp_dispose (struct mbuf *); int unp_output (struct mbuf *, struct mbuf *, struct unpcb *, |
