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

Re: [PATCH 2/2] git: continue alias lookup on EACCES errors

From
Jeff King <peff@peff.net>
Date
Mar 28, 2012, 20:51 UTC
Message-ID
<20120328205144.GA10174@sigill.intra.peff.net>
In-Reply-To
<20120328204221.GE8982@burratino>
On Wed, Mar 28, 2012 at 03:42:21PM -0500, Jonathan Nieder wrote:
> > +		path = mkpath("%.*s/%s", (int)(end - p), p, file);
> [...]
>  - (end - p) is not guaranteed to fit inside an int.  What should happen
>    when my PATH is very long?

That is the cost of using the mkpath convenience function (otherwise, the compiler will complain that ".*" expects an int). We can do it manually, but in practice, do you really expect your PATH environment variable to overflow an int?

>  - the existence check would be simpler spelled as access(path, F_OK).

Yeah, I think that is nicer. I went with !stat() because that is our usual file_exists test, and I was wondering if there were any portability issues with access(..., F_OK). However, we seem to use it already in other places, so it should be fine.

>  - the above checks if there is _any_ nonexecutable instance of "file"
>    in the directories listed in $PATH, but isn't what we want to check
>    whether _all_ of them are nonexecutable?

If there is one that is executable, then execvp would not have returned. So if there is any entry that is non-executable, then they all are. And we don't care about the actual number; we only care whether there is one (in which case it is no ENOENT).

Show 14 quoted lines
> > +int sane_execvp(const char *file, char * const argv[])
> > +{
> > +	int ret = execvp(file, argv);
> > +	if (ret < 0 && errno == EACCES && !file_in_path_is_nonexecutable(file))
> > +		errno = ENOENT;
> > +	return ret;
> > +}
> 
> Makes sense.  No objections from me.
> 
> 	if (!execvp(file, argv))
> 		return 0;
> [...]
> 	return -1;

That is nicer; I have a general avoidance of rewriting return codes, but I think it is safe to translate a non-zero execvp result into -1.

Show 9 quoted lines
> 	/*
> 	 * When a command can't be found because one of the directories
> 	 * listed in $PATH is unsearchable, execvp reports EACCES, but
> 	 * careful usability testing (read: analysis of occasional bug
> 	 * reports) reveals that "No such file or directory" is more
> 	 * intuitive.
> 	 */
> 	if (errno == EACCES && cannot_find_in_PATH(file))
> 		errno = ENOENT;

I think we can even simplify cannot_find to "!exists_in_PATH" to make it even simpler. If it exists and execvp did not execute it, then it must be non-executable (or there is a race condition :) ).

-Peff
Previous: Jonathan NiederNext: Jonathan Nieder
Message 24 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.