All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: James Pickens <jepicken@gmail.com>, Git ML <git@vger.kernel.org>
Subject: [PATCH 1/2] run-command: propagate EACCES errors to parent
Date: Tue, 27 Mar 2012 14:04:25 -0400	[thread overview]
Message-ID: <20120327180425.GA4659@sigill.intra.peff.net> (raw)
In-Reply-To: <20120327175933.GA1716@sigill.intra.peff.net>

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.

 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]);
 		}
-- 
1.7.9.5.5.g9b709b

  reply	other threads:[~2012-03-27 18:04 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       ` Jeff King [this message]
2012-03-27 18:24         ` [PATCH 1/2] run-command: propagate EACCES errors to parent 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
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=20120327180425.GA4659@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jepicken@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.