Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Support FD_CLOEXEC in rump kernels.



details:   https://anonhg.NetBSD.org/src/rev/c4578935f721
branches:  trunk
changeset: 762096:c4578935f721
user:      pooka <pooka%NetBSD.org@localhost>
date:      Tue Feb 15 15:54:28 2011 +0000

description:
Support FD_CLOEXEC in rump kernels.

diffstat:

 sys/kern/kern_descrip.c          |  55 ++++++++++++++++++++++++++++++++-
 sys/kern/kern_exec.c             |   5 +-
 sys/kern/subr_exec_fd.c          |  65 +--------------------------------------
 sys/kern/vfs_cwd.c               |  15 ++++++++-
 sys/rump/librump/rumpkern/rump.c |   8 +---
 sys/sys/filedesc.h               |   3 +-
 6 files changed, 76 insertions(+), 75 deletions(-)

diffs (269 lines):

diff -r ec24a41dc1b6 -r c4578935f721 sys/kern/kern_descrip.c
--- a/sys/kern/kern_descrip.c   Tue Feb 15 15:18:37 2011 +0000
+++ b/sys/kern/kern_descrip.c   Tue Feb 15 15:54:28 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_descrip.c,v 1.210 2011/01/28 18:44:44 pooka Exp $ */
+/*     $NetBSD: kern_descrip.c,v 1.211 2011/02/15 15:54:28 pooka 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.210 2011/01/28 18:44:44 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.211 2011/02/15 15:54:28 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1691,6 +1691,57 @@
 }
 
 /*
+ * Close open files on exec.
+ */
+void
+fd_closeexec(void)
+{
+       proc_t *p;
+       filedesc_t *fdp;
+       fdfile_t *ff;
+       lwp_t *l;
+       fdtab_t *dt;
+       int fd;
+
+       l = curlwp;
+       p = l->l_proc;
+       fdp = p->p_fd;
+
+       if (fdp->fd_refcnt > 1) {
+               fdp = fd_copy();
+               fd_free();
+               p->p_fd = fdp;
+               l->l_fd = fdp;
+       }
+       if (!fdp->fd_exclose) {
+               return;
+       }
+       fdp->fd_exclose = false;
+       dt = fdp->fd_dt;
+
+       for (fd = 0; fd <= fdp->fd_lastfile; fd++) {
+               if ((ff = dt->dt_ff[fd]) == NULL) {
+                       KASSERT(fd >= NDFDFILE);
+                       continue;
+               }
+               KASSERT(fd >= NDFDFILE ||
+                   ff == (fdfile_t *)fdp->fd_dfdfile[fd]);
+               if (ff->ff_file == NULL)
+                       continue;
+               if (ff->ff_exclose) {
+                       /*
+                        * We need a reference to close the file.
+                        * No other threads can see the fdfile_t at
+                        * this point, so don't bother locking.
+                        */
+                       KASSERT((ff->ff_refcnt & FR_CLOSING) == 0);
+                       ff->ff_refcnt++;
+                       fd_close(fd);
+               }
+       }
+}
+
+/*
  * Sets descriptor owner. If the owner is a process, 'pgid'
  * is set to positive value, process ID. If the owner is process group,
  * 'pgid' is set to -pg_id.
diff -r ec24a41dc1b6 -r c4578935f721 sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c      Tue Feb 15 15:18:37 2011 +0000
+++ b/sys/kern/kern_exec.c      Tue Feb 15 15:54:28 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_exec.c,v 1.305 2011/01/18 08:21:03 matt Exp $     */
+/*     $NetBSD: kern_exec.c,v 1.306 2011/02/15 15:54:28 pooka Exp $    */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -59,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.305 2011/01/18 08:21:03 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.306 2011/02/15 15:54:28 pooka Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_modular.h"
@@ -951,6 +951,7 @@
                goto exec_abort;
        }
 
+       cwdexec();
        fd_closeexec();         /* handle close on exec */
        execsigs(p);            /* reset catched signals */
 
