From patchwork Sat Jun 10 14:51:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13274943 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4244EC7EE2F for ; Sat, 10 Jun 2023 14:51:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232586AbjFJOvc (ORCPT ); Sat, 10 Jun 2023 10:51:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229521AbjFJOvb (ORCPT ); Sat, 10 Jun 2023 10:51:31 -0400 Received: from mout.web.de (mout.web.de [217.72.192.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68AC730E8 for ; Sat, 10 Jun 2023 07:51:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1686408673; x=1687013473; i=l.s.r@web.de; bh=1fnr8nEXeuSkaREVdsIC/2C00I1XOLC334by4aVITyM=; h=X-UI-Sender-Class:Date:From:Subject:To:Cc:References:In-Reply-To; b=t51sHJFEDLxFFsG5FZXoXUAaJUk93GPfaRxQ7AcKTcwOY/+8qy62qEzQRJd1aEM4WWBLBwq A2/aGqeqUiUxlaF/wB+boMvURXJbCoQ2M/GfY4+dTjBKC7u/T0HvR61qjF4+7EXZ1I8fFj3lQ FwbVcHcVe+dvB3fL5uftB3zfyDx2KUqdDbSUEmZH4kj1qWlSwwkaV8QBz/R2oOUnjP8miOYkF B/v6YdYqNQu3H9hX0AnnEB+f/QPpyC1sE4cwNSI2UpZSK7+w5c4lt+SytI3ESsqTB99xDn4EF OH0VMOHJ3x80683IHbbGnj0tHj/JKAw70Dt/TqJN+BNWKC/C9mbg== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([91.47.146.76]) by smtp.web.de (mrweb106 [213.165.67.124]) with ESMTPSA (Nemesis) id 1Mmymz-1phDYU3LxX-00k6UU; Sat, 10 Jun 2023 16:51:13 +0200 Message-ID: <14e1be60-3765-0ba5-00f5-2848bb57bf53@web.de> Date: Sat, 10 Jun 2023 16:51:12 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.11.2 From: =?utf-8?q?Ren=C3=A9_Scharfe?= Subject: [PATCH 1/2] t1800: loosen matching of error message for bad shebang To: git@vger.kernel.org Cc: rsbecker@nexbridge.com, =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= , Junio C Hamano References: <022e01d8ceb5$c2da52c0$488ef840$@nexbridge.com> <003501d8cf8d$21ce5ba0$656b12e0$@nexbridge.com> <013701d90f80$692ba9c0$3b82fd40$@nexbridge.com> <2e3be2e9-191d-fbfd-54c6-a3958e35637c@web.de> <013501d98cee$e58dc980$b0a95c80$@nexbridge.com> <013601d98cf2$392153c0$ab63fb40$@nexbridge.com> <28d808e4-77b4-d91e-8a86-c21287019b56@web.de> Content-Language: en-US In-Reply-To: X-Provags-ID: V03:K1:IMad7irnXOa0mEwYYMTxMroZ9ZcK8ByzkOUubGa3GoMGn6LeneA s4tfCRQtsrX4nCgumdgYqcY0/00nafWITB+P/HMvo4Pd8JBGPgVVd9tjbKgeoCii33S4ibb 7YO9F7mM5bNb4qSUUYYjDtpD5cJB/BvqRZl4sf5xN2CoInh2/ol1CYvZbWD9UbW+4gQIPUj g9Dn4q6toOHLntBpzX6TQ== UI-OutboundReport: notjunk:1;M01:P0:4475kk75aRM=;8PoWbjoItDblzfIU0awpBuQI3fX pBvx1xgTyR09K5ratx5QfELooNsGf0A+5tcZymXzLu9H4GmXbEzW4nvZahZep6NXSnJvazeDZ +AC7oNNeWcdYDZFHogGBANm7Ep9wXxlT803pjYOySInvyM6BAB5X1f7GZ1OwCurvJgVYbwhWj Mn3JST1uR2zVMkbgo85TKdSkz27pWJbZJdKdthRvDX6/xWiv57j9kajsiQdbZuX/DNZh+9vq/ 2N6w7hzPsa58PMhl5dm6mh0tPKHDJbTa3WuIdlVI5w8EqXNQV+OfZfHdANr1ePUYwS5BHzDaK qOtuyhkODVz+gG40Cpl0iKz0ZGE/3370VNXrUUQovyE7H5LeZrBDSvMtYx5rQ7w9VexlVFWyU +kAYVkT12jiJuwqwRxo0Nt4SwGu/u+7gzplp2e8bps3UgwtNlJUoEeOF7vc4nHmQSdpl290vd +GTvA8UDsOPe5jl7P0E9wATZznlrreRecBcC7/8T1znmri9z6CJlgXG6Mhopo+nyHSJAC8A8D UQgGlub+r/Sgj5Tpy28gZmoFDIPr4PzLFxsGHGP6z/5cThMtF72oWZvOPgwelZhQ+Z4YpRYNp b9MI0E5QsmBKV8h2gZK7T+UtWFTo1WPY2QPsh3iWcJdBOL1RPpM1HPHEAWRmaqVHFPYgEkaNq psCCzxTEuXTE3U4CoiI8ZGVFSxvngA0qfXxX/DamPw5AU23JZf3cypCmyFYuju1T4LQMwS4IW jpYESI0bi47y2GUSCcYm9a1TOkavcWSD40T3Krp8yNUHoEfW/EW/P1fBBaVIwu7hgaElRbELo vqf5Rrmg8FmoS+5jUjgJ2Jzya7sf5/zNVXo6TsIBvHEE4WvaxN+ACQrJP+qFKTS8Ywp2Kv984 C8teA8aeAY9DJvx1XNGPBID3r7P89iKP4mIz3m/hAXuclL0RcFFuQoRtnCz+VW4MRbfHdj7xp WqO6IYao9As/ndhqkliMfn2UYxc= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org t1800.16 checks whether an attempt to run a hook script with a missing executable in its #! line fails and reports that error. The expected error message differs between platforms. The test handles two common variants, but on NonStop OS we get a third one: "fatal: cannot exec 'bad-hooks/test-hook': ...", which causes the test to fail there. We don't really care about the specific message text all that much here. Use grep and a single regex with alternations to ascertain that we get an error message (fatal or otherwise) about the failed invocation of the hook, but don't bother checking if we get the right variant for the platform the test is running on or whether quoting is done. This looser check let's the test pass on NonStop OS. Reported-by: Randall S. Becker Signed-off-by: René Scharfe --- t/t1800-hook.sh | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) -- 2.41.0 diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh index 3506f627b6..c156d6decc 100755 --- a/t/t1800-hook.sh +++ b/t/t1800-hook.sh @@ -156,25 +156,15 @@ test_expect_success 'git hook run a hook with a bad shebang' ' mkdir bad-hooks && write_script bad-hooks/test-hook "/bad/path/no/spaces" expect <<-\EOF - fatal: cannot run bad-hooks/test-hook: ... - EOF - else - cat >expect <<-\EOF - error: cannot spawn bad-hooks/test-hook: ... - EOF - fi && test_expect_code 1 git \ -c core.hooksPath=bad-hooks \ hook run test-hook >out 2>err && test_must_be_empty out && - sed -e "s/test-hook: .*/test-hook: .../" actual && - test_cmp expect actual + + # TODO: We should emit the same (or at least a more similar) + # error on MINGW (essentially Git for Windows) and all other + # platforms.. See the OS-specific code in start_command() + grep -E "^(error|fatal): cannot (exec|run|spawn) .*bad-hooks/test-hook" err ' test_expect_success 'stdin to hooks' ' From patchwork Sat Jun 10 14:51:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 13274944 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5D92C7EE2F for ; Sat, 10 Jun 2023 14:52:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233186AbjFJOvj (ORCPT ); Sat, 10 Jun 2023 10:51:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232624AbjFJOvi (ORCPT ); Sat, 10 Jun 2023 10:51:38 -0400 Received: from mout.web.de (mout.web.de [212.227.17.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C1E530E5 for ; Sat, 10 Jun 2023 07:51:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1686408682; x=1687013482; i=l.s.r@web.de; bh=2m380pGhk78pmFpfDL7sBCWdTNLalishKtHdlvgnCvc=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=WFdtp0c6dxN9oI6o2zAy4TnWT0lE83KEd8KkkmLK9+D2trjEHvj3F/57ovLYQcOKvrJbfli S2SltIsc+Uif3GJZNDnTpCFfr4EkIzOItCP2Jlfz6UDJLleXrH8UI7Nz8VonEILLH4MQ3vmRn RqEnNiggH1GxGwzoQaNwql0TDEurMtMpry1q4Ofe25FEsDNv6uo3Gafyyoxk4cd3xZ2jyE8ld R7YiXMG3wtncq2+LKKNZPNa/FbRIDqfR6TeySKsu8IktEk26y3AawiR1aJfqqlJECfX4cvPyY pJsekAYvobDMLC9qbTyj3p0h+B3+tjNnSthXpZLgPEfhAetYKTEw== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Received: from [192.168.178.29] ([91.47.146.76]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MIc7b-1qKPzr1V37-00ETOj; Sat, 10 Jun 2023 16:51:22 +0200 Message-ID: <753d6b82-580d-bcff-c0c2-e7ad53f13b21@web.de> Date: Sat, 10 Jun 2023 16:51:21 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.11.2 Subject: [PATCH 2/2] run-command: report exec error even on ENOENT To: git@vger.kernel.org Cc: rsbecker@nexbridge.com, Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= References: <022e01d8ceb5$c2da52c0$488ef840$@nexbridge.com> <003501d8cf8d$21ce5ba0$656b12e0$@nexbridge.com> <013701d90f80$692ba9c0$3b82fd40$@nexbridge.com> <2e3be2e9-191d-fbfd-54c6-a3958e35637c@web.de> <013501d98cee$e58dc980$b0a95c80$@nexbridge.com> <013601d98cf2$392153c0$ab63fb40$@nexbridge.com> <28d808e4-77b4-d91e-8a86-c21287019b56@web.de> Content-Language: en-US From: =?utf-8?q?Ren=C3=A9_Scharfe?= In-Reply-To: X-Provags-ID: V03:K1:Z0rDEB5s6bejqnQp5xFBPXrbvjCX+0Bb2CKjo2iHcfQeCq1MXZv 2lT7fWsm5LvmzQbpYNmzfq0zfmKoNBB2Hormoc2Nxr/ygZFJWOKhGti3n6JEt2HCcgxvAI8 2k30LO0Qzu36N9dw4aa9blRw3/MU481tAEWxglaySO6S/bV9Ct5mbC4r/Mt0UYQ1rhOQXfy 06YZBPOCSA9Q+MZlcnpjw== UI-OutboundReport: notjunk:1;M01:P0:KXdqfD5vRkE=;weyosRkKYyhRHf0fxReXMoNGyZa eQaQ/ytru5Ufb7jYrX9YaqH9d6d+SQ0DVWqQyoMfEYV3M54K7drqPg8SdnTBKkaLufUQqWGNc Oz5TwVkXRe5/2LEV7BdDfyjQVsfBPP3EEZ2do0TpvaIXnZtYJJ+i4DPD4XtupEnjLKNz3DQ+t cnlz/iiQBIwpUsgWY989kmd7+YM0bx77jfBqIX5BpRQdGvAQJPNZbHe8FHM4HOEb+l6m3zA1j yOVrkuBkL3B+IkQxCIn+qQejx/Li4eDnp9mUN6+jtmj3ECBeUOmwFYjj/NE7ObbQzK2Yh0kzY nnOL31z37RbvxI+YT6K0PxzUSjjs/o4rpCLBP+EUlO4JarGBLOlAPqUTPsgtuOZbYS9JZyTWt MWmvNqoeRyk21Xe5vPUtZCrKXatHeP9nZFg5ULUAdxoy6e8CEL4nMmkFVQQB0Tl2fphGS90lo UDUfS/Tv7Rek+50r3Rpb8fgqajtFqH6nbkOgnztNicmw64mVVY5DlJeB5ZqXOgBX1VZXB3tWN B1ITIwfEqYBD+yUcppWsSDUCx5hRn3n0ZxHUutq7Us2kepOsrz9bu8+ceGfoVf6hiOeEKkLsx G5f3MRjbEQrzIBU9OLCrLbxNCMz35xK7vRhcX3pbmK52MZMcMXiPhk2sDSSVN1QAB0VV721D/ gOYnw98moDKdjhFciByElQnof2kmT4a97JxZOpSRRCGtWAEp6O0cLf0etmcFxYogBBLFG+MfN An5Lir2PtTyaX/W53tFxIjGaVyju1icidEu9UDj7uWZ5CPqnxZ/Ajl8nw3ksNeNoIEiIOHk5L B5WmZuMhnFHhVW8zdnG7tNy8QWF6ZiWSr2vmNjgUK9NxGL7VLXR7AgRZyFzLrATcALHCuORA2 9bK/pq3mnvNrbZqX2cRYzg7dKt7LWBWpvdtS89OptzHfNZyfp2UuQAPd9/oYfvSUYgzDWuINI LtmAOQv/WPoNyzpn/onLH2zIACU= Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org If execve(2) fails with ENOENT and we report the error, we use the format "cannot run %s", followed by the actual error message. For other errors we use "cannot exec '%s'". Stop making this subtle distinction and use the second format for all execve(2) errors. This simplifies the code and makes the prefix more precise by indicating the failed operation. It also allows us to slightly simplify t1800.16. On Windows -- which lacks execve(2) -- we already use a single format in all cases: "cannot spawn %s". Signed-off-by: René Scharfe --- Patch formatted with -U6 for easier review. run-command.c | 14 +++----------- t/t1800-hook.sh | 2 +- 2 files changed, 4 insertions(+), 12 deletions(-) -- 2.41.0 diff --git a/run-command.c b/run-command.c index 60c9419866..758f8534da 100644 --- a/run-command.c +++ b/run-command.c @@ -304,13 +304,12 @@ static int child_notifier = -1; enum child_errcode { CHILD_ERR_CHDIR, CHILD_ERR_DUP2, CHILD_ERR_CLOSE, CHILD_ERR_SIGPROCMASK, - CHILD_ERR_ENOENT, CHILD_ERR_SILENT, CHILD_ERR_ERRNO }; struct child_err { enum child_errcode err; @@ -387,15 +386,12 @@ static void child_err_spew(struct child_process *cmd, struct child_err *cerr) case CHILD_ERR_CLOSE: error_errno("close() in child failed"); break; case CHILD_ERR_SIGPROCMASK: error_errno("sigprocmask failed restoring signals"); break; - case CHILD_ERR_ENOENT: - error_errno("cannot run %s", cmd->args.v[0]); - break; case CHILD_ERR_SILENT: break; case CHILD_ERR_ERRNO: error_errno("cannot exec '%s'", cmd->args.v[0]); break; } @@ -843,19 +839,15 @@ int start_command(struct child_process *cmd) execve(argv.v[1], (char *const *) argv.v + 1, (char *const *) childenv); if (errno == ENOEXEC) execve(argv.v[0], (char *const *) argv.v, (char *const *) childenv); - if (errno == ENOENT) { - if (cmd->silent_exec_failure) - child_die(CHILD_ERR_SILENT); - child_die(CHILD_ERR_ENOENT); - } else { - child_die(CHILD_ERR_ERRNO); - } + if (cmd->silent_exec_failure && errno == ENOENT) + child_die(CHILD_ERR_SILENT); + child_die(CHILD_ERR_ERRNO); } atfork_parent(&as); if (cmd->pid < 0) error_errno("cannot fork() for %s", cmd->args.v[0]); else if (cmd->clean_on_exit) mark_child_for_cleanup(cmd->pid, cmd); diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh index c156d6decc..8b0234cf2d 100755 --- a/t/t1800-hook.sh +++ b/t/t1800-hook.sh @@ -161,13 +161,13 @@ test_expect_success 'git hook run a hook with a bad shebang' ' hook run test-hook >out 2>err && test_must_be_empty out && # TODO: We should emit the same (or at least a more similar) # error on MINGW (essentially Git for Windows) and all other # platforms.. See the OS-specific code in start_command() - grep -E "^(error|fatal): cannot (exec|run|spawn) .*bad-hooks/test-hook" err + grep -E "^(error|fatal): cannot (exec|spawn) .*bad-hooks/test-hook" err ' test_expect_success 'stdin to hooks' ' write_script .git/hooks/test-hook <<-\EOF && echo BEGIN stdin cat