tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: [PATCH] rfc: reuse previously closed descriptor in freopen()



On Mon, Aug 25, 2008 at 6:58 PM, David Holland 
<dholland-tech%netbsd.org@localhost> wrote:
>  > What is the advantage to not reuse previously closed descriptor for fd >= 
> 3?
> I'm not sure I understand your question; but the intent of the code is
> that the stdio files "stdin", "stdout", and "stderr" should remain
> connected to fds 0, 1, and 2. Your patch breaks this if someone
> freopens stderr and the new fd is, say, 8.
How? I printed out fds of regular files: they were 3 and 4 before
those lines and 4 4 after.
But files are different for new fd = 4 and previous fd = 4.
What is the advantage in this case?

> Perhaps you meant to test wantfd < 3 rather than f < 3?
I'm not sure, but possible both fds should be checked.

> But even then,
> the principle of least surprise suggests that freopen, which is
> supposed to adjust an existing open FILE * rather than create a new
> one, should retain the same fd if possible.
I don't see any difference in code if fd will be changed to another one.
The freopen() fills fp-><smth> always independently of f or wantfd descriptors.

> And finally, if it ain't broke, don't fix it - this is stdio and
> potentially affects a lot of code, not all of which is well written or
> defensive (or even correct) about its assumptions.
I suppose this is unusual assumptions. In linux my small test case
shows normal fd reusing instead of NetBSD's one. And other test case
assumes the same behaviour as in linux.

-- 
With Best Regards,
Andy Shevchenko


Home | Main Index | Thread Index | Old Index