[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <48EE6CD6.10007@zytor.com>
Date: Thu, 09 Oct 2008 13:43:02 -0700
From: "H. Peter Anvin" <hpa@...or.com>
To: Ulrich Drepper <drepper@...hat.com>
CC: mtk.manpages@...il.com, Al Viro <viro@...iv.linux.org.uk>,
LKML <linux-kernel@...r.kernel.org>
Subject: Re: dup2() vs dup3() inconsistency when
Ulrich Drepper 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)? There is no reason to use
> dup2(fd,fd), so why the hell somebody wants to defend this is beyond me.
>
The result of dup3(fd, fd, O_CLOEXEC) is to set the O_CLOEXEC flag on fd.
The behaviour of dup2() is functionally the following:
1. Duplicate the file descriptor from file_table[oldfd].
2. If file_table[newfd] is in use, close it.
3. Install the duplicate file descriptor at file_table[newfd].
Step (2) could be considered a bit dubious, but the behaviour of
dup2(fd, fd) is a direct consequence of the chosen semantics.
-hpa
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists