Skip to content

Commit

Permalink
Merge pull request #13 from mariux64/even-more-noise
Browse files Browse the repository at this point in the history
Abort more noisily
  • Loading branch information
donald authored Aug 17, 2022
2 parents 917e92a + 96ff047 commit 1c765e9
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions cmirror.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -1435,7 +1443,7 @@ static void master(char *master_path, char *target) {
if (!res)
die("%m");
if (wstatus) {
_exit(1);
die(NULL);
}
}

Expand Down

0 comments on commit 1c765e9

Please sign in to comment.