summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Clemens Buchacher <drizzd@aon.at>2011-07-27 23:32:34 +0200
committerLibravatar Junio C Hamano <gitster@pobox.com>2011-07-31 18:27:07 -0700
commit3bc4181fde899e02aff89f7c0a47f18d37311cb3 (patch)
treeeacd31e4e1a91b6ad7fb2317b007c5203675e0e6
parenttests: print failed test numbers at the end of the test run (diff)
downloadtgif-3bc4181fde899e02aff89f7c0a47f18d37311cb3.tar.xz
error_routine: use parent's stderr if exec fails
The new process's error output may be redirected elsewhere, but if the exec fails, output should still go to the parent's stderr. This has already been done for the die_routine. Do the same for error_routine. Signed-off-by: Clemens Buchacher <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--git-compat-util.h2
-rw-r--r--run-command.c15
-rw-r--r--usage.c18
3 files changed, 27 insertions, 8 deletions
diff --git a/git-compat-util.h b/git-compat-util.h
index e0bb81ed8d..041cbdb93e 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -236,6 +236,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)));
@@ -244,6 +245,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 70e8a249d0..5c91f37fb8 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)
@@ -217,6 +215,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]);
diff --git a/usage.c b/usage.c
index b5e67e3d0d..a2a6678004 100644
--- a/usage.c
+++ b/usage.c
@@ -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;