Skip to content

Abort more noisily #13

Merged
merged 1 commit into from
Aug 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions cmirror.c
Original file line number Diff line number Diff line change
@@ -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);
}
}