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>
This commit is contained in:
Clemens Buchacher
2011-07-27 23:32:34 +02:00
committed by Junio C Hamano
parent 2579e1d293
commit 3bc4181fde
3 changed files with 27 additions and 8 deletions

18
usage.c
View File

@@ -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;