From: Bodo Eggert <7eggert@gmx.de>
To: mtk.manpages@gmail.com
Cc: 7eggert@gmx.de, "H. Peter Anvin" <hpa@zytor.com>,
Ulrich Drepper <drepper@redhat.com>,
Al Viro <viro@zeniv.linux.org.uk>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: dup2() vs dup3() inconsistency when
Date: Fri, 10 Oct 2008 15:19:31 +0200 (CEST) [thread overview]
Message-ID: <alpine.LSU.0.999.0810101514510.5758@be1.lrz> (raw)
In-Reply-To: <cfd18e0f0810100459n13ae6fbfx53861f423114f4f7@mail.gmail.com>
On Fri, 10 Oct 2008, Michael Kerrisk wrote:
> On Fri, Oct 10, 2008 at 1:42 PM, Bodo Eggert <7eggert@gmx.de> wrote:
> > Michael Kerrisk <mtk.manpages@googlemail.com> wrote:
> >
> >> Well, as long as we are fixing the dup3() interface in the way that Al
> >> and Ulrich have suggested, what about another fix:
> >>
> >> give an error if newfd is already open, thus forcing the user to do an
> >> explicit close
> >>
> >> ?
> >>
> >> This silent close in dup2() is an implementation blemish. Why not eliminate
> >> it?
> >
> > I think it might be usefull:
> > Thread B does some logging to fd 42
> > Thread A switches the logfile by creating a new file, writing a header and
> > then does dup3(fd, 42, O_WRONLY|O_APPEND|O_CLOEXEC); close(fd);
>
> I don't know the details of the kernel locks here, so perhaps this is
> a naive question: but, as things stand is there not the potential for
> some nasty race if one thread is writing to fd 42 at the same time as
> another thread does a dup2(fd, 42)?
I strongly hope there would not be any ...
> > (Off cause this is not yet implemented, O_RDONLY would give some problems,
> > O_CLOEXEC alone might be better done while open()ing the file, ... but you
> > get the idea.)
> >
> >
> > BTW: I think dup3(fd, -1, flags) should use the file descriptor dup() would
> > return. Or should there be a dupf(fd, flags) syscall instead?
>
> If one did this, maybe it would be better to have an extra flag that
> said: "use the first free file descriptor >= newfd", thus giving the
> more general functionality like fcntl(F_DUPFD).
I think you are right. I thought about something similar, too, but was
distracted enough to not think about the connection.
--
Funny quotes:
10. Nothing is fool proof to a talented fool.
next prev parent reply other threads:[~2008-10-10 13:09 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <bl2EV-7G2-9@gated-at.bofh.it>
[not found] ` <bl7v3-5sk-17@gated-at.bofh.it>
[not found] ` <blasN-OS-9@gated-at.bofh.it>
[not found] ` <blaCu-Z0-11@gated-at.bofh.it>
[not found] ` <blaMj-18o-23@gated-at.bofh.it>
[not found] ` <blaMj-18o-21@gated-at.bofh.it>
[not found] ` <bliqg-2DH-1@gated-at.bofh.it>
2008-10-10 11:42 ` Bodo Eggert
2008-10-10 11:59 ` Michael Kerrisk
2008-10-10 13:19 ` Bodo Eggert [this message]
2008-10-09 12:10 Michael Kerrisk
2008-10-09 17:21 ` H. Peter Anvin
2008-10-09 20:31 ` Ulrich Drepper
2008-10-09 20:43 ` H. Peter Anvin
2008-10-09 20:52 ` Ulrich Drepper
2008-10-09 20:57 ` H. Peter Anvin
2008-10-09 21:04 ` Ulrich Drepper
2008-10-10 5:04 ` Michael Kerrisk
2008-10-10 12:09 ` Bernd Petrovitsch
2008-10-10 12:15 ` Michael Kerrisk
2008-10-10 13:02 ` Bernd Petrovitsch
2008-10-10 13:15 ` Michael Kerrisk
2008-10-10 13:31 ` Bernd Petrovitsch
2008-10-10 5:01 ` Michael Kerrisk
2008-10-10 13:43 ` Heikki Orsila
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LSU.0.999.0810101514510.5758@be1.lrz \
--to=7eggert@gmx.de \
--cc=drepper@redhat.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mtk.manpages@gmail.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®