Re: dup2() vs dup3() inconsistency when
From: Michael Kerrisk
Date: Fri Oct 10 2008 - 01:01:20 EST
On Thu, Oct 9, 2008 at 10:31 PM, Ulrich Drepper <drepper@xxxxxxxxxx> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> H. Peter Anvin wrote:
>> The dup2() behavior comes from the logical consequence of dup2()'s
>> "close on reuse"; one would think it would be logical for dup3() to
>> behave the same way.
>
> No. We deliberately decided on this change. Otherwise, what is the
> result of dup3(fd, fd, O_CLOEXEC)?
Good point. However, I don't find any list mail that discussed this
implementation choice or its rationale. That would have been useful.
> There is no reason to use
> dup2(fd,fd), so why the hell somebody wants to defend this is beyond me.
There is no defense, except consistency with historical behavior. My
reasons for raising this thread were:
a) to point out the inconsistency with dup2().
b) to check that the change was intentional (though it was already
fairly clear that it was)
c) to determine the reason(s) for the change (which were not made clear)
As you point out, we have various possibilities with dup3(fd, fd, flags)
1) Do nothing to fd.
2) change the O_CLOEXEC flag for fd.
3) Give an error.
The problem is that depending on one's perspective one argue that
either 1 or 2 is consistent with dup2(), so 3 seems a reasonable thing
to do.
Cheers,
Michael
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
git://git.kernel.org/pub/scm/docs/man-pages/man-pages.git
man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html
Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/