git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	James Pickens <jepicken@gmail.com>, Git ML <git@vger.kernel.org>,
	Frans Klaver <fransklaver@gmail.com>
Subject: Re: [PATCH 2/2] git: continue alias lookup on EACCES errors
Date: Wed, 28 Mar 2012 16:51:44 -0400	[thread overview]
Message-ID: <20120328205144.GA10174@sigill.intra.peff.net> (raw)
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).

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

> 	/*
> 	 * 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

  reply	other threads:[~2012-03-28 20:51 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-26 23:48 Bug? Bad permissions in $PATH breaks Git aliases James Pickens
2012-03-27  3:19 ` Jeff King
2012-03-27  7:25   ` James Pickens
2012-03-27 15:11   ` Junio C Hamano
2012-03-27 17:59     ` Jeff King
2012-03-27 18:04       ` [PATCH 1/2] run-command: propagate EACCES errors to parent Jeff King
2012-03-27 18:24         ` Junio C Hamano
2012-03-27 18:33           ` Jeff King
2012-03-27 18:05       ` [PATCH 2/2] git: continue alias lookup on EACCES errors Jeff King
2012-03-27 19:16         ` Junio C Hamano
2012-03-28  4:30           ` Jeff King
2012-03-28 17:42             ` Junio C Hamano
2012-03-28 17:48               ` Jeff King
2012-03-28 18:04                 ` Jonathan Nieder
2012-03-28 18:31                   ` Junio C Hamano
2012-03-28 18:40                     ` Jonathan Nieder
2012-03-28 19:39                       ` Jeff King
2012-03-28 19:45                         ` Jonathan Nieder
2012-03-28 20:18                           ` Jeff King
2012-03-28 20:37                             ` Jeff King
2012-03-28 20:51                               ` Jonathan Nieder
2012-03-28 20:52                                 ` Jeff King
2012-03-28 20:42                             ` Jonathan Nieder
2012-03-28 20:51                               ` Jeff King [this message]
2012-03-28 21:01                                 ` Jonathan Nieder
2012-03-28 21:25                                   ` Jeff King
2012-03-28 21:30                               ` Frans Klaver
2012-03-28 20:43                             ` Junio C Hamano
2012-03-28 21:04                               ` Jeff King
2012-03-28 21:44                                 ` Junio C Hamano
2012-03-28 21:57                             ` Jeff King
2012-03-28 22:07                               ` Jeff King
2012-03-28 22:18                                 ` Junio C Hamano
2012-03-29 11:31                               ` Frans Klaver
2012-03-29 17:20                                 ` Jeff King
2012-03-29 17:23                                   ` Frans Klaver
2012-03-28 19:38                     ` Jeff King
2012-03-28 18:29                 ` Junio C Hamano
2012-03-28 19:40                   ` Jeff King
2012-03-29 11:16                     ` Frans Klaver
2012-03-29 17:15                       ` Jeff King
2012-03-29 17:21                         ` Frans Klaver
2012-03-27  6:14 ` Bug? Bad permissions in $PATH breaks Git aliases Johannes Sixt
2012-03-27  7:37   ` James Pickens
2012-03-27 15:14     ` Junio C Hamano
2012-03-27 17:48       ` James Pickens
2012-03-27 18:03         ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120328205144.GA10174@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=fransklaver@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jepicken@gmail.com \
    --cc=jrnieder@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).