From owner-svn-src-all@freebsd.org Wed Jun 8 02:09:16 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 24BE0B6D6A2; Wed, 8 Jun 2016 02:09:16 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E375C18E7; Wed, 8 Jun 2016 02:09:15 +0000 (UTC) (envelope-from oshogbo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5829FV9076021; Wed, 8 Jun 2016 02:09:15 GMT (envelope-from oshogbo@FreeBSD.org) Received: (from oshogbo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5829Ecd076017; Wed, 8 Jun 2016 02:09:14 GMT (envelope-from oshogbo@FreeBSD.org) Message-Id: <201606080209.u5829Ecd076017@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: oshogbo set sender to oshogbo@FreeBSD.org using -f From: Mariusz Zaborski Date: Wed, 8 Jun 2016 02:09:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r301573 - in head: lib/libc/sys sys/kern sys/sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jun 2016 02:09:16 -0000 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 @@ -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_ */