git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Johannes Sixt <j.sixt@viscovery.net>
Cc: "Shawn O. Pearce" <spearce@spearce.org>, git@vger.kernel.org
Subject: Re: [PATCH 2/6] Automatically close stderr pipes created by run_command
Date: Fri, 15 Feb 2008 09:11:36 -0800	[thread overview]
Message-ID: <7vfxvui1pz.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 47B3F51C.3060002@viscovery.net

Johannes Sixt <j.sixt@viscovery.net> writes:

> Shawn O. Pearce schrieb:
>> Like the out pipe and in pipe, we now automatically close the err
>> pipe if it was requested by the caller and it hasn't been closed
>> by the caller.  This simplifies anyone who wants to get a pipe to
>> the stderr stream for another process.
>
> IMHO, this is backwards.
>
> The .in, .out, .err members of struct child_process serve two different
> purposes:
>
> 1. Caller sets them to some fd > 0. This means:
>    "Here is a readable (.in) or writable (.out, .err) fd; use it."
>
> 2. Caller sets them to -1: This means:
>    "Create a pipe and give me the writable (.in) or readable (.out,
>    .err) end of it back."
>
> Notice that in a clean implementation:
>
> - case 1. would imply that the fd is "given away", i.e.
>   start_command/finish_command take ownership and close it;
>
> - case 2. would imply that the caller takes ownership of the returned
>   fd and has to close it.

I am puzzled.  In a clean implementation perhaps the fds belong
to the caller in both cases.  Or belong to the callee in both
cases.  Or perhaps sometimes belong to the caller and someimes
to the callee as you wrote above, but that seems arbitrary.

I suspect from the caller's point of view, if we can always make
them owned by the caller, that would be the most consistent and
convenient.  "Here is a fd --- I lend it to you so use it but do
not close --- I may have other uses for it later".

In any case, I agree with you that the current code lacks
consistency either way and we need an order there.

  reply	other threads:[~2008-02-15 17:12 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-14  6:22 [PATCH 2/6] Automatically close stderr pipes created by run_command Shawn O. Pearce
2008-02-14  8:00 ` Johannes Sixt
2008-02-15 17:11   ` Junio C Hamano [this message]
2008-02-15 19:45     ` Johannes Sixt
2008-02-15 22:14       ` Junio C Hamano
2008-02-16 17:36         ` [PATCH] start_command(), .in/.out/.err = -1: Callers must close the file descriptor Johannes Sixt
2008-02-16 17:36           ` [PATCH] start_command(), if .in/.out > 0, closes file descriptors, not the callers Johannes Sixt
2008-02-16 22:55             ` Junio C Hamano
2008-02-17  7:42               ` Shawn O. Pearce
2008-02-17  8:07                 ` Junio C Hamano
2008-02-17  8:20                   ` Shawn O. Pearce
2008-02-17  9:29               ` Johannes Sixt
2008-02-21 22:42                 ` [PATCH v2] " Johannes Sixt
2008-02-22  1:17                   ` Junio C Hamano
2008-02-16  8:25   ` [PATCH 2/6] Automatically close stderr pipes created by run_command Junio C Hamano

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=7vfxvui1pz.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=j.sixt@viscovery.net \
    --cc=spearce@spearce.org \
    /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;
as well as URLs for NNTP newsgroup(s).