Author: oshogbo
Date: Wed Jun  8 02:09:14 2016
New Revision: 301573
URL: https://svnweb.freebsd.org/changeset/base/301573

Log:
  Introduce the PD_CLOEXEC for pdfork(2).
  
  Reviewed by:  mjg

Modified:
  head/lib/libc/sys/pdfork.2
  head/sys/kern/kern_fork.c
  head/sys/kern/sys_procdesc.c
  head/sys/sys/procdesc.h

Modified: head/lib/libc/sys/pdfork.2
==============================================================================
--- head/lib/libc/sys/pdfork.2  Wed Jun  8 02:03:53 2016        (r301572)
+++ head/lib/libc/sys/pdfork.2  Wed Jun  8 02:09:14 2016        (r301573)
@@ -32,7 +32,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd April 7, 2014
+.Dd June 8, 2016
 .Dt PDFORK 2
 .Os
 .Sh NAME
@@ -80,6 +80,10 @@ This option is not permitted in
 capability mode (see
 .Xr cap_enter 2 ) .
 .El
+.Bl -tag -width ".Dv PD_DAEMON"
+.It Dv PD_CLOEXEC
+Set close-on-exec on process descriptor.
+.El
 .Pp
 .Fn pdgetpid
 queries the process ID (PID) in the process descriptor

Modified: head/sys/kern/kern_fork.c
==============================================================================
--- head/sys/kern/kern_fork.c   Wed Jun  8 02:03:53 2016        (r301572)
+++ head/sys/kern/kern_fork.c   Wed Jun  8 02:09:14 2016        (r301573)
@@ -827,6 +827,10 @@ fork1(struct thread *td, struct fork_req
                /* Must provide a place to put a procdesc if creating one. */
                if (fr->fr_pd_fd == NULL)
                        return (EINVAL);
+
+               /* Check if we are using supported flags. */
+               if ((fr->fr_pd_flags & ~PD_ALLOWED_AT_FORK) != 0)
+                       return (EINVAL);
        }
 
        p1 = td->td_proc;
@@ -878,8 +882,8 @@ fork1(struct thread *td, struct fork_req
         * later.
         */
        if (flags & RFPROCDESC) {
-               error = falloc_caps(td, &fp_procdesc, fr->fr_pd_fd, 0,
-                   fr->fr_pd_fcaps);
+               error = procdesc_falloc(td, &fp_procdesc, fr->fr_pd_fd,
+                   fr->fr_pd_flags, fr->fr_pd_fcaps);
                if (error != 0)
                        goto fail2;
        }

Modified: head/sys/kern/sys_procdesc.c
==============================================================================
--- head/sys/kern/sys_procdesc.c        Wed Jun  8 02:03:53 2016        
(r301572)
+++ head/sys/kern/sys_procdesc.c        Wed Jun  8 02:09:14 2016        
(r301573)
@@ -243,6 +243,22 @@ procdesc_new(struct proc *p, int flags)
 }
 
 /*
+ * Create a new process decriptor for the process that refers to it.
+ */
+int
+procdesc_falloc(struct thread *td, struct file **resultfp, int *resultfd,
+    int flags, struct filecaps *fcaps)
+{
+       int fflags;
+
+       fflags = 0;
+       if (flags & PD_CLOEXEC)
+               fflags = O_CLOEXEC;
+
+       return (falloc_caps(td, resultfp, resultfd, fflags, fcaps));
+}
+
+/*
  * Initialize a file with a process descriptor.
  */
 void

Modified: head/sys/sys/procdesc.h
==============================================================================
--- head/sys/sys/procdesc.h     Wed Jun  8 02:03:53 2016        (r301572)
+++ head/sys/sys/procdesc.h     Wed Jun  8 02:09:14 2016        (r301573)
@@ -101,6 +101,9 @@ void         procdesc_finit(struct procdesc *, 
 pid_t   procdesc_pid(struct file *);
 void    procdesc_reap(struct proc *);
 
+int     procdesc_falloc(struct thread *, struct file **, int *, int,
+           struct filecaps *);
+
 #else /* !_KERNEL */
 
 #include <sys/_types.h>
@@ -127,5 +130,8 @@ __END_DECLS
  * Flags which can be passed to pdfork(2).
  */
 #define        PD_DAEMON       0x00000001      /* Don't exit when procdesc 
closes. */
+#define        PD_CLOEXEC      0x00000002      /* Close file descriptor on 
exec. */
+
+#define        PD_ALLOWED_AT_FORK      (PD_DAEMON | PD_CLOEXEC)
 
 #endif /* !_SYS_PROCDESC_H_ */
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to