git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] run-command: propagate EACCES errors to parent

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 27, 2012, 18:24 UTC
Message-ID
<7vhax9j41p.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20120327180425.GA4659@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 17 quoted lines
> The caller of run_command does not directly get access to
> the errno from exec, because it happens in the forked child.
> However, knowing the specific reason for an exec failure can
> help the parent respond better or produce better error
> messages.
>
> We already propagate ENOENT to the parent via exit code 127.
> Let's do the same for EACCES with exit code 126, which is
> already used by bash to indicate the same thing.
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> Actually, there is a slight bending of the truth in the commit message.
> bash implements its own execvp, and it will only return 126/EACCES if a
> file is found via stat(), but is not executable. If there is an
> inaccessible directory in the PATH (meaning that stat() will fail), it
> will silently convert that to 127/ENOENT.

I am wondering what would happen if we treated EACCESS and ENOENT exactly the same way. Wouldn't the four breakage scenarios in the cover letter end up being even better? Case (3) will still say does-not-exist is not a git command (instead of "permission denied", which this patch gives), but your case (2) will see a much better diagnosis.

Take the above with a grain of salt, though, as this is written soon after I wrote my response to James (the one with "I may be a mean person").

Show 30 quoted lines
>  run-command.c |    9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/run-command.c b/run-command.c
> index 1db8abf..e303beb 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -185,6 +185,10 @@ static int wait_or_whine(pid_t pid, const char *argv0, int silent_exec_failure)
>  			code = -1;
>  			failed_errno = ENOENT;
>  		}
> +		else if (code == 126) {
> +			code = -1;
> +			failed_errno = EACCES;
> +		}
>  	} else {
>  		error("waitpid is confused (%s)", argv0);
>  	}
> @@ -346,6 +350,11 @@ fail_pipe:
>  				error("cannot run %s: %s", cmd->argv[0],
>  					strerror(ENOENT));
>  			exit(127);
> +		} else if (errno == EACCES) {
> +			if (!cmd->silent_exec_failure)
> +				error("cannot run %s: %s", cmd->argv[0],
> +					strerror(errno));
> +			exit(126);
>  		} else {
>  			die_errno("cannot exec '%s'", cmd->argv[0]);
>  		}
Previous: Jeff KingNext: Jeff King
Message 7 of 47 in “Bug? Bad permissions in $PATH breaks Git aliases”
  1. James PickensMar 26, 2012
  2. Jeff KingMar 27, 2012
  3. James PickensMar 27, 2012
  4. Junio C HamanoMar 27, 2012
  5. Jeff KingMar 27, 2012
  6. 1/2 run-command: propagate EACCES errors to parentJeff King, Mar 27, 2012
  7. Junio C HamanoMar 27, 2012
  8. Jeff KingMar 27, 2012
  9. 2/2 git: continue alias lookup on EACCES errorsJeff King, Mar 27, 2012
  10. Junio C HamanoMar 27, 2012
  11. Jeff KingMar 28, 2012
  12. Junio C HamanoMar 28, 2012
  13. Jeff KingMar 28, 2012
  14. Jonathan NiederMar 28, 2012
  15. Junio C HamanoMar 28, 2012
  16. Jonathan NiederMar 28, 2012
  17. Jeff KingMar 28, 2012
  18. Jonathan NiederMar 28, 2012
  19. Jeff KingMar 28, 2012
  20. Jeff KingMar 28, 2012
  21. Jonathan NiederMar 28, 2012
  22. Jeff KingMar 28, 2012
  23. Jonathan NiederMar 28, 2012
  24. Jeff KingMar 28, 2012
  25. Jonathan NiederMar 28, 2012
  26. Jeff KingMar 28, 2012
  27. Frans KlaverMar 28, 2012
  28. Junio C HamanoMar 28, 2012
  29. Jeff KingMar 28, 2012
  30. Junio C HamanoMar 28, 2012
  31. Jeff KingMar 28, 2012
  32. Jeff KingMar 28, 2012
  33. Junio C HamanoMar 28, 2012
  34. Frans KlaverMar 29, 2012
  35. Jeff KingMar 29, 2012
  36. Frans KlaverMar 29, 2012
  37. Jeff KingMar 28, 2012
  38. Junio C HamanoMar 28, 2012
  39. Jeff KingMar 28, 2012
  40. Frans KlaverMar 29, 2012
  41. Jeff KingMar 29, 2012
  42. Frans KlaverMar 29, 2012
  43. Johannes SixtMar 27, 2012
  44. James PickensMar 27, 2012
  45. Junio C HamanoMar 27, 2012
  46. James PickensMar 27, 2012
  47. Junio C HamanoMar 27, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.