From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 5935F1F4B4 for ; Sat, 30 Jan 2021 09:32:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231547AbhA3J3S (ORCPT ); Sat, 30 Jan 2021 04:29:18 -0500 Received: from bsmtp5.bon.at ([195.3.86.187]:5076 "EHLO bsmtp5.bon.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230455AbhA3J2h (ORCPT ); Sat, 30 Jan 2021 04:28:37 -0500 X-Greylist: delayed 1358 seconds by postgrey-1.27 at vger.kernel.org; Sat, 30 Jan 2021 04:28:37 EST Received: from bsmtp1.bon.at (unknown [192.168.181.104]) by bsmtp5.bon.at (Postfix) with ESMTPS id 4DSSFr2tCXz5vHD for ; Sat, 30 Jan 2021 09:35:28 +0100 (CET) Received: from dx.site (unknown [93.83.142.38]) by bsmtp1.bon.at (Postfix) with ESMTPSA id 4DSS6m3SBKz5tl9; Sat, 30 Jan 2021 09:29:20 +0100 (CET) Received: from [IPv6:::1] (localhost [IPv6:::1]) by dx.site (Postfix) with ESMTP id D68C94BCE; Sat, 30 Jan 2021 09:29:18 +0100 (CET) Subject: Re: [PATCH] pager: exit without error on SIGPIPE To: Denton Liu Cc: Vincent Lefevre , Git Mailing List References: From: Johannes Sixt Message-ID: Date: Sat, 30 Jan 2021 09:29:18 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Am 30.01.21 um 00:48 schrieb Denton Liu: > If the pager closes before the git command feeding the pager finishes, > git is killed by a SIGPIPE and the corresponding exit code is 141. > Since the pipe is just an implementation detail, it does not make sense > for this error code to be user-facing. > > Handle SIGPIPEs by simply calling exit(0) in wait_for_pager_signal(). > > Introduce `test-tool pager` which infinitely prints `y` to the pager in > order to test the new behavior. This cannot be tested with any existing > git command because there are no other commands which produce infinite > output. Without the change to pager.c, the newly introduced test fails. > > Reported-by: Vincent Lefevre > Signed-off-by: Denton Liu ... > diff --git a/pager.c b/pager.c > index ee435de675..5922d99dc8 100644 > --- a/pager.c > +++ b/pager.c > @@ -34,6 +34,8 @@ static void wait_for_pager_atexit(void) > static void wait_for_pager_signal(int signo) > { > wait_for_pager(1); > + if (signo == SIGPIPE) > + exit(0); > sigchain_pop(signo); > raise(signo); > } > diff --git a/t/helper/test-pager.c b/t/helper/test-pager.c > new file mode 100644 > index 0000000000..feb68b8643 > --- /dev/null > +++ b/t/helper/test-pager.c > @@ -0,0 +1,12 @@ > +#include "test-tool.h" > +#include "cache.h" > + > +int cmd__pager(int argc, const char **argv) > +{ > + if (argc > 1) > + usage("\ttest-tool pager"); > + > + setup_pager(); > + for (;;) > + puts("y"); > +} My gut feeling tells that this will end in an infinite loop on Windows. There are no signals on Windows that would kill the upstream of a pipe. This call site will only notice that the downstream of the pipe was closed, when it checks for write errors. Let me test it. -- Hannes