diff -r ec24a41dc1b6 -r c4578935f721 sys/kern/subr_exec_fd.c
--- a/sys/kern/subr_exec_fd.c   Tue Feb 15 15:18:37 2011 +0000
+++ b/sys/kern/subr_exec_fd.c   Tue Feb 15 15:54:28 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_exec_fd.c,v 1.4 2010/11/19 06:44:43 dholland Exp $        */
+/*     $NetBSD: subr_exec_fd.c,v 1.5 2011/02/15 15:54:28 pooka Exp $   */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -26,12 +26,8 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-/*
- * File descriptor related subroutines for exec.
- */
-
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_exec_fd.c,v 1.4 2010/11/19 06:44:43 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_exec_fd.c,v 1.5 2011/02/15 15:54:28 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/file.h>
@@ -42,63 +38,6 @@
 #include <sys/vnode.h>
 
 /*
- * Close open files on exec.
- */
-void
-fd_closeexec(void)
-{
-       proc_t *p;
-       filedesc_t *fdp;
-       fdfile_t *ff;
-       lwp_t *l;
-       fdtab_t *dt;
-       int fd;
-
-       l = curlwp;
-       p = l->l_proc;
-       fdp = p->p_fd;
-
-       cwdunshare(p);
-
-       if (p->p_cwdi->cwdi_edir) {
-               vrele(p->p_cwdi->cwdi_edir);
-       }
-
-       if (fdp->fd_refcnt > 1) {
-               fdp = fd_copy();
-               fd_free();
-               p->p_fd = fdp;
-               l->l_fd = fdp;
-       }
-       if (!fdp->fd_exclose) {
-               return;
-       }
-       fdp->fd_exclose = false;
-       dt = fdp->fd_dt;
-
-       for (fd = 0; fd <= fdp->fd_lastfile; fd++) {
-               if ((ff = dt->dt_ff[fd]) == NULL) {
-                       KASSERT(fd >= NDFDFILE);
-                       continue;
-               }
-               KASSERT(fd >= NDFDFILE ||
-                   ff == (fdfile_t *)fdp->fd_dfdfile[fd]);
-               if (ff->ff_file == NULL)
-                       continue;
-               if (ff->ff_exclose) {
-                       /*
-                        * We need a reference to close the file.
-                        * No other threads can see the fdfile_t at
-                        * this point, so don't bother locking.
-                        */
-                       KASSERT((ff->ff_refcnt & FR_CLOSING) == 0);
-                       ff->ff_refcnt++;
-                       fd_close(fd);
-               }
-       }
-}
-
-/*
  * It is unsafe for set[ug]id processes to be started with file
  * descriptors 0..2 closed, as these descriptors are given implicit
  * significance in the Standard C library.  fdcheckstd() will create a
diff -r ec24a41dc1b6 -r c4578935f721 sys/kern/vfs_cwd.c
--- a/sys/kern/vfs_cwd.c        Tue Feb 15 15:18:37 2011 +0000
+++ b/sys/kern/vfs_cwd.c        Tue Feb 15 15:54:28 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_cwd.c,v 1.3 2010/01/08 11:35:10 pooka Exp $        */
+/*     $NetBSD: vfs_cwd.c,v 1.4 2011/02/15 15:54:28 pooka Exp $        */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_cwd.c,v 1.3 2010/01/08 11:35:10 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_cwd.c,v 1.4 2011/02/15 15:54:28 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -148,3 +148,14 @@
                vrele(cwdi->cwdi_edir);
        pool_cache_put(cwdi_cache, cwdi);
 }
+
+void
+cwdexec(struct proc *p)
+{
+
+       cwdunshare(p);
+
+       if (p->p_cwdi->cwdi_edir) {
+               vrele(p->p_cwdi->cwdi_edir);
+       }
+}
diff -r ec24a41dc1b6 -r c4578935f721 sys/rump/librump/rumpkern/rump.c
--- a/sys/rump/librump/rumpkern/rump.c  Tue Feb 15 15:18:37 2011 +0000
+++ b/sys/rump/librump/rumpkern/rump.c  Tue Feb 15 15:54:28 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rump.c,v 1.230 2011/02/15 10:35:05 pooka Exp $ */
+/*     $NetBSD: rump.c,v 1.231 2011/02/15 15:54:28 pooka Exp $ */
 
 /*
  * Copyright (c) 2007 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.230 2011/02/15 10:35:05 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.231 2011/02/15 15:54:28 pooka Exp $");
 
 #include <sys/systm.h>
 #define ELFSIZE ARCH_ELFSIZE
@@ -786,10 +786,8 @@
 {
        struct proc *p = curproc;
 
+       fd_closeexec();
        strlcpy(p->p_comm, comm, sizeof(p->p_comm));
-
-       /* TODO: apply CLOEXEC */
-       /* TODO: other stuff? */
 }
 
 static void
diff -r ec24a41dc1b6 -r c4578935f721 sys/sys/filedesc.h
--- a/sys/sys/filedesc.h        Tue Feb 15 15:18:37 2011 +0000
+++ b/sys/sys/filedesc.h        Tue Feb 15 15:54:28 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: filedesc.h,v 1.57 2009/10/27 02:58:28 rmind Exp $      */
+/*     $NetBSD: filedesc.h,v 1.58 2011/02/15 15:54:28 pooka Exp $      */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -211,6 +211,7 @@
 void   cwdshare(proc_t *);
 void   cwdunshare(proc_t *);
 void   cwdfree(struct cwdinfo *);
+void   cwdexec(struct proc *);
 
 #define GETCWD_CHECK_ACCESS 0x0001
 int    getcwd_common(struct vnode *, struct vnode *, char **, char *, int,



Home | Main Index | Thread Index | Old Index