git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH/RFC] sane_execvp(): ignore non-directory on PATH
@ 2012-07-31 19:46 Junio C Hamano
  2012-07-31 20:23 ` Jeff King
  0 siblings, 1 reply; 2+ messages in thread
From: Junio C Hamano @ 2012-07-31 19:46 UTC (permalink / raw)
  To: git; +Cc: Jeff King

When you have a non-directory on your PATH, a funny thing happens:

	$ PATH=$PATH:/bin/sh git foo
	fatal: cannot exec 'git-foo': Not a directory?

Worse yet, as real commands always take precedence over aliases,
this behaviour interacts rather badly with them:

	$ PATH=$PATH:/bin/sh git -c alias.foo=show git foo -s
	fatal: cannot exec 'git-foo': Not a directory?

This is because an ENOTDIR error from the underlying execvp(2) is
reported back to the caller of our sane_execvp() wrapper as-is.  By
translating it to ENOENT, just like the case where we _might_ have
the command in an unreadable directory, fixes it.  Without an alias,
we would get

	git: 'foo' is not a git command. See 'git --help'.

and we use the 'foo' alias when it is available.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

 * We can view this as a follow-up to 38f865c (run-command: treat
   inaccessible directories as ENOENT, 2012-03-30).

 run-command.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/run-command.c b/run-command.c
index 805d41f..f9b7db2 100644
--- a/run-command.c
+++ b/run-command.c
@@ -77,6 +77,8 @@ int sane_execvp(const char *file, char * const argv[])
 	 */
 	if (errno == EACCES && !strchr(file, '/'))
 		errno = exists_in_PATH(file) ? EACCES : ENOENT;
+	else if (errno == ENOTDIR && !strchr(file, '/'))
+		errno = ENOENT;
 	return -1;
 }
 

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

end of thread, other threads:[~2012-07-31 20:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-31 19:46 [PATCH/RFC] sane_execvp(): ignore non-directory on PATH Junio C Hamano
2012-07-31 20:23 ` Jeff King

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 NNTP newsgroup(s).