Git Mailing List Archive mirror
 help / color / mirror / Atom feed
* [BUG] Git 2.28.0-rc1 t1800 message text comparison
@ 2022-09-22 19:01 rsbecker
  2022-09-22 19:02 ` [BUG] Git 2.38.0-rc1 " rsbecker
  2022-09-23 20:43 ` rsbecker
  0 siblings, 2 replies; 13+ messages in thread
From: rsbecker @ 2022-09-22 19:01 UTC (permalink / raw)
  To: git

Rc1 is looking good except for this test.

We get a diff as follows:

-fatal: cannot run bad-hooks/test-hook: ...
+fatal: cannot exec 'bad-hooks/test-hook': Permission denied

It looks like the pattern 
sed -e s/test-hook: .*/test-hook: .../

needs to be a bit extended. Adding

sed -e s/exec/run/ | send -e s/["']//g

might help clear off the other noise.

Regards,
Randall


^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: [BUG] Git 2.38.0-rc1 t1800 message text comparison
  2022-09-22 19:01 [BUG] Git 2.28.0-rc1 t1800 message text comparison rsbecker
@ 2022-09-22 19:02 ` rsbecker
  2022-09-23 20:43 ` rsbecker
  1 sibling, 0 replies; 13+ messages in thread
From: rsbecker @ 2022-09-22 19:02 UTC (permalink / raw)
  To: rsbecker, git

On September 22, 2022 3:02 PM, I wrote:
>Rc1 is looking good except for this test.
>
>We get a diff as follows:
>
>-fatal: cannot run bad-hooks/test-hook: ...
>+fatal: cannot exec 'bad-hooks/test-hook': Permission denied
>
>It looks like the pattern
>sed -e s/test-hook: .*/test-hook: .../
>
>needs to be a bit extended. Adding
>
>sed -e s/exec/run/ | send -e s/["']//g
>
>might help clear off the other noise.

The subject should have been 2.38.0, not 2.28.0.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: [BUG] Git 2.38.0-rc1 t1800 message text comparison
  2022-09-22 19:01 [BUG] Git 2.28.0-rc1 t1800 message text comparison rsbecker
  2022-09-22 19:02 ` [BUG] Git 2.38.0-rc1 " rsbecker
@ 2022-09-23 20:43 ` rsbecker
  2022-12-14  5:53   ` rsbecker
  1 sibling, 1 reply; 13+ messages in thread
From: rsbecker @ 2022-09-23 20:43 UTC (permalink / raw)
  To: git

On September 22, 2022 3:03 PM, I wrote:
>On September 22, 2022 3:02 PM, I wrote:
>>Rc1 is looking good except for this test.
>>
>>We get a diff as follows:
>>
>>-fatal: cannot run bad-hooks/test-hook: ...
>>+fatal: cannot exec 'bad-hooks/test-hook': Permission denied
>>
>>It looks like the pattern
>>sed -e s/test-hook: .*/test-hook: .../
>>
>>needs to be a bit extended. Adding
>>
>>sed -e s/exec/run/ | send -e s/["']//g
>>
>>might help clear off the other noise.

A patch that might work is as follows:

diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh
index 43fcb7c0bf..9a723631a2 100755
--- a/t/t1800-hook.sh
+++ b/t/t1800-hook.sh
@@ -173,7 +173,10 @@ test_expect_success 'git hook run a hook with a bad
shebang' '
                -c core.hooksPath=bad-hooks \
                hook run test-hook >out 2>err &&
        test_must_be_empty out &&
-       sed -e "s/test-hook: .*/test-hook: .../" <err >actual &&
+       quot=`echo "\047"` &&
+       sed -e "s/exec/run/" <err | \
+               sed -e "s/$quot//g" | \
+               sed -e "s/test-hook: .*/test-hook: .../" >actual &&
        test_cmp expect actual
 '

This does not require setting up a prerequisite for NonStop and the
technique might make the MING code easier but adding a change from spawn to
run.

-Randall


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* RE: [BUG] Git 2.38.0-rc1 t1800 message text comparison
  2022-09-23 20:43 ` rsbecker
@ 2022-12-14  5:53   ` rsbecker
  2023-05-22 20:39     ` René Scharfe
  0 siblings, 1 reply; 13+ messages in thread
From: rsbecker @ 2022-12-14  5:53 UTC (permalink / raw)
  To: rsbecker, git

On September 23, 2022 4:43 PM, I wrote:
>On September 22, 2022 3:03 PM, I wrote:
>>On September 22, 2022 3:02 PM, I wrote:
>>>Rc1 is looking good except for this test.
>>>
>>>We get a diff as follows:
>>>
>>>-fatal: cannot run bad-hooks/test-hook: ...
>>>+fatal: cannot exec 'bad-hooks/test-hook': Permission denied
>>>
>>>It looks like the pattern
>>>sed -e s/test-hook: .*/test-hook: .../
>>>
>>>needs to be a bit extended. Adding
>>>
>>>sed -e s/exec/run/ | send -e s/["']//g
>>>
>>>might help clear off the other noise.
>
>A patch that might work is as follows:
>
>diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh index 43fcb7c0bf..9a723631a2
>100755
>--- a/t/t1800-hook.sh
>+++ b/t/t1800-hook.sh
>@@ -173,7 +173,10 @@ test_expect_success 'git hook run a hook with a bad
>shebang' '
>                -c core.hooksPath=bad-hooks \
>                hook run test-hook >out 2>err &&
>        test_must_be_empty out &&
>-       sed -e "s/test-hook: .*/test-hook: .../" <err >actual &&
>+       quot=`echo "\047"` &&
>+       sed -e "s/exec/run/" <err | \
>+               sed -e "s/$quot//g" | \
>+               sed -e "s/test-hook: .*/test-hook: .../" >actual &&
>        test_cmp expect actual
> '
>
>This does not require setting up a prerequisite for NonStop and the
technique
>might make the MING code easier but adding a change from spawn to run.

This is still broken on NonStop. Is there any hope of a resolution?

Thanks,
Randall


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [BUG] Git 2.38.0-rc1 t1800 message text comparison
  2022-12-14  5:53   ` rsbecker
@ 2023-05-22 20:39     ` René Scharfe
  2023-05-22 20:49       ` rsbecker
  0 siblings, 1 reply; 13+ messages in thread
From: René Scharfe @ 2023-05-22 20:39 UTC (permalink / raw)
  To: rsbecker, git

Am 14.12.22 um 06:53 schrieb rsbecker@nexbridge.com:
> On September 23, 2022 4:43 PM, I wrote:
>> On September 22, 2022 3:03 PM, I wrote:
>>> On September 22, 2022 3:02 PM, I wrote:
>>>> Rc1 is looking good except for this test.
>>>>
>>>> We get a diff as follows:
>>>>
>>>> -fatal: cannot run bad-hooks/test-hook: ...
>>>> +fatal: cannot exec 'bad-hooks/test-hook': Permission denied
>>>>
>>>> It looks like the pattern
>>>> sed -e s/test-hook: .*/test-hook: .../
>>>>
>>>> needs to be a bit extended. Adding
>>>>
>>>> sed -e s/exec/run/ | send -e s/["']//g
>>>>
>>>> might help clear off the other noise.
>>
>> A patch that might work is as follows:
>>
>> diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh index 43fcb7c0bf..9a723631a2
>> 100755
>> --- a/t/t1800-hook.sh
>> +++ b/t/t1800-hook.sh
>> @@ -173,7 +173,10 @@ test_expect_success 'git hook run a hook with a bad
>> shebang' '
>>                -c core.hooksPath=bad-hooks \
>>                hook run test-hook >out 2>err &&
>>        test_must_be_empty out &&
>> -       sed -e "s/test-hook: .*/test-hook: .../" <err >actual &&
>> +       quot=`echo "\047"` &&
>> +       sed -e "s/exec/run/" <err | \
>> +               sed -e "s/$quot//g" | \
>> +               sed -e "s/test-hook: .*/test-hook: .../" >actual &&
>>        test_cmp expect actual
>> '
>>
>> This does not require setting up a prerequisite for NonStop and the
> technique
>> might make the MING code easier but adding a change from spawn to run.
>
> This is still broken on NonStop. Is there any hope of a resolution?

So trying to execute an executable file consisting only of the line
"#!/bad/path/no/spaces" causes NonStop to report "Permission denied"?
That message text belongs to error code EACCES, not to EPERM ("Operation
not permitted"), right?

POSIX allows execve to return EACCES if the file to execute is not a
regular file and executing that file type is not supported or if
permissions are missing to one of its path components.

Either you have something called /bad that is not a regular file (e.g. a
directory) -- then it's just a matter of changing the test to use a
different supposedly non-existing filename, perhaps by creating and
deleting a temporary file for just that purpose.

Or NonStop correctly returns ENOEXEC on the first execve(2) call in
run-command.c and returns ENOACCES on the fallback with SHELL_PATH
(default value /usr/coreutils/bin/bash), because you are not allowed to
execute that shell.  Then SHELL_PATH needs to be corrected.

Or valid shells need to be placed in some kind of allow list to be
accepted in #!-lines, lest NonStop returns ENOACCES on them.  Or NonStop
is simply reporting a bogus error code for some reason.  In those cases
you probably need an execve) compat/ wrapper that corrects the error
code.

Or I'm missing something here, which is a relatively safe bet.  Anyway,
depending on the cause of the "Permission denied" message, loosening the
textual comparison in the test might not be enough.  There may not be a
point for end users to distinguish between "exec" vs. "run", but the
silent_exec_failure feature of run-command depends on the error code
being ENOENT.

René


^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: [BUG] Git 2.38.0-rc1 t1800 message text comparison
  2023-05-22 20:39     ` René Scharfe
@ 2023-05-22 20:49       ` rsbecker
  2023-05-22 21:13         ` rsbecker
  0 siblings, 1 reply; 13+ messages in thread
From: rsbecker @ 2023-05-22 20:49 UTC (permalink / raw)
  To: 'René Scharfe', git

On Monday, May 22, 2023 4:39 PM, René Scharfe wrote:
>Am 14.12.22 um 06:53 schrieb rsbecker@nexbridge.com:
>> On September 23, 2022 4:43 PM, I wrote:
>>> On September 22, 2022 3:03 PM, I wrote:
>>>> On September 22, 2022 3:02 PM, I wrote:
>>>>> Rc1 is looking good except for this test.
>>>>>
>>>>> We get a diff as follows:
>>>>>
>>>>> -fatal: cannot run bad-hooks/test-hook: ...
>>>>> +fatal: cannot exec 'bad-hooks/test-hook': Permission denied
>>>>>
>>>>> It looks like the pattern
>>>>> sed -e s/test-hook: .*/test-hook: .../
>>>>>
>>>>> needs to be a bit extended. Adding
>>>>>
>>>>> sed -e s/exec/run/ | send -e s/["']//g
>>>>>
>>>>> might help clear off the other noise.
>>>
>>> A patch that might work is as follows:
>>>
>>> diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh index
>>> 43fcb7c0bf..9a723631a2
>>> 100755
>>> --- a/t/t1800-hook.sh
>>> +++ b/t/t1800-hook.sh
>>> @@ -173,7 +173,10 @@ test_expect_success 'git hook run a hook with a
>>> bad shebang' '
>>>                -c core.hooksPath=bad-hooks \
>>>                hook run test-hook >out 2>err &&
>>>        test_must_be_empty out &&
>>> -       sed -e "s/test-hook: .*/test-hook: .../" <err >actual &&
>>> +       quot=`echo "\047"` &&
>>> +       sed -e "s/exec/run/" <err | \
>>> +               sed -e "s/$quot//g" | \
>>> +               sed -e "s/test-hook: .*/test-hook: .../" >actual &&
>>>        test_cmp expect actual
>>> '
>>>
>>> This does not require setting up a prerequisite for NonStop and the
>> technique
>>> might make the MING code easier but adding a change from spawn to run.
>>
>> This is still broken on NonStop. Is there any hope of a resolution?
>
>So trying to execute an executable file consisting only of the line
>"#!/bad/path/no/spaces" causes NonStop to report "Permission denied"?
>That message text belongs to error code EACCES, not to EPERM ("Operation not
>permitted"), right?

That should be correct, although the OS Devs I spoke to about this said "EPERM". I am experimenting.

>POSIX allows execve to return EACCES if the file to execute is not a regular file and
>executing that file type is not supported or if permissions are missing to one of its
>path components.

Part of the OS Dev's response was that POSIX is actually ambiguous on this point. Linux made the decision to use ENOENT. NonStop decided to use EPERM (although it may actually be EACCESS - I will report back.

>Either you have something called /bad that is not a regular file (e.g. a
>directory) -- then it's just a matter of changing the test to use a different supposedly
>non-existing filename, perhaps by creating and deleting a temporary file for just that
>purpose.
>
>Or NonStop correctly returns ENOEXEC on the first execve(2) call in run-command.c
>and returns ENOACCES on the fallback with SHELL_PATH (default value
>/usr/coreutils/bin/bash), because you are not allowed to execute that shell.  Then
>SHELL_PATH needs to be corrected.
>
>Or valid shells need to be placed in some kind of allow list to be accepted in #!-lines,
>lest NonStop returns ENOACCES on them.  Or NonStop is simply reporting a bogus
>error code for some reason.  In those cases you probably need an execve) compat/
>wrapper that corrects the error code.
>
>Or I'm missing something here, which is a relatively safe bet.  Anyway, depending on
>the cause of the "Permission denied" message, loosening the textual comparison in
>the test might not be enough.  There may not be a point for end users to distinguish
>between "exec" vs. "run", but the silent_exec_failure feature of run-command
>depends on the error code being ENOENT.

I will report my debug findings.
--Randall


^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: [BUG] Git 2.38.0-rc1 t1800 message text comparison
  2023-05-22 20:49       ` rsbecker
@ 2023-05-22 21:13         ` rsbecker
  2023-06-04 12:13           ` René Scharfe
  0 siblings, 1 reply; 13+ messages in thread
From: rsbecker @ 2023-05-22 21:13 UTC (permalink / raw)
  To: rsbecker, 'René Scharfe', git

On Monday, May 22, 2023 4:49 PM, I wrote:
>On Monday, May 22, 2023 4:39 PM, René Scharfe wrote:
>>Am 14.12.22 um 06:53 schrieb rsbecker@nexbridge.com:
>>> On September 23, 2022 4:43 PM, I wrote:
>>>> On September 22, 2022 3:03 PM, I wrote:
>>>>> On September 22, 2022 3:02 PM, I wrote:
>>>>>> Rc1 is looking good except for this test.
>>>>>>
>>>>>> We get a diff as follows:
>>>>>>
>>>>>> -fatal: cannot run bad-hooks/test-hook: ...
>>>>>> +fatal: cannot exec 'bad-hooks/test-hook': Permission denied
>>>>>>
>>>>>> It looks like the pattern
>>>>>> sed -e s/test-hook: .*/test-hook: .../
>>>>>>
>>>>>> needs to be a bit extended. Adding
>>>>>>
>>>>>> sed -e s/exec/run/ | send -e s/["']//g
>>>>>>
>>>>>> might help clear off the other noise.
>>>>
>>>> A patch that might work is as follows:
>>>>
>>>> diff --git a/t/t1800-hook.sh b/t/t1800-hook.sh index
>>>> 43fcb7c0bf..9a723631a2
>>>> 100755
>>>> --- a/t/t1800-hook.sh
>>>> +++ b/t/t1800-hook.sh
>>>> @@ -173,7 +173,10 @@ test_expect_success 'git hook run a hook with a
>>>> bad shebang' '
>>>>                -c core.hooksPath=bad-hooks \
>>>>                hook run test-hook >out 2>err &&
>>>>        test_must_be_empty out &&
>>>> -       sed -e "s/test-hook: .*/test-hook: .../" <err >actual &&
>>>> +       quot=`echo "\047"` &&
>>>> +       sed -e "s/exec/run/" <err | \
>>>> +               sed -e "s/$quot//g" | \
>>>> +               sed -e "s/test-hook: .*/test-hook: .../" >actual &&
>>>>        test_cmp expect actual
>>>> '
>>>>
>>>> This does not require setting up a prerequisite for NonStop and the
>>> technique
>>>> might make the MING code easier but adding a change from spawn to run.
>>>
>>> This is still broken on NonStop. Is there any hope of a resolution?
>>
>>So trying to execute an executable file consisting only of the line
>>"#!/bad/path/no/spaces" causes NonStop to report "Permission denied"?
>>That message text belongs to error code EACCES, not to EPERM
>>("Operation not permitted"), right?
>
>That should be correct, although the OS Devs I spoke to about this said "EPERM". I
>am experimenting.
>
>>POSIX allows execve to return EACCES if the file to execute is not a
>>regular file and executing that file type is not supported or if
>>permissions are missing to one of its path components.
>
>Part of the OS Dev's response was that POSIX is actually ambiguous on this point.
>Linux made the decision to use ENOENT. NonStop decided to use EPERM (although it
>may actually be EACCESS - I will report back.
>
>>Either you have something called /bad that is not a regular file (e.g.
>>a
>>directory) -- then it's just a matter of changing the test to use a
>>different supposedly non-existing filename, perhaps by creating and
>>deleting a temporary file for just that purpose.
>>
>>Or NonStop correctly returns ENOEXEC on the first execve(2) call in
>>run-command.c and returns ENOACCES on the fallback with SHELL_PATH
>>(default value /usr/coreutils/bin/bash), because you are not allowed to
>>execute that shell.  Then SHELL_PATH needs to be corrected.
>>
>>Or valid shells need to be placed in some kind of allow list to be
>>accepted in #!-lines, lest NonStop returns ENOACCES on them.  Or
>>NonStop is simply reporting a bogus error code for some reason.  In
>>those cases you probably need an execve) compat/ wrapper that corrects the error
>code.
>>
>>Or I'm missing something here, which is a relatively safe bet.  Anyway,
>>depending on the cause of the "Permission denied" message, loosening
>>the textual comparison in the test might not be enough.  There may not
>>be a point for end users to distinguish between "exec" vs. "run", but
>>the silent_exec_failure feature of run-command depends on the error code being
>ENOENT.
>
>I will report my debug findings.

NonStop actually does report EACCES, not EPERM. The comment at the front of run-command.c does describe the situation. The following is a potential fix:

diff --git a/run-command.c b/run-command.c
index 60c9419866..b76e117d35 100644
--- a/run-command.c
+++ b/run-command.c
@@ -846,7 +846,7 @@ int start_command(struct child_process *cmd)
                        execve(argv.v[0], (char *const *) argv.v,
                               (char *const *) childenv);

-               if (errno == ENOENT) {
+               if (errno == ENOENT || errno == EACCES) {
                        if (cmd->silent_exec_failure)
                                child_die(CHILD_ERR_SILENT);
                        child_die(CHILD_ERR_ENOENT);

This does pass and should cover all POSIX interpretations.

Regards,
Randall


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [BUG] Git 2.38.0-rc1 t1800 message text comparison
  2023-05-22 21:13         ` rsbecker
@ 2023-06-04 12:13           ` René Scharfe
  2023-06-04 20:55             ` René Scharfe
  0 siblings, 1 reply; 13+ messages in thread
From: René Scharfe @ 2023-06-04 12:13 UTC (permalink / raw)
  To: rsbecker, git

Am 22.05.23 um 23:13 schrieb rsbecker@nexbridge.com:
> On Monday, May 22, 2023 4:49 PM, I wrote:
>> On Monday, May 22, 2023 4:39 PM, René Scharfe wrote:
>>> So trying to execute an executable file consisting only of the line
>>> "#!/bad/path/no/spaces" causes NonStop to report "Permission denied"?
>>> That message text belongs to error code EACCES, not to EPERM
>>> ("Operation not permitted"), right?
>>
>> That should be correct, although the OS Devs I spoke to about this said "EPERM". I
>> am experimenting.
>>
>>> POSIX allows execve to return EACCES if the file to execute is not a
>>> regular file and executing that file type is not supported or if
>>> permissions are missing to one of its path components.
>>
>> Part of the OS Dev's response was that POSIX is actually ambiguous on this point.
>> Linux made the decision to use ENOENT. NonStop decided to use EPERM (although it
>> may actually be EACCESS - I will report back.

In https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html
I don't see how EACCES would be a valid response in this case.  And it
makes no intuitive sense -- which permission is missing in this
situation?

That doesn't change the fact that this issue needs to be dealt with in
Git somehow.

> NonStop actually does report EACCES, not EPERM. The comment at the
> front of run-command.c does describe the situation.
Do you mean the one about EACCES being reported if a directory in $PATH
is inaccessible in sane_execvp()?  That does not apply here because
"#!/bad/path/no/spaces" specifies an absolute path, so $PATH is not
searched.

> The following is a potential fix:
>
> diff --git a/run-command.c b/run-command.c
> index 60c9419866..b76e117d35 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -846,7 +846,7 @@ int start_command(struct child_process *cmd)
>                         execve(argv.v[0], (char *const *) argv.v,
>                                (char *const *) childenv);
>
> -               if (errno == ENOENT) {
> +               if (errno == ENOENT || errno == EACCES) {
>                         if (cmd->silent_exec_failure)
>                                 child_die(CHILD_ERR_SILENT);
>                         child_die(CHILD_ERR_ENOENT);
>
> This does pass and should cover all POSIX interpretations.

That would misreport execution failures due to missing permissions
(think e.g. "chmod 0 file") as "No such file or directory".  So this
should be only done if really needed, perhaps guarded by an access(2)
check for verifying that EACCES is bogus, and only on affected
platforms.

René




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [BUG] Git 2.38.0-rc1 t1800 message text comparison
  2023-06-04 12:13           ` René Scharfe
@ 2023-06-04 20:55             ` René Scharfe
  2023-06-06  0:31               ` Junio C Hamano
  0 siblings, 1 reply; 13+ messages in thread
From: René Scharfe @ 2023-06-04 20:55 UTC (permalink / raw)
  To: rsbecker, git

Am 04.06.23 um 14:13 schrieb René Scharfe:
> Am 22.05.23 um 23:13 schrieb rsbecker@nexbridge.com:
>> The following is a potential fix:
>>
>> diff --git a/run-command.c b/run-command.c
>> index 60c9419866..b76e117d35 100644
>> --- a/run-command.c
>> +++ b/run-command.c
>> @@ -846,7 +846,7 @@ int start_command(struct child_process *cmd)
>>                         execve(argv.v[0], (char *const *) argv.v,
>>                                (char *const *) childenv);
>>
>> -               if (errno == ENOENT) {
>> +               if (errno == ENOENT || errno == EACCES) {
>>                         if (cmd->silent_exec_failure)
>>                                 child_die(CHILD_ERR_SILENT);
>>                         child_die(CHILD_ERR_ENOENT);
>>
>> This does pass and should cover all POSIX interpretations.
>
> That would misreport execution failures due to missing permissions
> (think e.g. "chmod 0 file") as "No such file or directory".  So this
> should be only done if really needed, perhaps guarded by an access(2)
> check for verifying that EACCES is bogus, and only on affected
> platforms.

Actually the difference is a bit more subtle.  With that patch and
silent_exec_failure on, missing permissions wouldn't be reported
anymore, and with it off the eventual message command would change
from:

                error_errno("cannot exec '%s'", cmd->args.v[0]);

to:

                error_errno("cannot run %s", cmd->args.v[0]);

So the actual errno-based message would be the same, unless its
suppressed.

What's the significance of "run" and "exec" here?  Why do we have both
variants?  Is it to tell apart errors of the actual execve(2) call from
those in code leading up to it (e.g. when searching the executable in
$PATH)?  But at this point we are after the call, so why is ENOENT
from execve(2) a "run" thing, not an "exec" thing?

René

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [BUG] Git 2.38.0-rc1 t1800 message text comparison
  2023-06-04 20:55             ` René Scharfe
@ 2023-06-06  0:31               ` Junio C Hamano
  2023-06-10 14:51                 ` [PATCH 1/2] t1800: loosen matching of error message for bad shebang René Scharfe
  2023-06-10 14:51                 ` [PATCH 2/2] run-command: report exec error even on ENOENT René Scharfe
  0 siblings, 2 replies; 13+ messages in thread
From: Junio C Hamano @ 2023-06-06  0:31 UTC (permalink / raw)
  To: René Scharfe; +Cc: rsbecker, git

René Scharfe <l.s.r@web.de> writes:

> What's the significance of "run" and "exec" here?  Why do we have both
> variants?  Is it to tell apart errors of the actual execve(2) call from
> those in code leading up to it (e.g. when searching the executable in
> $PATH)?  But at this point we are after the call, so why is ENOENT
> from execve(2) a "run" thing, not an "exec" thing?

I was reading output from

    $ git log --reverse -p -SNOENT 7e5d776854e.. run-command.c

45c0961c (run_command(): handle missing command errors more
gracefully, 2009-01-28) explains how we use NOENT to tell between
"we failed to run the command requested because it did not even
exist" and "we failed to run the command and the reason why it
failed is *not* because it did not exist" (the distinction matters
to implement "run command X on $PATH").  To further that, 38f865c2
(run-command: treat inaccessible directories as ENOENT, 2012-03-30)
and a7855083 (sane_execvp(): ignore non-directory on $PATH,
2012-07-31) dealt corner cases where entries on $PATH were
unreadable or were non-directories, but the idea should be the same.

All of the above matters purely when we fail silently (because we
expect only some directories on $PATH contain the command), and I
suspect that the phrasing differences when we _do_ tell the human
user what we failed to run does not matter all that much.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/2] t1800: loosen matching of error message for bad shebang
  2023-06-06  0:31               ` Junio C Hamano
@ 2023-06-10 14:51                 ` René Scharfe
  2023-06-12 18:01                   ` Junio C Hamano
  2023-06-10 14:51                 ` [PATCH 2/2] run-command: report exec error even on ENOENT René Scharfe
  1 sibling, 1 reply; 13+ messages in thread
From: René Scharfe @ 2023-06-10 14:51 UTC (permalink / raw)
  To: git; +Cc: rsbecker, Ævar Arnfjörð Bjarmason, Junio C Hamano

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 <randall.becker@nexbridge.ca>
Signed-off-by: René Scharfe <l.s.r@web.de>
---
 t/t1800-hook.sh | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)

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" </dev/null &&

-	# 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()
-	if test_have_prereq !MINGW
-	then
-		cat >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: .../" <err >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' '
--
2.41.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/2] run-command: report exec error even on ENOENT
  2023-06-06  0:31               ` Junio C Hamano
  2023-06-10 14:51                 ` [PATCH 1/2] t1800: loosen matching of error message for bad shebang René Scharfe
@ 2023-06-10 14:51                 ` René Scharfe
  1 sibling, 0 replies; 13+ messages in thread
From: René Scharfe @ 2023-06-10 14:51 UTC (permalink / raw)
  To: git; +Cc: rsbecker, Junio C Hamano, Ævar Arnfjörð Bjarmason

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 <l.s.r@web.de>
---
Patch formatted with -U6 for easier review.

 run-command.c   | 14 +++-----------
 t/t1800-hook.sh |  2 +-
 2 files changed, 4 insertions(+), 12 deletions(-)

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
--
2.41.0


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] t1800: loosen matching of error message for bad shebang
  2023-06-10 14:51                 ` [PATCH 1/2] t1800: loosen matching of error message for bad shebang René Scharfe
@ 2023-06-12 18:01                   ` Junio C Hamano
  0 siblings, 0 replies; 13+ messages in thread
From: Junio C Hamano @ 2023-06-12 18:01 UTC (permalink / raw)
  To: René Scharfe; +Cc: git, rsbecker, Ævar Arnfjörð Bjarmason

René Scharfe <l.s.r@web.de> writes:

> +	# 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

Looking great.  Thanks.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-06-12 18:01 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-22 19:01 [BUG] Git 2.28.0-rc1 t1800 message text comparison rsbecker
2022-09-22 19:02 ` [BUG] Git 2.38.0-rc1 " rsbecker
2022-09-23 20:43 ` rsbecker
2022-12-14  5:53   ` rsbecker
2023-05-22 20:39     ` René Scharfe
2023-05-22 20:49       ` rsbecker
2023-05-22 21:13         ` rsbecker
2023-06-04 12:13           ` René Scharfe
2023-06-04 20:55             ` René Scharfe
2023-06-06  0:31               ` Junio C Hamano
2023-06-10 14:51                 ` [PATCH 1/2] t1800: loosen matching of error message for bad shebang René Scharfe
2023-06-12 18:01                   ` Junio C Hamano
2023-06-10 14:51                 ` [PATCH 2/2] run-command: report exec error even on ENOENT René Scharfe

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 read-only IMAP folder(s) and NNTP newsgroup(s).