Re: [PATCH] Fix start_command closing cmd->out/in regardless of cmd->close_out/in
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 21, 2007, 09:11 UTC
- Message-ID
- <7vmyt8gdzv.fsf@gitster.siamese.dyndns.org>
- In-Reply-To
- <46dff0320711201838g5affba6bo21a8c837b0bef681@mail.gmail.com>
"Ping Yin" <pkufranky@gmail.com> writes:
Show 5 quoted lines
> On Nov 21, 2007 12:17 AM, Johannes Sixt <j.sixt@viscovery.net> wrote: > ... >> This way the change is more local without affecting well-tested other callers. > > This way works, but it is a tricky one, not a natural or graceful one.
I do not know about "natural". That largely would depend on where one starts thinking about the issues from.
But I think an API definition that says "These fds are closed after the call, so if you are going to use them, you can dup() them beforehand" is equally valid, and I suspect that forgetting to dup() is easier to detect than forgetting to close() --- you will notice the former mistake immediately because your read and write say "oops, nobody on the other end" but the latter mistake will result in a hung process. And for that reason, I think it can be called more "graceful". So ...
Show 9 quoted lines
>> Furthermore, I don't think that it's correct to just set the .close_in or >> .close_out flags. This will close the fd only in finish_command(), which can >> be too late: Think again of a writable pipe end that remains open and keeps >> the reader waiting for input that is not going to happen. > > This may happen. However, i have scanned all the git codes using the > auto closing behaviour and i don't discover the problem you mentioned. > So i think it deserves to correct the misbehaviour after carefully > testing. And we can make a clarification for that if necessary.
... I do not necessarily agree that your patch is correcting the misbehaviour.