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

Re: [PATCH] run-command.c: Accept EACCES as command not found

From
Frans Klaver <fransklaver@gmail.com>
Date
Nov 21, 2011, 23:06 UTC
Message-ID
<op.v5bjtk1r0aolir@keputer>
In-Reply-To
<7vbos5f7ix.fsf@alter.siamese.dyndns.org>

On Mon, 21 Nov 2011 23:13:58 +0100, Junio C Hamano <gitster@pobox.com> wrote:

Show 12 quoted lines
> Frans Klaver <fransklaver@gmail.com> writes:
>
>> execvp returns ENOENT if a command was not found after searching PATH.
>> If path contains a directory that current user has insufficient
>> privileges to, EACCES is returned. This may still mean the program
>> wasn't found.
>>
>> If the latter case is encountered, git errors out without giving aliases
>> a try,...
>
> Isn't that a *good* thing in general, though, so that the user can
> diagnose the breakage in the $PATH and fix it?

Actually I went through diagnosing and fixing it. After tracking it down, I did wonder about this question myself and I didn't come to a definitive conclusion on it. On one hand I do agree that it may be an incentive for the user to fix his path. On the other hand I found it an obscure one to track down; git's behavior doesn't match bash behavior:

$ git config --global alias.aliasedinit init && mkdir searchpath && chmod 400 searchpath && PATH=$(pwd)/searchpath:$PATH && export PATH && mkdir someproject && cd someproject && git aliasedinit fatal: cannot exec 'git-aliasedinit': Permission denied

$ git-aliasedinit bash: git-aliasedinit: command not found

This isn't very intuitive to track down an incorrect PATH with, imo. You have to dig into git core code, learn about how git handles commands, learn about debugging forked processes, and find out that execvp uses EACCES for more than just "permission denied" _just_ to find out you've got a wrong environment variable lying about. That's a full day of work gone for a newbie. If bash would also tell me in natural language that permission was denied, I wouldn't even have considered doing this patch.

For my part the root of the problem lies with the use of EACCES by execvp here, not so much with how git uses it. For this particular case, EACCES doesn't just mean "it exists, but you cannot execute this", it may also mean "not found, but one of the paths could not be accessed". If git were to provide a really helpful message, we'd have to detect which paths got denied. Once we know that, we can even on the spot decide to error out or not. In other words, we'd have to figure out which meaning of EACCES is actually used. Based on that, git can error out, warn or ignore at will.

In any case, I thought it best to have other developers have a look at it. I can put a bit more of that information in the commit message, but I'd be just as happy to drop the patch and keep the exercise.

Frans
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 25 in “run-command.c: Accept EACCES as command not found”
  1. run-command.c: Accept EACCES as command not foundFrans Klaver, Nov 21, 2011
  2. Junio C HamanoNov 21, 2011
  3. Frans KlaverNov 21, 2011
  4. Junio C HamanoNov 21, 2011
  5. Frans KlaverNov 22, 2011
  6. Frans KlaverNov 23, 2011
  7. Nguyen Thai Ngoc DuyNov 23, 2011
  8. Frans KlaverNov 23, 2011
  9. Frans KlaverNov 23, 2011
  10. 0/2 run-command: Add EACCES diagnosticsFrans Klaver, Dec 6, 2011
  11. 1/2 run-command: Add checks after execvp fails with EACCESFrans Klaver, Dec 6, 2011
  12. Junio C HamanoDec 6, 2011
  13. Frans KlaverDec 7, 2011
  14. Frans KlaverDec 8, 2011
  15. Junio C HamanoDec 9, 2011
  16. Frans KlaverDec 9, 2011
  17. 2/2 run-command: Add interpreter permissions checkFrans Klaver, Dec 6, 2011
  18. Junio C HamanoDec 6, 2011
  19. Frans KlaverDec 7, 2011
  20. 0/2 run-command: Add eacces diagnosticsFrans Klaver, Dec 13, 2011
  21. 1/2 run-command: Add checks after execvp fails with EACCESFrans Klaver, Dec 13, 2011
  22. Junio C HamanoDec 13, 2011
  23. Frans KlaverDec 14, 2011
  24. Frans KlaverDec 14, 2011
  25. 2/2 run-command: Add interpreter permissions checkFrans Klaver, Dec 13, 2011

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.