Date: Sat, 21 Jan 2012 01:56:45 +0200 From: Kostik Belousov <kostikbel@gmail.com> To: Eitan Adler <lists@eitanadler.com> Cc: jilles@freebsd.org, FreeBSD Hackers <freebsd-hackers@freebsd.org>, Colin Percival <cperciva@freebsd.org> Subject: Re: dup3 syscall - atomic set O_CLOEXEC with dup2 Message-ID: <20120120235645.GP31224@deviant.kiev.zoral.com.ua> In-Reply-To: <CAF6rxg=Xbh--nL3pebj=ra%2B09K%2BWJYen2JPVDWwR14%2BifG-_iQ@mail.gmail.com> References: <CAF6rxg=EjkwFbXQt3i2Nnz6_dcZtdek-2YdqyZnAdVPxVaWR_Q@mail.gmail.com> <20120112100840.GV31224@deviant.kiev.zoral.com.ua> <CAF6rxgne7M9xBb-mM1xsjPy3r-O%2BO%2BMzuYrsweG849V83MX3mA@mail.gmail.com> <CAF6rxgn5uddFb4LOGb0E_OOpVMiFavOVHwnrKF7cFHb6tfrPjw@mail.gmail.com> <CAF6rxg=Xbh--nL3pebj=ra%2B09K%2BWJYen2JPVDWwR14%2BifG-_iQ@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
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.
>
> On Thu, Jan 12, 2012 at 10:07 PM, Eitan Adler <lists@eitanadler.com> wrote:
> > Okay - here is version 2 (compile and run tested)
> >
> > Index: sys/kern/kern_descrip.c
> > ===================================================================
> > --- sys/kern/kern_descrip.c (revision 229830)
> > +++ sys/kern/kern_descrip.c (working copy)
> > @@ -110,6 +110,7 @@
> > /* Flags for do_dup() */
> > #define DUP_FIXED 0x1 /* Force fixed allocation */
> > #define DUP_FCNTL 0x2 /* fcntl()-style errors */
> > +#define DUP_CLOEXEC 0x4 /* Enable O_CLOEXEC on the new fd */
> >
> > static int do_dup(struct thread *td, int flags, int old, int new,
> > register_t *retval);
> > @@ -307,7 +308,36 @@
> > return (0);
> > }
> >
> > +struct dup3_args {
> > + u_int from;
> > + u_int to;
> > + int flags;
> > +};
> > +
> > /*
> > + * Duplicate a file descriptor and allow for O_CLOEXEC
> > + */
> > +
> > +int
> > +sys_dup3(struct thread * td, struct dup3_args * uap) {
> > + int dupflags;
> > +
> > + if (uap->from == uap->to)
> > + return (EINVAL);
> > +
> > + if (uap->flags & ~O_CLOEXEC)
> > + return (EINVAL);
> > +
> > + dupflags = DUP_FIXED;
> > + if (uap->flags & O_CLOEXEC)
> > + dupflags |= DUP_CLOEXEC;
> > +
> > + return (do_dup(td, dupflags, (int)uap->from, (int)uap->to,
> > + td->td_retval));
> > + return (0);
> > +}
> > +
> > +/*
> > * Duplicate a file descriptor to a particular value.
> > *
> > * Note: keep in mind that a potential race condition exists when closing
> > @@ -912,6 +942,9 @@
> > fdp->fd_lastfile = new;
> > *retval = new;
> >
> > + if (flags & DUP_CLOEXEC)
> > + fdp->fd_ofileflags[new] |= UF_EXCLOSE;
> > +
> > /*
> > * If we dup'd over a valid file, we now own the reference to it
> > * and must dispose of it using closef() semantics (as if a
> > Index: sys/kern/syscalls.master
> > ===================================================================
> > --- sys/kern/syscalls.master (revision 229830)
> > +++ sys/kern/syscalls.master (working copy)
> > @@ -951,5 +951,6 @@
> > off_t offset, off_t len); }
> > 531 AUE_NULL STD { int posix_fadvise(int fd, off_t offset, \
> > off_t len, int advice); }
> > +532 AUE_NULL STD { int dup3(u_int from, u_int to, int flags); }
> > ; Please copy any additions and changes to the following compatability tables:
> > ; sys/compat/freebsd32/syscalls.master
> > Index: sys/compat/freebsd32/syscalls.master
> > ===================================================================
> > --- sys/compat/freebsd32/syscalls.master (revision 229830)
> > +++ sys/compat/freebsd32/syscalls.master (working copy)
> > @@ -997,3 +997,4 @@
> > uint32_t offset1, uint32_t offset2,\
> > uint32_t len1, uint32_t len2, \
> > int advice); }
> > +532 AUE_NULL STD { int dup3(u_int from, u_int to, int flags); }
> >
> > Index: lib/libc/sys/Symbol.map
> > ===================================================================
> > --- lib/libc/sys/Symbol.map (revision 229830)
> > +++ lib/libc/sys/Symbol.map (working copy)
> > @@ -383,6 +383,7 @@
> >
> > FBSD_1.3 {
> > posix_fadvise;
> > + dup3;
> > };
> >
> > FBSDprivate_1.0 {
> >
> >
> > --
> > Eitan Adler
>
>
>
> --
> Eitan Adler
[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (FreeBSD)
iEYEARECAAYFAk8Z/zwACgkQC3+MBN1Mb4jALwCg63vZXRWsMzLqKymjhBDJLYCo
eD8AoOM1qj6/uxkb+reKeQ9aFUXSPr01
=RQMx
-----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120120235645.GP31224>
