diff options
author | Junio C Hamano <gitster@pobox.com> | 2011-08-17 17:25:55 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-08-17 17:25:55 -0700 |
commit | 253348b2dbb6519c82e6bc3543c652b9727771ed (patch) | |
tree | 27b77cb1cf424396f9c609ad062766411fe6adeb | |
parent | ddd89c6f86210f18ce19198d163e05dfd311c5ce (diff) | |
parent | fc1b56f054a79400c4e72cb1aab97ba2605cbd83 (diff) | |
download | git-253348b2dbb6519c82e6bc3543c652b9727771ed.tar.gz git-253348b2dbb6519c82e6bc3543c652b9727771ed.tar.xz |
Merge branch 'cb/maint-exec-error-report'
* cb/maint-exec-error-report:
notice error exit from pager
error_routine: use parent's stderr if exec fails
-rw-r--r-- | git-compat-util.h | 2 | ||||
-rw-r--r-- | run-command.c | 30 | ||||
-rw-r--r-- | usage.c | 18 |
3 files changed, 33 insertions, 17 deletions
diff --git a/git-compat-util.h b/git-compat-util.h index ddfbf7714..5ef8ff76f 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -240,6 +240,7 @@ extern char *gitbasename(char *); /* General helper functions */ extern void vreportf(const char *prefix, const char *err, va_list params); +extern void vwritef(int fd, const char *prefix, const char *err, va_list params); extern NORETURN void usage(const char *err); extern NORETURN void usagef(const char *err, ...) __attribute__((format (printf, 1, 2))); extern NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2))); @@ -248,6 +249,7 @@ extern int error(const char *err, ...) __attribute__((format (printf, 1, 2))); extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2))); extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params)); +extern void set_error_routine(void (*routine)(const char *err, va_list params)); extern int prefixcmp(const char *str, const char *prefix); extern int suffixcmp(const char *str, const char *suffix); diff --git a/run-command.c b/run-command.c index 70e8a249d..a2796c4ca 100644 --- a/run-command.c +++ b/run-command.c @@ -77,16 +77,14 @@ static void notify_parent(void) static NORETURN void die_child(const char *err, va_list params) { - char msg[4096]; - int len = vsnprintf(msg, sizeof(msg), err, params); - if (len > sizeof(msg)) - len = sizeof(msg); - - write_in_full(child_err, "fatal: ", 7); - write_in_full(child_err, msg, len); - write_in_full(child_err, "\n", 1); + vwritef(child_err, "fatal: ", err, params); exit(128); } + +static void error_child(const char *err, va_list params) +{ + vwritef(child_err, "error: ", err, params); +} #endif static inline void set_cloexec(int fd) @@ -127,9 +125,6 @@ static int wait_or_whine(pid_t pid, const char *argv0, int silent_exec_failure) 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); @@ -217,6 +212,7 @@ fail_pipe: set_cloexec(child_err); } set_die_routine(die_child); + set_error_routine(error_child); close(notify_pipe[0]); set_cloexec(notify_pipe[1]); @@ -283,14 +279,14 @@ fail_pipe: } else { execvp(cmd->argv[0], (char *const*) cmd->argv); } - /* - * Do not check for cmd->silent_exec_failure; the parent - * process will check it when it sees this exit code. - */ - if (errno == ENOENT) + if (errno == ENOENT) { + if (!cmd->silent_exec_failure) + error("cannot run %s: %s", cmd->argv[0], + strerror(ENOENT)); exit(127); - else + } else { die_errno("cannot exec '%s'", cmd->argv[0]); + } } if (cmd->pid < 0) error("cannot fork() for %s: %s", cmd->argv[0], @@ -4,6 +4,7 @@ * Copyright (C) Linus Torvalds, 2005 */ #include "git-compat-util.h" +#include "cache.h" void vreportf(const char *prefix, const char *err, va_list params) { @@ -12,6 +13,18 @@ void vreportf(const char *prefix, const char *err, va_list params) fprintf(stderr, "%s%s\n", prefix, msg); } +void vwritef(int fd, const char *prefix, const char *err, va_list params) +{ + char msg[4096]; + int len = vsnprintf(msg, sizeof(msg), err, params); + if (len > sizeof(msg)) + len = sizeof(msg); + + write_in_full(fd, prefix, strlen(prefix)); + write_in_full(fd, msg, len); + write_in_full(fd, "\n", 1); +} + static NORETURN void usage_builtin(const char *err, va_list params) { vreportf("usage: ", err, params); @@ -46,6 +59,11 @@ void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list param die_routine = routine; } +void set_error_routine(void (*routine)(const char *err, va_list params)) +{ + error_routine = routine; +} + void NORETURN usagef(const char *err, ...) { va_list params; |