diff --git a/cmirror.c b/cmirror.c index 15b6d06..1e1f5d5 100644 --- a/cmirror.c +++ b/cmirror.c @@ -34,6 +34,7 @@ #define STEAL_POINTER(SRC) ({ void *tmp=*(SRC); *(SRC)=NULL; tmp; }) static const char *log_prefix; +static int noisy_abort; static void warn(const char *restrict fmt, ...) { if (log_prefix) @@ -45,12 +46,16 @@ static void warn(const char *restrict fmt, ...) { } static G_NORETURN void die(const char *restrict fmt, ...) { - if (log_prefix) - fprintf(stderr, "%s: ", log_prefix); - va_list ap; - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); + if (fmt) { + if (log_prefix) + fprintf(stderr, "%s: ", log_prefix); + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + } + if (noisy_abort) + fputs("cmirror aborted\n", stderr); _exit(1); } @@ -355,7 +360,7 @@ static void execvp_checked(char **argv) { int wstatus; waitpid(pid, &wstatus, 0); if (wstatus) - _exit(1); + die(NULL); } static void fileop_rmdir_recurse(char *path) { @@ -674,7 +679,7 @@ static void slave(char *slave_path) { if (error) die("mkdir: %s\n", error->message); if (wait_status) - _exit(1); + die(NULL); } int res = chdir(slave_path); if (res == -1) @@ -1084,6 +1089,9 @@ static void master(char *master_path, char *target) { g_autofree char *slave_path; g_autofree char *slave_user; + if (!quiet) + noisy_abort = 1; + EXCEPTS = g_ptr_array_new(); g_ptr_array_add (EXCEPTS, "./quota.group"); g_ptr_array_add (EXCEPTS, "./quota.user"); @@ -1435,7 +1443,7 @@ static void master(char *master_path, char *target) { if (!res) die("%m"); if (wstatus) { - _exit(1); + die(NULL); } }