From owner-freebsd-hackers@FreeBSD.ORG Fri Jan 20 23:56:51 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EF8D1106564A; Fri, 20 Jan 2012 23:56:51 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id D84588FC0C; Fri, 20 Jan 2012 23:56:50 +0000 (UTC) Received: from skuns.kiev.zoral.com.ua (localhost [127.0.0.1]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id q0KNujiu091162 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 21 Jan 2012 01:56:46 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5) with ESMTP id q0KNuj3r090263; Sat, 21 Jan 2012 01:56:45 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5/Submit) id q0KNujdJ090262; Sat, 21 Jan 2012 01:56:45 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 21 Jan 2012 01:56:45 +0200 From: Kostik Belousov To: Eitan Adler Message-ID: <20120120235645.GP31224@deviant.kiev.zoral.com.ua> References: <20120112100840.GV31224@deviant.kiev.zoral.com.ua> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="FKBLnz/kFCbVUHCG" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-3.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: jilles@freebsd.org, FreeBSD Hackers , Colin Percival Subject: Re: dup3 syscall - atomic set O_CLOEXEC with dup2 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Jan 2012 23:56:52 -0000 --FKBLnz/kFCbVUHCG Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 20, 2012 at 06:25:42PM -0500, Eitan Adler wrote: > I figure this isn't wanted? You silently ignored part of the notes that were provided, and keep complete silence on the primary question about non-standard and fractional nature of the patch. I see no reason to retype my previous response. >=20 > On Thu, Jan 12, 2012 at 10:07 PM, Eitan Adler wrot= e: > > Okay - here is version 2 (compile and run tested) > > > > Index: sys/kern/kern_descrip.c > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > --- sys/kern/kern_descrip.c =9A =9A (revision 229830) > > +++ sys/kern/kern_descrip.c =9A =9A (working copy) > > @@ -110,6 +110,7 @@ > > =9A/* Flags for do_dup() */ > > =9A#define DUP_FIXED =9A =9A =9A0x1 =9A =9A /* Force fixed allocation */ > > =9A#define DUP_FCNTL =9A =9A =9A0x2 =9A =9A /* fcntl()-style errors */ > > +#define DUP_CLOEXEC =9A =9A0x4 =9A =9A /* Enable O_CLOEXEC on the new = fd */ > > > > =9Astatic int do_dup(struct thread *td, int flags, int old, int new, > > =9A =9A register_t *retval); > > @@ -307,7 +308,36 @@ > > =9A =9A =9A =9Areturn (0); > > =9A} > > > > +struct dup3_args { > > + =9A =9A =9A u_int =9A from; > > + =9A =9A =9A u_int =9A to; > > + =9A =9A =9A int =9A =9A flags; > > +}; > > + > > =9A/* > > + * Duplicate a file descriptor and allow for O_CLOEXEC > > + */ > > + > > +int > > +sys_dup3(struct thread * td, struct dup3_args * uap) { > > + =9A =9A =9A int dupflags; > > + > > + =9A =9A =9A if (uap->from =3D=3D uap->to) > > + =9A =9A =9A =9A =9A =9A =9A return (EINVAL); > > + > > + =9A =9A =9A if (uap->flags & ~O_CLOEXEC) > > + =9A =9A =9A =9A =9A =9A =9A return (EINVAL); > > + > > + =9A =9A =9A dupflags =3D DUP_FIXED; > > + =9A =9A =9A if (uap->flags & O_CLOEXEC) > > + =9A =9A =9A =9A =9A =9A =9A dupflags |=3D DUP_CLOEXEC; > > + > > + =9A =9A =9A return (do_dup(td, dupflags, (int)uap->from, (int)uap->to, > > + =9A =9A =9A =9A =9A =9A =9A =9A =9A td->td_retval)); > > + =9A =9A =9A return (0); > > +} > > + > > +/* > > =9A* Duplicate a file descriptor to a particular value. > > =9A* > > =9A* Note: keep in mind that a potential race condition exists when clo= sing > > @@ -912,6 +942,9 @@ > > =9A =9A =9A =9A =9A =9A =9A =9Afdp->fd_lastfile =3D new; > > =9A =9A =9A =9A*retval =3D new; > > > > + =9A =9A =9A if (flags & DUP_CLOEXEC) > > + =9A =9A =9A =9A =9A =9A =9A fdp->fd_ofileflags[new] |=3D UF_EXCLOSE; > > + > > =9A =9A =9A =9A/* > > =9A =9A =9A =9A * If we dup'd over a valid file, we now own the referen= ce to it > > =9A =9A =9A =9A * and must dispose of it using closef() semantics (as i= f a > > Index: sys/kern/syscalls.master > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > --- sys/kern/syscalls.master =9A =9A(revision 229830) > > +++ sys/kern/syscalls.master =9A =9A(working copy) > > @@ -951,5 +951,6 @@ > > =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A= off_t offset, off_t len); } > > =9A531 =9A =9AAUE_NULL =9A =9A =9A =9ASTD =9A =9A { int posix_fadvise(i= nt fd, off_t offset, \ > > =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A= off_t len, int advice); } > > +532 =9A =9AAUE_NULL =9A =9A =9A =9ASTD =9A =9A { int dup3(u_int from, = u_int to, int flags); } > > =9A; Please copy any additions and changes to the following compatabili= ty tables: > > =9A; sys/compat/freebsd32/syscalls.master > > Index: sys/compat/freebsd32/syscalls.master > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > --- sys/compat/freebsd32/syscalls.master =9A =9A =9A =9A(revision 22983= 0) > > +++ sys/compat/freebsd32/syscalls.master =9A =9A =9A =9A(working copy) > > @@ -997,3 +997,4 @@ > > =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A= uint32_t offset1, uint32_t offset2,\ > > =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A= uint32_t len1, uint32_t len2, \ > > =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A =9A= int advice); } > > +532 =9A =9AAUE_NULL =9A =9A =9A =9ASTD =9A =9A { int dup3(u_int from, = u_int to, int flags); } > > > > Index: lib/libc/sys/Symbol.map > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > --- lib/libc/sys/Symbol.map =9A =9A (revision 229830) > > +++ lib/libc/sys/Symbol.map =9A =9A (working copy) > > @@ -383,6 +383,7 @@ > > > > =9AFBSD_1.3 { > > =9A =9A =9A =9Aposix_fadvise; > > + =9A =9A =9A dup3; > > =9A}; > > > > =9AFBSDprivate_1.0 { > > > > > > -- > > Eitan Adler >=20 >=20 >=20 > --=20 > Eitan Adler --FKBLnz/kFCbVUHCG Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (FreeBSD) iEYEARECAAYFAk8Z/zwACgkQC3+MBN1Mb4jALwCg63vZXRWsMzLqKymjhBDJLYCo eD8AoOM1qj6/uxkb+reKeQ9aFUXSPr01 =RQMx -----END PGP SIGNATURE----- --FKBLnz/kFCbVUHCG--