git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Denton Liu <liu.denton@gmail.com>,
	Git Mailing List <git@vger.kernel.org>,
	Vincent Lefevre <vincent@vinc17.net>,
	Johannes Sixt <j6t@kdbg.org>
Subject: Re: [PATCH] pager: exit without error on SIGPIPE
Date: Wed, 03 Feb 2021 03:45:00 +0100	[thread overview]
Message-ID: <87r1lxeuoj.fsf@evledraar.gmail.com> (raw)
In-Reply-To: <xmqqczxjhwgv.fsf@gitster.c.googlers.com>


On Tue, Feb 02 2021, Junio C Hamano wrote:

> Junio C Hamano <gitster@pobox.com> writes:
>
>> Sorry, but you still have lost me---I do not see if/why we even care
>> about atexit codepath.  As far as the end users are concered, they
>> are running "git" and observing the exit code from "git".  There,
>> reporting that "git" was killed by SIGPIPE, instead of exiting
>> normally, is not something they want to hear about after quitting
>> their pager, and that is why the signal reception codepath matters.
>
> (something I noticed that I left unsaid...)
>
> On the other hand, "git" spawns not just pager but other
> subprocesses (e.g. "hooks"), and it is entirely up to us what to do
> with the exit code from them.  When we care about making an external
> effect (e.g. post-$action hooks that are run for their side effects),
> we can ignore their exit status just fine.
>
> And I do not see why the "we waited before leaving, and noticed the
> pager exited with non-zero status" that we could notice in the
> atexit codepath has to be so special.  We _could_ (modulo the "exit
> there is not portable" you noted) make our exit status reflect that,
> but I do not think it is all that important a "failure" (as opposed
> to, say, we tried to show a commit message but failed to recode it
> into utf-8, or we tried to spawn the pager but failed to start a
> process) to clobber _our_ exit status with pager's exit status.

Because your patch upthread makes git's exit code on pager failure a
function of how your PIPE_BUF happens to be consumed on your OS.

You can see this if you do this:

    diff --git a/pager.c b/pager.c
    index ee435de6756..5124124ac36 100644
    --- a/pager.c
    +++ b/pager.c
    @@ -30,0 +31 @@ static void wait_for_pager_atexit(void)
    +       trace2_region_enter_printf("pager", "wait_for_pager_atexit", the_repository, "%d", 0);
    @@ -35,0 +37 @@ static void wait_for_pager_signal(int signo)
    +       trace2_region_enter_printf("pager", "wait_for_pager_signal", the_repository, "%d", 1);

And then e.g.:

    GIT_TRACE2_EVENT=/tmp/trace2.json ~/g/git/git -c core.pager="less; exit 1" log -100; echo $?

On my laptop & screen size I get around ~20 page lenghts with less
before I get to the end.

If I quit on the first page I get an exit code of 141, ditto the second,
on everything from the 3rd forward I get an exit code of 0. Because at
that point git's/the OS/pipe buffers etc. have flushed the rest to the
pager.

So:

 1. With something like your patch we'd get an exit code of !0 on pager
    failure only if the user won the PIPE_BUF roulette.

 2. With finishing up my "WIP/PATCH v2 5/5" we'd get consistent exit
    codes carried down, but that patch is insanity already, and
    finishing it would be even crazier.

So I haven't been advocating for #2, just the #0 of "I don't really see
the problem with the current behavior of SIGHUP, maybe configure your
shell?".

B.t.w. to <5772995f-c887-7f13-6b5f-dc44f4477dcb@kdbg.org> in the
side-thread: Having a smarter pager than just less isn't really all that
unusual, e.g. it's very handy on a remote system to type commands
interactively but sloooowly, but then configure a pager with some
combination of an ssh tunnel + nc + remote system's screen so you can
browse around without every search/page up/down taking 1-2 seconds.

It's also nice when a thing like that can quit as fast as possible when
it gets SIGHUP, not wait on the exit code of the spawned program, which
may involve tearing down an ssh session or whatever.

But I digress.

Getting back to the point, whatever anyone thinks of returning SIGHUP as
we do now or not, I think it's bonkers to ignore SIGHUP and *then*
return a non-zero *only in the non-atexit case*.

That just means that if you do have a broken pager you're going to get
flaky exits depending on the state of our flushed buffers, who's going
to be helped by such a fickle exit code?

So if we're going to change the behavior to not return SIGHUP, and don't
want to refactor our entire atexit() handling in #2 to be guaranteed to
pass down the pager's exit code, I don't see how anything except the
approach of just exit(0) in that case makes sense, which is what Denton
Liu's patch initially suggested doing.

  parent reply	other threads:[~2021-02-03  2:46 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-15 16:15 git fails with a broken pipe when one quits the pager Vincent Lefevre
2021-01-29 23:48 ` [PATCH] pager: exit without error on SIGPIPE Denton Liu
2021-01-30  8:29   ` Johannes Sixt
2021-01-30 12:52     ` Johannes Sixt
2021-02-01 15:03   ` Ævar Arnfjörð Bjarmason
2021-02-01 17:47     ` Junio C Hamano
2021-02-01 19:52       ` Ævar Arnfjörð Bjarmason
2021-02-01 20:55         ` Junio C Hamano
2021-02-02  2:05           ` Ævar Arnfjörð Bjarmason
2021-02-02  4:45             ` Junio C Hamano
2021-02-02  5:25               ` Junio C Hamano
2021-02-02  7:45                 ` Johannes Sixt
2021-02-02 20:13                   ` Junio C Hamano
2021-02-02 22:15                     ` Johannes Sixt
2021-02-02 22:21                       ` Junio C Hamano
2021-02-03 17:07                         ` Johannes Sixt
2021-02-03 18:12                           ` Junio C Hamano
2021-02-04 15:10                           ` Vincent Lefevre
2021-02-03  2:45                 ` Ævar Arnfjörð Bjarmason [this message]
2021-02-03  2:54                   ` Junio C Hamano
2021-02-03  3:36                     ` Ævar Arnfjörð Bjarmason
2021-02-03 17:19                     ` Johannes Sixt
2021-01-31  1:47 ` git fails with a broken pipe when one quits the pager Ævar Arnfjörð Bjarmason
2021-01-31  3:36   ` Vincent Lefevre
2021-01-31  3:47     ` Vincent Lefevre
2021-01-31 20:49     ` Ævar Arnfjörð Bjarmason
2021-02-01 10:34       ` Vincent Lefevre
2021-02-01 11:33         ` Chris Torek
2021-02-01 12:36           ` Vincent Lefevre
2021-02-01 12:53             ` Chris Torek
2021-02-01 15:17               ` Vincent Lefevre
2021-02-01 15:00           ` Ævar Arnfjörð Bjarmason
2021-02-01 12:10         ` Ævar Arnfjörð Bjarmason
2021-02-01 14:48           ` Vincent Lefevre
2021-02-01 15:44             ` Ævar Arnfjörð Bjarmason
2021-02-01 22:16               ` Johannes Sixt
2021-02-03  2:48                 ` Ævar Arnfjörð Bjarmason
2021-02-03 17:11                   ` Johannes Sixt
2021-02-03 15:26               ` Vincent Lefevre
2021-02-04  0:14                 ` Ævar Arnfjörð Bjarmason
2021-02-04 15:38                   ` Vincent Lefevre
2021-02-01 14:49           ` [PATCH 0/3] pager: test for exit behavior & trace2 bug fix Ævar Arnfjörð Bjarmason
2021-02-02  1:59             ` [PATCH v2 0/5] " Ævar Arnfjörð Bjarmason
2021-02-02  1:59             ` [PATCH v2 1/5] pager: refactor wait_for_pager() function Ævar Arnfjörð Bjarmason
2021-02-02  1:59             ` [PATCH v2 2/5] pager: test for exit code with and without SIGPIPE Ævar Arnfjörð Bjarmason
2021-02-02  8:50               ` Denton Liu
2021-02-05  7:47               ` Johannes Sixt
2021-02-02  1:59             ` [PATCH v2 3/5] run-command: add braces for "if" block in wait_or_whine() Ævar Arnfjörð Bjarmason
2021-02-02  2:00             ` [PATCH v2 4/5] pager: properly log pager exit code when signalled Ævar Arnfjörð Bjarmason
2021-02-05  7:58               ` Johannes Sixt
2021-02-05 11:37                 ` Junio C Hamano
2021-02-02  2:00             ` [WIP/PATCH v2 5/5] WIP pager: respect exit code of pager over SIGPIPE Ævar Arnfjörð Bjarmason
2021-02-01 14:49           ` [PATCH 1/3] pager: test for exit code Ævar Arnfjörð Bjarmason
2021-02-01 14:49           ` [PATCH 2/3] pager: refactor wait_for_pager() function Ævar Arnfjörð Bjarmason
2021-02-01 14:49           ` [PATCH 3/3] pager: properly log pager exit code when signalled Ævar Arnfjörð Bjarmason
2021-02-01 18:07             ` Junio C Hamano
2021-02-01 19:21               ` Ævar Arnfjörð Bjarmason
2021-02-01 18:15             ` Junio C Hamano
2021-02-01 19:23               ` Ævar Arnfjörð Bjarmason
2021-02-01 22:04       ` git fails with a broken pipe when one quits the pager Johannes Sixt

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=87r1lxeuoj.fsf@evledraar.gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=liu.denton@gmail.com \
    --cc=vincent@vinc17.net \
    /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).