diff options
author | Clemens Buchacher <drizzd@aon.at> | 2011-07-27 23:32:34 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-07-31 18:27:07 -0700 |
commit | 3bc4181fde899e02aff89f7c0a47f18d37311cb3 (patch) | |
tree | eacd31e4e1a91b6ad7fb2317b007c5203675e0e6 /usage.c | |
parent | 2579e1d2936ad4e385ef21e5c346d9853d7faa01 (diff) | |
download | git-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.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -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; |