summaryrefslogtreecommitdiff
path: root/usage.c
diff options
context:
space:
mode:
authorClemens Buchacher <drizzd@aon.at>2011-07-27 23:32:34 +0200
committerJunio C Hamano <gitster@pobox.com>2011-07-31 18:27:07 -0700
commit3bc4181fde899e02aff89f7c0a47f18d37311cb3 (patch)
treeeacd31e4e1a91b6ad7fb2317b007c5203675e0e6 /usage.c
parent2579e1d2936ad4e385ef21e5c346d9853d7faa01 (diff)
downloadgit-3bc4181fde899e02aff89f7c0a47f18d37311cb3.tar.gz
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>
Diffstat (limited to 'usage.c')
-rw-r--r--usage.c18
1 files changed, 18 insertions, 0 deletions
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;