usage.c API users: use die_message() for "fatal :" + exit 128
Change code that printed its own "fatal: " message and exited with a status code of 128 to use the die_message() function added in a preceding commit. This change also demonstrates why the return value of die_message_routine() needed to be that of "report_fn". We have callers such as the run-command.c::child_err_spew() which would like to replace its error routine with the return value of "get_die_message_routine()". Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Dec 7, 2021 at 19:26 UTC
e081a7c3b7290c50c817598e5f2686d068540762
4 files changed
+15
-18
builtin/fast-import.c
+7
-5
@@ -401,16 +401,18 @@ static void dump_marks(void);
401
402
static NORETURN void die_nicely(const char *err, va_list params)
403
{
404
+ va_list cp;
405
static int zombie;
405
- char message[2 * PATH_MAX];
406
+ report_fn die_message_fn = get_die_message_routine();
407
407
- vsnprintf(message, sizeof(message), err, params);
408
- fputs("fatal: ", stderr);
409
- fputs(message, stderr);
410
- fputc('\n', stderr);
408
+ va_copy(cp, params);
409
+ die_message_fn(err, params);
410
411
if (!zombie) {
412
+ char message[2 * PATH_MAX];
413
+
414
zombie = 1;
415
+ vsnprintf(message, sizeof(message), err, cp);
416
write_crash_report(message);
417
end_packfile();
418
unkeep_all_packs();
http-backend.c
+2
-1
@@ -659,8 +659,9 @@ static NORETURN void die_webcgi(const char *err, va_list params)
659
{
660
if (dead <= 1) {
661
struct strbuf hdr = STRBUF_INIT;
662
+ report_fn die_message_fn = get_die_message_routine();
663
663
- vreportf("fatal: ", err, params);
664
+ die_message_fn(err, params);
665
666
http_status(&hdr, 500, "Internal Server Error");
667
hdr_nocache(&hdr);
parse-options.c
+1
-1
@@ -1075,6 +1075,6 @@ void NORETURN usage_msg_opt(const char *msg,
1075
const char * const *usagestr,
1076
const struct option *options)
1077
{
1078
- fprintf(stderr, "fatal: %s\n\n", msg);
1078
+ die_message("%s\n", msg); /* The extra \n is intentional */
1079
usage_with_options(usagestr, options);
1080
}
run-command.c
+5
-11
@@ -340,15 +340,6 @@ static void child_close_pair(int fd[2])
340
child_close(fd[1]);
341
}
342
343
-/*
344
- * parent will make it look like the child spewed a fatal error and died
345
- * this is needed to prevent changes to t0061.
346
- */
347
-static void fake_fatal(const char *err, va_list params)
348
-{
349
- vreportf("fatal: ", err, params);
350
-}
351
-
343
static void child_error_fn(const char *err, va_list params)
344
{
345
const char msg[] = "error() should not be called in child\n";
@@ -372,9 +363,10 @@ static void NORETURN child_die_fn(const char *err, va_list params)
363
static void child_err_spew(struct child_process *cmd, struct child_err *cerr)
364
{
365
static void (*old_errfn)(const char *err, va_list params);
366
+ report_fn die_message_routine = get_die_message_routine();
367
368
old_errfn = get_error_routine();
377
- set_error_routine(fake_fatal);
369
+ set_error_routine(die_message_routine);
370
errno = cerr->syserr;
371
372
switch (cerr->err) {
@@ -1082,7 +1074,9 @@ static void *run_thread(void *data)
1074
1075
static NORETURN void die_async(const char *err, va_list params)
1076
{
1085
- vreportf("fatal: ", err, params);
1077
+ report_fn die_message_fn = get_die_message_routine();
1078
+
1079
+ die_message_fn(err, params);
1080
1081
if (in_async()) {
1082
struct async *async = pthread_getspecific(async_key);