All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: larsxschneider@gmail.com
Cc: git@vger.kernel.org, luke@diamand.org
Subject: Re: [PATCH v1 1/2] git-p4: print stderr if P4 read_pipe operation fails
Date: Wed, 09 Sep 2015 09:00:31 -0700	[thread overview]
Message-ID: <xmqqbndb7fc0.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <1441629723-90604-2-git-send-email-larsxschneider@gmail.com> (larsxschneider@gmail.com's message of "Mon, 7 Sep 2015 14:42:02 +0200")

larsxschneider@gmail.com writes:

> From: Lars Schneider <larsxschneider@gmail.com>
>
> If read_pipe crashes then the caller can inspect the error and handle
> it appropriately.
>
> Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
> ---
>  git-p4.py | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/git-p4.py b/git-p4.py
> index 073f87b..36a4bcb 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -134,11 +134,11 @@ def read_pipe(c, ignore_error=False):
>          sys.stderr.write('Reading pipe: %s\n' % str(c))
>  
>      expand = isinstance(c,basestring)
> -    p = subprocess.Popen(c, stdout=subprocess.PIPE, shell=expand)
> +    p = subprocess.Popen(c, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=expand)
>      pipe = p.stdout
>      val = pipe.read()
>      if p.wait() and not ignore_error:
> -        die('Command failed: %s' % str(c))
> +        die('Command failed: %s\nError: %s' % (str(c), p.stderr.read()))

I don't know enough about the callers of this helper function to
tell offhand if that is an issue, but this looks unsafe depending on
what the process on the other side of these pipes are doing.

If it attempts to spew a lot on its standard error stream first and
then write some to its standard output, I would not be surprised it
would get stuck waiting for us to read and drain its standard error
before it can proceed to write to its standard output, and in the
meantime we would be waiting for it to say something on its standard
output, no?

  reply	other threads:[~2015-09-09 16:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-07 12:42 [PATCH v1 0/2] git-p4: handle "Translation of file content failed" larsxschneider
2015-09-07 12:42 ` [PATCH v1 1/2] git-p4: print stderr if P4 read_pipe operation fails larsxschneider
2015-09-09 16:00   ` Junio C Hamano [this message]
2015-09-09 18:50     ` Lars Schneider
2015-09-07 12:42 ` [PATCH v1 2/2] git-p4: handle "Translation of file content failed" larsxschneider

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=xmqqbndb7fc0.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=larsxschneider@gmail.com \
    --cc=luke@diamand.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.