Merge branch 'ab/usage-die-message'
Code clean-up to hide vreportf() from public API. * ab/usage-die-message: config API: use get_error_routine(), not vreportf() usage.c + gc: add and use a die_message_errno() gc: return from cmd_gc(), don't call exit() usage.c API users: use die_message() for error() + exit 128 usage.c API users: use die_message() for "fatal :" + exit 128 usage.c: add a die_message() routinemaint
commit
4b51386bbf
|
@ -401,16 +401,18 @@ static void dump_marks(void);
|
||||||
|
|
||||||
static NORETURN void die_nicely(const char *err, va_list params)
|
static NORETURN void die_nicely(const char *err, va_list params)
|
||||||
{
|
{
|
||||||
|
va_list cp;
|
||||||
static int zombie;
|
static int zombie;
|
||||||
char message[2 * PATH_MAX];
|
report_fn die_message_fn = get_die_message_routine();
|
||||||
|
|
||||||
vsnprintf(message, sizeof(message), err, params);
|
va_copy(cp, params);
|
||||||
fputs("fatal: ", stderr);
|
die_message_fn(err, params);
|
||||||
fputs(message, stderr);
|
|
||||||
fputc('\n', stderr);
|
|
||||||
|
|
||||||
if (!zombie) {
|
if (!zombie) {
|
||||||
|
char message[2 * PATH_MAX];
|
||||||
|
|
||||||
zombie = 1;
|
zombie = 1;
|
||||||
|
vsnprintf(message, sizeof(message), err, cp);
|
||||||
write_crash_report(message);
|
write_crash_report(message);
|
||||||
end_packfile();
|
end_packfile();
|
||||||
unkeep_all_packs();
|
unkeep_all_packs();
|
||||||
|
|
14
builtin/gc.c
14
builtin/gc.c
|
@ -470,7 +470,8 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
|
||||||
/*
|
/*
|
||||||
* Returns 0 if there was no previous error and gc can proceed, 1 if
|
* Returns 0 if there was no previous error and gc can proceed, 1 if
|
||||||
* gc should not proceed due to an error in the last run. Prints a
|
* gc should not proceed due to an error in the last run. Prints a
|
||||||
* message and returns -1 if an error occurred while reading gc.log
|
* message and returns with a non-[01] status code if an error occurred
|
||||||
|
* while reading gc.log
|
||||||
*/
|
*/
|
||||||
static int report_last_gc_error(void)
|
static int report_last_gc_error(void)
|
||||||
{
|
{
|
||||||
|
@ -484,7 +485,7 @@ static int report_last_gc_error(void)
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
ret = error_errno(_("cannot stat '%s'"), gc_log_path);
|
ret = die_message_errno(_("cannot stat '%s'"), gc_log_path);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,7 +494,7 @@ static int report_last_gc_error(void)
|
||||||
|
|
||||||
len = strbuf_read_file(&sb, gc_log_path, 0);
|
len = strbuf_read_file(&sb, gc_log_path, 0);
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
ret = error_errno(_("cannot read '%s'"), gc_log_path);
|
ret = die_message_errno(_("cannot read '%s'"), gc_log_path);
|
||||||
else if (len > 0) {
|
else if (len > 0) {
|
||||||
/*
|
/*
|
||||||
* A previous gc failed. Report the error, and don't
|
* A previous gc failed. Report the error, and don't
|
||||||
|
@ -611,12 +612,13 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
|
||||||
}
|
}
|
||||||
if (detach_auto) {
|
if (detach_auto) {
|
||||||
int ret = report_last_gc_error();
|
int ret = report_last_gc_error();
|
||||||
if (ret < 0)
|
|
||||||
/* an I/O error occurred, already reported */
|
|
||||||
exit(128);
|
|
||||||
if (ret == 1)
|
if (ret == 1)
|
||||||
/* Last gc --auto failed. Skip this one. */
|
/* Last gc --auto failed. Skip this one. */
|
||||||
return 0;
|
return 0;
|
||||||
|
else if (ret)
|
||||||
|
/* an I/O error occurred, already reported */
|
||||||
|
return ret;
|
||||||
|
|
||||||
if (lock_repo_for_gc(force, &pid))
|
if (lock_repo_for_gc(force, &pid))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -200,11 +200,12 @@ static void prepare_note_data(const struct object_id *object, struct note_data *
|
||||||
static void write_note_data(struct note_data *d, struct object_id *oid)
|
static void write_note_data(struct note_data *d, struct object_id *oid)
|
||||||
{
|
{
|
||||||
if (write_object_file(d->buf.buf, d->buf.len, blob_type, oid)) {
|
if (write_object_file(d->buf.buf, d->buf.len, blob_type, oid)) {
|
||||||
error(_("unable to write note object"));
|
int status = die_message(_("unable to write note object"));
|
||||||
|
|
||||||
if (d->edit_path)
|
if (d->edit_path)
|
||||||
error(_("the note contents have been left in %s"),
|
die_message(_("the note contents have been left in %s"),
|
||||||
d->edit_path);
|
d->edit_path);
|
||||||
exit(128);
|
exit(status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
config.c
3
config.c
|
@ -2555,11 +2555,12 @@ void git_die_config(const char *key, const char *err, ...)
|
||||||
{
|
{
|
||||||
const struct string_list *values;
|
const struct string_list *values;
|
||||||
struct key_value_info *kv_info;
|
struct key_value_info *kv_info;
|
||||||
|
report_fn error_fn = get_error_routine();
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
va_list params;
|
va_list params;
|
||||||
va_start(params, err);
|
va_start(params, err);
|
||||||
vreportf("error: ", err, params);
|
error_fn(err, params);
|
||||||
va_end(params);
|
va_end(params);
|
||||||
}
|
}
|
||||||
values = git_config_get_value_multi(key);
|
values = git_config_get_value_multi(key);
|
||||||
|
|
|
@ -498,11 +498,12 @@ static inline int git_has_dir_sep(const char *path)
|
||||||
struct strbuf;
|
struct strbuf;
|
||||||
|
|
||||||
/* General helper functions */
|
/* General helper functions */
|
||||||
void vreportf(const char *prefix, const char *err, va_list params);
|
|
||||||
NORETURN void usage(const char *err);
|
NORETURN void usage(const char *err);
|
||||||
NORETURN void usagef(const char *err, ...) __attribute__((format (printf, 1, 2)));
|
NORETURN void usagef(const char *err, ...) __attribute__((format (printf, 1, 2)));
|
||||||
NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2)));
|
NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2)));
|
||||||
NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
|
NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
|
||||||
|
int die_message(const char *err, ...) __attribute__((format (printf, 1, 2)));
|
||||||
|
int die_message_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
|
||||||
int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
|
int error(const char *err, ...) __attribute__((format (printf, 1, 2)));
|
||||||
int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
|
int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
|
||||||
void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
|
void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
|
||||||
|
@ -537,6 +538,7 @@ static inline int const_error(void)
|
||||||
typedef void (*report_fn)(const char *, va_list params);
|
typedef void (*report_fn)(const char *, va_list params);
|
||||||
|
|
||||||
void set_die_routine(NORETURN_PTR report_fn routine);
|
void set_die_routine(NORETURN_PTR report_fn routine);
|
||||||
|
report_fn get_die_message_routine(void);
|
||||||
void set_error_routine(report_fn routine);
|
void set_error_routine(report_fn routine);
|
||||||
report_fn get_error_routine(void);
|
report_fn get_error_routine(void);
|
||||||
void set_warn_routine(report_fn routine);
|
void set_warn_routine(report_fn routine);
|
||||||
|
|
|
@ -659,8 +659,9 @@ static NORETURN void die_webcgi(const char *err, va_list params)
|
||||||
{
|
{
|
||||||
if (dead <= 1) {
|
if (dead <= 1) {
|
||||||
struct strbuf hdr = STRBUF_INIT;
|
struct strbuf hdr = STRBUF_INIT;
|
||||||
|
report_fn die_message_fn = get_die_message_routine();
|
||||||
|
|
||||||
vreportf("fatal: ", err, params);
|
die_message_fn(err, params);
|
||||||
|
|
||||||
http_status(&hdr, 500, "Internal Server Error");
|
http_status(&hdr, 500, "Internal Server Error");
|
||||||
hdr_nocache(&hdr);
|
hdr_nocache(&hdr);
|
||||||
|
|
|
@ -1076,6 +1076,6 @@ void NORETURN usage_msg_opt(const char *msg,
|
||||||
const char * const *usagestr,
|
const char * const *usagestr,
|
||||||
const struct option *options)
|
const struct option *options)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "fatal: %s\n\n", msg);
|
die_message("%s\n", msg); /* The extra \n is intentional */
|
||||||
usage_with_options(usagestr, options);
|
usage_with_options(usagestr, options);
|
||||||
}
|
}
|
||||||
|
|
|
@ -340,15 +340,6 @@ static void child_close_pair(int fd[2])
|
||||||
child_close(fd[1]);
|
child_close(fd[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* parent will make it look like the child spewed a fatal error and died
|
|
||||||
* this is needed to prevent changes to t0061.
|
|
||||||
*/
|
|
||||||
static void fake_fatal(const char *err, va_list params)
|
|
||||||
{
|
|
||||||
vreportf("fatal: ", err, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void child_error_fn(const char *err, va_list params)
|
static void child_error_fn(const char *err, va_list params)
|
||||||
{
|
{
|
||||||
const char msg[] = "error() should not be called in child\n";
|
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)
|
||||||
static void child_err_spew(struct child_process *cmd, struct child_err *cerr)
|
static void child_err_spew(struct child_process *cmd, struct child_err *cerr)
|
||||||
{
|
{
|
||||||
static void (*old_errfn)(const char *err, va_list params);
|
static void (*old_errfn)(const char *err, va_list params);
|
||||||
|
report_fn die_message_routine = get_die_message_routine();
|
||||||
|
|
||||||
old_errfn = get_error_routine();
|
old_errfn = get_error_routine();
|
||||||
set_error_routine(fake_fatal);
|
set_error_routine(die_message_routine);
|
||||||
errno = cerr->syserr;
|
errno = cerr->syserr;
|
||||||
|
|
||||||
switch (cerr->err) {
|
switch (cerr->err) {
|
||||||
|
@ -1072,7 +1064,9 @@ static void *run_thread(void *data)
|
||||||
|
|
||||||
static NORETURN void die_async(const char *err, va_list params)
|
static NORETURN void die_async(const char *err, va_list params)
|
||||||
{
|
{
|
||||||
vreportf("fatal: ", err, params);
|
report_fn die_message_fn = get_die_message_routine();
|
||||||
|
|
||||||
|
die_message_fn(err, params);
|
||||||
|
|
||||||
if (in_async()) {
|
if (in_async()) {
|
||||||
struct async *async = pthread_getspecific(async_key);
|
struct async *async = pthread_getspecific(async_key);
|
||||||
|
|
42
usage.c
42
usage.c
|
@ -6,7 +6,7 @@
|
||||||
#include "git-compat-util.h"
|
#include "git-compat-util.h"
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
|
|
||||||
void vreportf(const char *prefix, const char *err, va_list params)
|
static void vreportf(const char *prefix, const char *err, va_list params)
|
||||||
{
|
{
|
||||||
char msg[4096];
|
char msg[4096];
|
||||||
char *p, *pend = msg + sizeof(msg);
|
char *p, *pend = msg + sizeof(msg);
|
||||||
|
@ -55,6 +55,12 @@ static NORETURN void usage_builtin(const char *err, va_list params)
|
||||||
exit(129);
|
exit(129);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void die_message_builtin(const char *err, va_list params)
|
||||||
|
{
|
||||||
|
trace2_cmd_error_va(err, params);
|
||||||
|
vreportf("fatal: ", err, params);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We call trace2_cmd_error_va() in the below functions first and
|
* We call trace2_cmd_error_va() in the below functions first and
|
||||||
* expect it to va_copy 'params' before using it (because an 'ap' can
|
* expect it to va_copy 'params' before using it (because an 'ap' can
|
||||||
|
@ -62,10 +68,9 @@ static NORETURN void usage_builtin(const char *err, va_list params)
|
||||||
*/
|
*/
|
||||||
static NORETURN void die_builtin(const char *err, va_list params)
|
static NORETURN void die_builtin(const char *err, va_list params)
|
||||||
{
|
{
|
||||||
trace2_cmd_error_va(err, params);
|
report_fn die_message_fn = get_die_message_routine();
|
||||||
|
|
||||||
vreportf("fatal: ", err, params);
|
|
||||||
|
|
||||||
|
die_message_fn(err, params);
|
||||||
exit(128);
|
exit(128);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,6 +114,7 @@ static int die_is_recursing_builtin(void)
|
||||||
* (ugh), so keep things static. */
|
* (ugh), so keep things static. */
|
||||||
static NORETURN_PTR report_fn usage_routine = usage_builtin;
|
static NORETURN_PTR report_fn usage_routine = usage_builtin;
|
||||||
static NORETURN_PTR report_fn die_routine = die_builtin;
|
static NORETURN_PTR report_fn die_routine = die_builtin;
|
||||||
|
static report_fn die_message_routine = die_message_builtin;
|
||||||
static report_fn error_routine = error_builtin;
|
static report_fn error_routine = error_builtin;
|
||||||
static report_fn warn_routine = warn_builtin;
|
static report_fn warn_routine = warn_builtin;
|
||||||
static int (*die_is_recursing)(void) = die_is_recursing_builtin;
|
static int (*die_is_recursing)(void) = die_is_recursing_builtin;
|
||||||
|
@ -118,6 +124,11 @@ void set_die_routine(NORETURN_PTR report_fn routine)
|
||||||
die_routine = routine;
|
die_routine = routine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
report_fn get_die_message_routine(void)
|
||||||
|
{
|
||||||
|
return die_message_routine;
|
||||||
|
}
|
||||||
|
|
||||||
void set_error_routine(report_fn routine)
|
void set_error_routine(report_fn routine)
|
||||||
{
|
{
|
||||||
error_routine = routine;
|
error_routine = routine;
|
||||||
|
@ -211,6 +222,29 @@ void NORETURN die_errno(const char *fmt, ...)
|
||||||
va_end(params);
|
va_end(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef die_message
|
||||||
|
int die_message(const char *err, ...)
|
||||||
|
{
|
||||||
|
va_list params;
|
||||||
|
|
||||||
|
va_start(params, err);
|
||||||
|
die_message_routine(err, params);
|
||||||
|
va_end(params);
|
||||||
|
return 128;
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef die_message_errno
|
||||||
|
int die_message_errno(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
char buf[1024];
|
||||||
|
va_list params;
|
||||||
|
|
||||||
|
va_start(params, fmt);
|
||||||
|
die_message_routine(fmt_with_err(buf, sizeof(buf), fmt), params);
|
||||||
|
va_end(params);
|
||||||
|
return 128;
|
||||||
|
}
|
||||||
|
|
||||||
#undef error_errno
|
#undef error_errno
|
||||||
int error_errno(const char *fmt, ...)
|
int error_errno(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue