From: Johannes Sixt <j6t@kdbg.org>
To: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
Cc: git@vger.kernel.org
Subject: [PATCH 2/4] run-command: move wait_or_whine earlier
Date: Sun, 10 Jan 2010 14:08:45 +0100 [thread overview]
Message-ID: <201001101408.45603.j6t@kdbg.org> (raw)
In-Reply-To: <201001101404.22258.j6t@kdbg.org>
We want to reuse it from start_command.
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
run-command.c | 84 ++++++++++++++++++++++++++++----------------------------
1 files changed, 42 insertions(+), 42 deletions(-)
diff --git a/run-command.c b/run-command.c
index 02c7bfb..dccac37 100644
--- a/run-command.c
+++ b/run-command.c
@@ -39,6 +39,48 @@ static inline void set_cloexec(int fd)
}
#endif
+static int wait_or_whine(pid_t pid, const char *argv0, int silent_exec_failure)
+{
+ int status, code = -1;
+ pid_t waiting;
+ int failed_errno = 0;
+
+ while ((waiting = waitpid(pid, &status, 0)) < 0 && errno == EINTR)
+ ; /* nothing */
+
+ if (waiting < 0) {
+ failed_errno = errno;
+ error("waitpid for %s failed: %s", argv0, strerror(errno));
+ } else if (waiting != pid) {
+ error("waitpid is confused (%s)", argv0);
+ } else if (WIFSIGNALED(status)) {
+ code = WTERMSIG(status);
+ error("%s died of signal %d", argv0, code);
+ /*
+ * This return value is chosen so that code & 0xff
+ * mimics the exit code that a POSIX shell would report for
+ * a program that died from this signal.
+ */
+ code -= 128;
+ } else if (WIFEXITED(status)) {
+ code = WEXITSTATUS(status);
+ /*
+ * Convert special exit code when execvp failed.
+ */
+ if (code == 127) {
+ code = -1;
+ failed_errno = ENOENT;
+ if (!silent_exec_failure)
+ error("cannot run %s: %s", argv0,
+ strerror(ENOENT));
+ }
+ } else {
+ error("waitpid is confused (%s)", argv0);
+ }
+ errno = failed_errno;
+ return code;
+}
+
int start_command(struct child_process *cmd)
{
int need_in, need_out, need_err;
@@ -272,48 +314,6 @@ fail_pipe:
return 0;
}
-static int wait_or_whine(pid_t pid, const char *argv0, int silent_exec_failure)
-{
- int status, code = -1;
- pid_t waiting;
- int failed_errno = 0;
-
- while ((waiting = waitpid(pid, &status, 0)) < 0 && errno == EINTR)
- ; /* nothing */
-
- if (waiting < 0) {
- failed_errno = errno;
- error("waitpid for %s failed: %s", argv0, strerror(errno));
- } else if (waiting != pid) {
- error("waitpid is confused (%s)", argv0);
- } else if (WIFSIGNALED(status)) {
- code = WTERMSIG(status);
- error("%s died of signal %d", argv0, code);
- /*
- * This return value is chosen so that code & 0xff
- * mimics the exit code that a POSIX shell would report for
- * a program that died from this signal.
- */
- code -= 128;
- } else if (WIFEXITED(status)) {
- code = WEXITSTATUS(status);
- /*
- * Convert special exit code when execvp failed.
- */
- if (code == 127) {
- code = -1;
- failed_errno = ENOENT;
- if (!silent_exec_failure)
- error("cannot run %s: %s", argv0,
- strerror(ENOENT));
- }
- } else {
- error("waitpid is confused (%s)", argv0);
- }
- errno = failed_errno;
- return code;
-}
-
int finish_command(struct child_process *cmd)
{
return wait_or_whine(cmd->pid, cmd->argv[0], cmd->silent_exec_failure);
--
1.6.6.115.gd1ab3
next prev parent reply other threads:[~2010-01-10 13:09 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-09 13:45 [RFC PATCH v2 0/2] Imporove remote helper exec failure reporting Ilari Liusvaara
2010-01-09 13:45 ` [RFC PATCH v2 1/2] Report exec errors from run-command Ilari Liusvaara
2010-01-10 13:04 ` [PATCH 0/4] Detect exec errors in start_command early Johannes Sixt
2010-01-10 13:07 ` [PATCH 1/4] start_command: report child process setup errors to the parent's stderr Johannes Sixt
2010-01-10 13:08 ` Johannes Sixt [this message]
2010-01-10 13:11 ` [PATCH 3/4] start_command: detect execvp failures early Johannes Sixt
2010-01-14 21:31 ` Junio C Hamano
2010-01-14 21:53 ` Johannes Sixt
2010-01-14 22:40 ` Junio C Hamano
2010-01-10 13:18 ` [PATCH 4/4] Improve error message when a transport helper was not found Johannes Sixt
2010-01-09 13:45 ` [RFC PATCH v2 2/2] Improve transport helper exec failure reporting Ilari Liusvaara
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=201001101408.45603.j6t@kdbg.org \
--to=j6t@kdbg.org \
--cc=git@vger.kernel.org \
--cc=ilari.liusvaara@elisanet.fi \
/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).