From de0c437bd254f204ab9408ead6c68f6b67cc9de2 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Mon, 20 Apr 2015 22:07:42 +0200 Subject: [PATCH] Put a clear separation between log and msg functions --- cmdline/check.c | 290 ++++++++++---------- cmdline/device.c | 20 +- cmdline/dry.c | 28 +- cmdline/dup.c | 12 +- cmdline/elem.c | 12 +- cmdline/elem.h | 4 +- cmdline/handle.c | 20 +- cmdline/import.c | 30 +- cmdline/list.c | 14 +- cmdline/mingw.c | 78 +++--- cmdline/mktest.c | 64 ++--- cmdline/nano.c | 14 +- cmdline/parity.c | 43 ++- cmdline/pool.c | 30 +- cmdline/rehash.c | 8 +- cmdline/scan.c | 152 +++++----- cmdline/scrub.c | 108 ++++---- cmdline/search.c | 18 +- cmdline/selftest.c | 36 +-- cmdline/snapraid.c | 80 +++--- cmdline/state.c | 670 ++++++++++++++++++++++----------------------- cmdline/status.c | 76 ++--- cmdline/support.c | 56 ++-- cmdline/support.h | 46 +++- cmdline/sync.c | 310 ++++++++++----------- cmdline/unix.c | 64 ++--- cmdline/util.c | 6 +- 27 files changed, 1158 insertions(+), 1131 deletions(-) diff --git a/cmdline/check.c b/cmdline/check.c index 94ba37e1..1d5d46e7 100644 --- a/cmdline/check.c +++ b/cmdline/check.c @@ -112,7 +112,7 @@ static int is_hash_matching(struct snapraid_state* state, int rehash, unsigned d ) { /* if a hash doesn't match, fail the check */ if (blockcmp(state, rehash, failed[failed_map[j]].block, buffer[failed[failed_map[j]].index], buffer_zero) != 0) { - msg_tag("hash_error: Hash mismatch on entry %u\n", failed_map[j]); + log_tag("hash_error: Hash mismatch on entry %u\n", failed_map[j]); return 0; } @@ -223,13 +223,13 @@ static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, u return 0; /* log */ - msg_tag("parity_error:%u:", pos); + log_tag("parity_error:%u:", pos); for (i = 0; i < r; ++i) { if (i != 0) - msg_tag("/"); - msg_tag("%s", lev_config_name(ip[i])); + log_tag("/"); + log_tag("%s", lev_config_name(ip[i])); } - msg_tag(":parity: Parity mismatch\n"); + log_tag(":parity: Parity mismatch\n"); ++error; } while (combination_next(r, n, ip)); } @@ -263,13 +263,13 @@ static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, u return 0; /* log */ - msg_tag("parity_error:%u:", pos); + log_tag("parity_error:%u:", pos); for (i = 0; i < r; ++i) { if (i != 0) - msg_tag("/"); - msg_tag("%s", lev_config_name(ip[i])); + log_tag("/"); + log_tag("%s", lev_config_name(ip[i])); } - msg_tag(":hash: Hash mismatch\n"); + log_tag(":hash: Hash mismatch\n"); ++error; } while (combination_next(r, n, ip)); } @@ -278,7 +278,7 @@ static int repair_step(struct snapraid_state* state, int rehash, unsigned pos, u if (error) return error; - msg_tag("strategy_error:%u: No strategy to recover from %u failures with %u parity %s hash\n", + log_tag("strategy_error:%u: No strategy to recover from %u failures with %u parity %s hash\n", pos, failed_count, n, has_hash ? "with" : "without"); return -1; } @@ -338,9 +338,9 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign disk = handle->disk->name; sub = block_file_get(block)->sub; - msg_tag("entry:%u:%s:%s:%s:%s:%s:%u:\n", j, state, hash, data, disk, esc(sub), block_file_pos(block)); + log_tag("entry:%u:%s:%s:%s:%s:%s:%u:\n", j, state, hash, data, disk, esc(sub), block_file_pos(block)); } else { - msg_tag("entry:%u:%s:%s:%s:\n", j, state, hash, data); + log_tag("entry:%u:%s:%s:%s:\n", j, state, hash, data); } } @@ -375,7 +375,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign || state_search_fetch(state, rehash, failed[j].block, buffer[failed[j].index]) == 0) ) { /* we already have corrected it! */ - msg_tag("hash_import: Fixed entry %u\n", j); + log_tag("hash_import: Fixed entry %u\n", j); } else { /* otherwise try to recover it */ failed_map[n] = j; @@ -389,7 +389,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign /* if nothing to fix */ if (!something_to_recover) { - msg_tag("recover_sync:%u:%u: Skipped for already recovered\n", pos, n); + log_tag("recover_sync:%u:%u: Skipped for already recovered\n", pos, n); /* recompute only the parity */ raid_gen(diskmax, state->level, state->block_size, buffer); @@ -423,7 +423,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign /* it may contain garbage */ failed[j].is_outofdate = 1; - msg_tag("hash_unknown: Unknown hash on entry %u\n", j); + log_tag("hash_unknown: Unknown hash on entry %u\n", j); } else if (hash_is_zero(failed[j].block->hash)) { /* if the block is not filled with 0, we are sure to have */ /* restored it to the state after the 'sync' */ @@ -434,7 +434,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign /* it may contain garbage */ failed[j].is_outofdate = 1; - msg_tag("hash_unknown: Maybe old zero on entry %u\n", j); + log_tag("hash_unknown: Maybe old zero on entry %u\n", j); } } else { /* if the hash is different than the previous one, we are sure to have */ @@ -446,7 +446,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign /* it may contain garbage */ failed[j].is_outofdate = 1; - msg_tag("hash_unknown: Maybe old data on entry %u\n", j); + log_tag("hash_unknown: Maybe old data on entry %u\n", j); } } } @@ -458,9 +458,9 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign error += ret; if (ret < 0) - msg_tag("recover_sync:%u:%u: Failed with no attempts\n", pos, n); + log_tag("recover_sync:%u:%u: Failed with no attempts\n", pos, n); else - msg_tag("recover_sync:%u:%u: Failed with %d attempts\n", pos, n, ret); + log_tag("recover_sync:%u:%u: Failed with %d attempts\n", pos, n, ret); /* Now assume that the parity IS NOT updated at the current state, */ /* but still represent the state before the last 'sync' process. */ @@ -556,7 +556,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign /* and we don't want to write it to the disk */ failed[j].is_outofdate = 1; - msg_tag("hash_unknown: Surely old data on entry %u\n", j); + log_tag("hash_unknown: Surely old data on entry %u\n", j); } } } @@ -567,11 +567,11 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign error += ret; if (ret < 0) - msg_tag("recover_unsync:%u:%u: Failed with no attempts\n", pos, n); + log_tag("recover_unsync:%u:%u: Failed with no attempts\n", pos, n); else - msg_tag("recover_unsync:%u:%u: Failed with %d attempts\n", pos, n, ret); + log_tag("recover_unsync:%u:%u: Failed with %d attempts\n", pos, n, ret); } else { - msg_tag("recover_unsync:%u:%u: Skipped for%s%s\n", pos, n, + log_tag("recover_unsync:%u:%u: Skipped for%s%s\n", pos, n, !something_to_recover ? " nothing to recover" : "", !something_unsynced ? " nothing unsynched" : "" ); @@ -636,7 +636,7 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s /* or at least pointing to NULL, in case it cannot be opened. */ if (handle[j].file != 0 && handle[j].file != file) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in opened file for block %u\n", block->parity_pos); + log_fatal("Internal inconsistency in opened file for block %u\n", block->parity_pos); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -658,8 +658,8 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s ret = handle_close(&handle[j]); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error closing '%s'. %s.\n", path, strerror(errno)); - msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + log_fatal("Error closing '%s'. %s.\n", path, strerror(errno)); + log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); return -1; /* LCOV_EXCL_STOP */ } @@ -667,13 +667,13 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s ret = rename(path, path_to); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error renaming '%s' to '%s'. %s.\n", path, path_to, strerror(errno)); - msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + log_fatal("Error renaming '%s' to '%s'. %s.\n", path, path_to, strerror(errno)); + log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); return -1; /* LCOV_EXCL_STOP */ } - msg_tag("status:unrecoverable:%s:%s\n", disk->name, esc(file->sub)); + log_tag("status:unrecoverable:%s:%s\n", disk->name, esc(file->sub)); msg_info("unrecoverable %s\n", path); /* and do not set the time if damaged */ @@ -686,7 +686,7 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s goto close_and_continue; } - msg_tag("status:recovered:%s:%s\n", disk->name, esc(file->sub)); + log_tag("status:recovered:%s:%s\n", disk->name, esc(file->sub)); msg_info("recovered %s\n", path); inode = handle[j].st.st_ino; @@ -714,29 +714,29 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s /* LCOV_EXCL_START */ /* mark the file as damaged */ file_flag_set(file, FILE_IS_DAMAGED); - msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); return -1; /* LCOV_EXCL_STOP */ } } else { - msg_tag("collision:%s:%s:%s: Not setting modification time to avoid inode collision\n", disk->name, esc(file->sub), esc(collide_file->sub)); + log_tag("collision:%s:%s:%s: Not setting modification time to avoid inode collision\n", disk->name, esc(file->sub), esc(collide_file->sub)); } } else { /* we are not fixing, but only checking */ /* print just the final status */ if (file_flag_has(file, FILE_IS_DAMAGED)) { if (state->opt.auditonly) { - msg_tag("status:damaged:%s:%s\n", disk->name, esc(file->sub)); + log_tag("status:damaged:%s:%s\n", disk->name, esc(file->sub)); msg_info("damaged %s\n", path); } else { - msg_tag("status:unrecoverable:%s:%s\n", disk->name, esc(file->sub)); + log_tag("status:unrecoverable:%s:%s\n", disk->name, esc(file->sub)); msg_info("unrecoverable %s\n", path); } } else if (file_flag_has(file, FILE_IS_FIXED)) { - msg_tag("status:recoverable:%s:%s\n", disk->name, esc(file->sub)); + log_tag("status:recoverable:%s:%s\n", disk->name, esc(file->sub)); msg_info("recoverable %s\n", path); } else { - msg_tag("status:correct:%s:%s\n", disk->name, esc(file->sub)); + log_tag("status:correct:%s:%s\n", disk->name, esc(file->sub)); /* we don't use msg_verbose() because it also goes into the log */ if (msg_level >= MSG_VERBOSE) msg_info("correct %s\n", path); @@ -752,8 +752,8 @@ close_and_continue: ret = handle_close(&handle[j]); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error closing '%s'. %s.\n", path, strerror(errno)); - msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + log_fatal("Error closing '%s'. %s.\n", path, strerror(errno)); + log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); return -1; /* LCOV_EXCL_STOP */ } @@ -872,7 +872,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* post process the files */ ret = file_post(state, fix, i, handle, diskmax); if (ret == -1) { - msg_error("Stopping at block %u\n", i); + log_fatal("Stopping at block %u\n", i); ++unrecoverable_error; goto bail; } @@ -967,8 +967,8 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = handle_close(&handle[j]); if (ret == -1) { /* LCOV_EXCL_START */ - msg_error("DANGER! Unexpected close error in a data disk, it isn't possible to check.\n"); - msg_error("Stopping at block %u\n", i); + log_fatal("DANGER! Unexpected close error in a data disk, it isn't possible to check.\n"); + log_fatal("Stopping at block %u\n", i); ++unrecoverable_error; goto bail; /* LCOV_EXCL_STOP */ @@ -981,11 +981,11 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret == -1) { /* LCOV_EXCL_START */ if (errno == EACCES) { - msg_error("WARNING! Please give write permission to the file.\n"); + log_fatal("WARNING! Please give write permission to the file.\n"); } else { - msg_error("DANGER! Without a working data disk, it isn't possible to fix errors on it.\n"); + log_fatal("DANGER! Without a working data disk, it isn't possible to fix errors on it.\n"); } - msg_error("Stopping at block %u\n", i); + log_fatal("Stopping at block %u\n", i); ++unrecoverable_error; goto bail; /* LCOV_EXCL_STOP */ @@ -1000,7 +1000,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna } else { /* otherwise, open the file only for reading */ ret = handle_open(&handle[j], file, state->file_mode, - msg_warning, state->opt.expected_missing ? msg_expected : 0); + log_error, state->opt.expected_missing ? log_expected : 0); if (ret == -1) { /* save the failed block for the check/fix */ failed[failed_count].is_bad = 1; @@ -1010,7 +1010,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna failed[failed_count].handle = &handle[j]; ++failed_count; - msg_tag("error:%u:%s:%s: Open error at position %u\n", i, disk->name, esc(file->sub), block_file_pos(block)); + log_tag("error:%u:%s:%s: Open error at position %u\n", i, disk->name, esc(file->sub), block_file_pos(block)); ++error; continue; } @@ -1037,22 +1037,22 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna && !(state->opt.syncedonly && file_flag_has(file, FILE_IS_UNSYNCED)) && handle[j].st.st_size > file->size ) { - msg_warning("File '%s' is larger than expected.\n", handle[j].path); - msg_tag("error:%u:%s:%s: Size error\n", i, disk->name, esc(file->sub)); + log_error("File '%s' is larger than expected.\n", handle[j].path); + log_tag("error:%u:%s:%s: Size error\n", i, disk->name, esc(file->sub)); ++error; if (fix) { ret = handle_truncate(&handle[j], file); if (ret == -1) { /* LCOV_EXCL_START */ - msg_error("DANGER! Unexpected truncate error in a data disk, it isn't possible to fix.\n"); - msg_error("Stopping at block %u\n", i); + log_fatal("DANGER! Unexpected truncate error in a data disk, it isn't possible to fix.\n"); + log_fatal("Stopping at block %u\n", i); ++unrecoverable_error; goto bail; /* LCOV_EXCL_STOP */ } - msg_tag("fixed:%u:%s:%s: Fixed size\n", i, disk->name, esc(file->sub)); + log_tag("fixed:%u:%s:%s: Fixed size\n", i, disk->name, esc(file->sub)); ++recovered_error; } } @@ -1065,7 +1065,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* read from the file */ read_size = handle_read(&handle[j], block, buffer[j], state->block_size, - msg_warning, state->opt.expected_missing ? msg_expected : 0); + log_error, state->opt.expected_missing ? log_expected : 0); if (read_size == -1) { /* save the failed block for the check/fix */ failed[failed_count].is_bad = 1; /* it's bad because we cannot read it */ @@ -1075,7 +1075,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna failed[failed_count].handle = &handle[j]; ++failed_count; - msg_tag("error:%u:%s:%s: Read error at position %u\n", i, disk->name, esc(file->sub), block_file_pos(block)); + log_tag("error:%u:%s:%s: Read error at position %u\n", i, disk->name, esc(file->sub), block_file_pos(block)); ++error; continue; } @@ -1116,7 +1116,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna failed[failed_count].handle = &handle[j]; ++failed_count; - msg_tag("error:%u:%s:%s: Data error at position %u\n", i, disk->name, esc(file->sub), block_file_pos(block)); + log_tag("error:%u:%s:%s: Data error at position %u\n", i, disk->name, esc(file->sub), block_file_pos(block)); ++error; continue; } @@ -1152,11 +1152,11 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* read the parity */ for (l = 0; l < state->level; ++l) { if (parity[l]) { - ret = parity_read(parity[l], i, buffer_recov[l], state->block_size, msg_warning); + ret = parity_read(parity[l], i, buffer_recov[l], state->block_size, log_error); if (ret == -1) { buffer_recov[l] = 0; /* no parity to use */ - msg_tag("parity_error:%u:%s: Read error\n", i, lev_config_name(l)); + log_tag("parity_error:%u:%s: Read error\n", i, lev_config_name(l)); ++error; } } else { @@ -1175,7 +1175,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* print a list of all the errors in files */ for (j = 0; j < failed_count; ++j) { if (failed[j].is_bad) - msg_tag("unrecoverable:%u:%s:%s: Unrecoverable error at position %u\n", i, failed[j].handle->disk->name, esc(block_file_get(failed[j].block)->sub), block_file_pos(failed[j].block)); + log_tag("unrecoverable:%u:%s:%s: Unrecoverable error at position %u\n", i, failed[j].handle->disk->name, esc(block_file_get(failed[j].block)->sub), block_file_pos(failed[j].block)); } /* keep track of damaged files */ @@ -1193,7 +1193,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna for (j = 0; j < failed_count; ++j) { if (failed[j].is_bad && failed[j].is_outofdate) { ++partial_recover_error; - msg_tag("unrecoverable:%u:%s:%s: Unrecoverable unsynced error at position %u\n", i, failed[j].handle->disk->name, esc(block_file_get(failed[j].block)->sub), block_file_pos(failed[j].block)); + log_tag("unrecoverable:%u:%s:%s: Unrecoverable unsynced error at position %u\n", i, failed[j].handle->disk->name, esc(block_file_get(failed[j].block)->sub), block_file_pos(failed[j].block)); } } if (partial_recover_error != 0) { @@ -1210,7 +1210,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (buffer_recov[l] != 0 && memcmp(buffer_recov[l], buffer[diskmax + l], state->block_size) != 0) { buffer_recov[l] = 0; - msg_tag("parity_error:%u:%s: Data error\n", i, lev_config_name(l)); + log_tag("parity_error:%u:%s: Data error\n", i, lev_config_name(l)); ++error; } } @@ -1236,12 +1236,12 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna file_flag_set(block_file_get(failed[j].block), FILE_IS_DAMAGED); if (errno == EACCES) { - msg_error("WARNING! Please give write permission to the file.\n"); + log_fatal("WARNING! Please give write permission to the file.\n"); } else { /* we do not use DANGER because it could be ENOSPC which is not always correctly reported */ - msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); } - msg_error("Stopping at block %u\n", i); + log_fatal("Stopping at block %u\n", i); ++unrecoverable_error; goto bail; /* LCOV_EXCL_STOP */ @@ -1258,7 +1258,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* note that it could be also marked as damaged in other iterations */ file_flag_set(block_file_get(failed[j].block), FILE_IS_FIXED); - msg_tag("fixed:%u:%s:%s: Fixed data error at position %u\n", i, failed[j].handle->disk->name, esc(block_file_get(failed[j].block)->sub), block_file_pos(failed[j].block)); + log_tag("fixed:%u:%s:%s: Fixed data error at position %u\n", i, failed[j].handle->disk->name, esc(block_file_get(failed[j].block)->sub), block_file_pos(failed[j].block)); ++recovered_error; } @@ -1273,14 +1273,14 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret == -1) { /* LCOV_EXCL_START */ /* we do not use DANGER because it could be ENOSPC which is not always correctly reported */ - msg_error("WARNING! Without a working %s disk, it isn't possible to fix errors on it.\n", lev_name(l)); - msg_error("Stopping at block %u\n", i); + log_fatal("WARNING! Without a working %s disk, it isn't possible to fix errors on it.\n", lev_name(l)); + log_fatal("Stopping at block %u\n", i); ++unrecoverable_error; goto bail; /* LCOV_EXCL_STOP */ } - msg_tag("parity_fixed:%u:%s: Fixed data error\n", i, lev_config_name(l)); + log_tag("parity_fixed:%u:%s: Fixed data error\n", i, lev_config_name(l)); ++recovered_error; } } @@ -1308,7 +1308,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* post process the files */ ret = file_post(state, fix, i, handle, diskmax); if (ret == -1) { - msg_error("Stopping at block %u\n", i); + log_fatal("Stopping at block %u\n", i); ++unrecoverable_error; goto bail; } @@ -1360,18 +1360,18 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret == -1) { unsuccesful = 1; - msg_warning("Error stating empty file '%s'. %s.\n", path, strerror(errno)); - msg_tag("error:%s:%s: Empty file stat error\n", disk->name, esc(file->sub)); + log_error("Error stating empty file '%s'. %s.\n", path, strerror(errno)); + log_tag("error:%s:%s: Empty file stat error\n", disk->name, esc(file->sub)); ++error; } else if (!S_ISREG(st.st_mode)) { unsuccesful = 1; - msg_tag("error:%s:%s: Empty file error for not regular file\n", disk->name, esc(file->sub)); + log_tag("error:%s:%s: Empty file error for not regular file\n", disk->name, esc(file->sub)); ++error; } else if (st.st_size != 0) { unsuccesful = 1; - msg_tag("error:%s:%s: Empty file error for size '%" PRIu64 "'\n", disk->name, esc(file->sub), st.st_size); + log_tag("error:%s:%s: Empty file error for size '%" PRIu64 "'\n", disk->name, esc(file->sub), st.st_size); ++error; } @@ -1382,8 +1382,8 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = mkancestor(path); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); - msg_error("Stopping\n"); + log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + log_fatal("Stopping\n"); ++unrecoverable_error; goto bail; /* LCOV_EXCL_STOP */ @@ -1394,14 +1394,14 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna f = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_NOFOLLOW, 0600); if (f == -1) { /* LCOV_EXCL_START */ - msg_error("Error creating empty file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error creating empty file '%s'. %s.\n", path, strerror(errno)); if (errno == EACCES) { - msg_error("WARNING! Please give write permission to the file.\n"); + log_fatal("WARNING! Please give write permission to the file.\n"); } else { /* we do not use DANGER because it could be ENOSPC which is not always correctly reported */ - msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); } - msg_error("Stopping\n"); + log_fatal("Stopping\n"); ++unrecoverable_error; goto bail; /* LCOV_EXCL_STOP */ @@ -1413,9 +1413,9 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* LCOV_EXCL_START */ close(f); - msg_error("Error timing file '%s'. %s.\n", file->sub, strerror(errno)); - msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); - msg_error("Stopping\n"); + log_fatal("Error timing file '%s'. %s.\n", file->sub, strerror(errno)); + log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + log_fatal("Stopping\n"); ++unrecoverable_error; goto bail; /* LCOV_EXCL_STOP */ @@ -1425,17 +1425,17 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = close(f); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); - msg_error("Stopping\n"); + log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + log_fatal("Stopping\n"); ++unrecoverable_error; goto bail; /* LCOV_EXCL_STOP */ } - msg_tag("fixed:%s:%s: Fixed empty file\n", disk->name, esc(file->sub)); + log_tag("fixed:%s:%s: Fixed empty file\n", disk->name, esc(file->sub)); ++recovered_error; - msg_tag("status:recovered:%s:%s\n", disk->name, esc(file->sub)); + log_tag("status:recovered:%s:%s\n", disk->name, esc(file->sub)); msg_info("recovered %s%s\n", disk->dir, file->sub); } } @@ -1468,13 +1468,13 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret == -1) { unsuccesful = 1; - msg_warning("Error stating hardlink '%s'. %s.\n", path, strerror(errno)); - msg_tag("hardlinkerror:%s:%s:%s: Hardlink stat error\n", disk->name, esc(link->sub), esc(link->linkto)); + log_error("Error stating hardlink '%s'. %s.\n", path, strerror(errno)); + log_tag("hardlinkerror:%s:%s:%s: Hardlink stat error\n", disk->name, esc(link->sub), esc(link->linkto)); ++error; } else if (!S_ISREG(st.st_mode)) { unsuccesful = 1; - msg_tag("hardlinkerror:%s:%s:%s: Hardlink error for not regular file\n", disk->name, esc(link->sub), esc(link->linkto)); + log_tag("hardlinkerror:%s:%s:%s: Hardlink error for not regular file\n", disk->name, esc(link->sub), esc(link->linkto)); ++error; } @@ -1498,19 +1498,19 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna } } - msg_warning("Error stating hardlink-to '%s'. %s.\n", pathto, strerror(errno)); - msg_tag("hardlinkerror:%s:%s:%s: Hardlink to stat error\n", disk->name, esc(link->sub), esc(link->linkto)); + log_error("Error stating hardlink-to '%s'. %s.\n", pathto, strerror(errno)); + log_tag("hardlinkerror:%s:%s:%s: Hardlink to stat error\n", disk->name, esc(link->sub), esc(link->linkto)); ++error; } else if (!S_ISREG(stto.st_mode)) { unsuccesful = 1; - msg_tag("hardlinkerror:%s:%s:%s: Hardlink-to error for not regular file\n", disk->name, esc(link->sub), esc(link->linkto)); + log_tag("hardlinkerror:%s:%s:%s: Hardlink-to error for not regular file\n", disk->name, esc(link->sub), esc(link->linkto)); ++error; } else if (!unsuccesful && st.st_ino != stto.st_ino) { unsuccesful = 1; - msg_warning("Mismatch hardlink '%s' and '%s'. Different inode.\n", path, pathto); - msg_tag("hardlinkerror:%s:%s:%s: Hardlink mismatch for different inode\n", disk->name, esc(link->sub), esc(link->linkto)); + log_error("Mismatch hardlink '%s' and '%s'. Different inode.\n", path, pathto); + log_tag("hardlinkerror:%s:%s:%s: Hardlink mismatch for different inode\n", disk->name, esc(link->sub), esc(link->linkto)); ++error; } } else { @@ -1520,14 +1520,14 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret < 0) { unsuccesful = 1; - msg_warning("Error reading symlink '%s'. %s.\n", path, strerror(errno)); - msg_tag("symlinkerror:%s:%s: Symlink read error\n", disk->name, esc(link->sub)); + log_error("Error reading symlink '%s'. %s.\n", path, strerror(errno)); + log_tag("symlinkerror:%s:%s: Symlink read error\n", disk->name, esc(link->sub)); ++error; } else if (ret >= PATH_MAX) { unsuccesful = 1; - msg_warning("Error reading symlink '%s'. Symlink too long.\n", path); - msg_tag("symlinkerror:%s:%s: Symlink read error\n", disk->name, esc(link->sub)); + log_error("Error reading symlink '%s'. Symlink too long.\n", path); + log_tag("symlinkerror:%s:%s: Symlink read error\n", disk->name, esc(link->sub)); ++error; } else { linkto[ret] = 0; @@ -1535,7 +1535,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (strcmp(linkto, link->linkto) != 0) { unsuccesful = 1; - msg_tag("symlinkerror:%s:%s: Symlink data error '%s' instead of '%s'\n", disk->name, esc(link->sub), linkto, link->linkto); + log_tag("symlinkerror:%s:%s: Symlink data error '%s' instead of '%s'\n", disk->name, esc(link->sub), linkto, link->linkto); ++error; } } @@ -1546,8 +1546,8 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = mkancestor(path); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); - msg_error("Stopping\n"); + log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + log_fatal("Stopping\n"); ++unrecoverable_error; goto bail; /* LCOV_EXCL_STOP */ @@ -1557,9 +1557,9 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = remove(path); if (ret != 0 && errno != ENOENT) { /* LCOV_EXCL_START */ - msg_error("Error removing '%s'. %s.\n", path, strerror(errno)); - msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); - msg_error("Stopping\n"); + log_fatal("Error removing '%s'. %s.\n", path, strerror(errno)); + log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + log_fatal("Stopping\n"); ++unrecoverable_error; goto bail; /* LCOV_EXCL_STOP */ @@ -1570,43 +1570,43 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = hardlink(pathto, path); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error writing hardlink '%s' to '%s'. %s.\n", path, pathto, strerror(errno)); + log_fatal("Error writing hardlink '%s' to '%s'. %s.\n", path, pathto, strerror(errno)); if (errno == EACCES) { - msg_error("WARNING! Please give write permission to the hardlink.\n"); + log_fatal("WARNING! Please give write permission to the hardlink.\n"); } else { /* we do not use DANGER because it could be ENOSPC which is not always correctly reported */ - msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); } - msg_error("Stopping\n"); + log_fatal("Stopping\n"); ++unrecoverable_error; goto bail; /* LCOV_EXCL_STOP */ } - msg_tag("hardlinkfixed:%s:%s: Fixed hardlink error\n", disk->name, esc(link->sub)); + log_tag("hardlinkfixed:%s:%s: Fixed hardlink error\n", disk->name, esc(link->sub)); ++recovered_error; } else { ret = symlink(link->linkto, path); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error writing symlink '%s' to '%s'. %s.\n", path, link->linkto, strerror(errno)); + log_fatal("Error writing symlink '%s' to '%s'. %s.\n", path, link->linkto, strerror(errno)); if (errno == EACCES) { - msg_error("WARNING! Please give write permission to the symlink.\n"); + log_fatal("WARNING! Please give write permission to the symlink.\n"); } else { /* we do not use DANGER because it could be ENOSPC which is not always correctly reported */ - msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); } - msg_error("Stopping\n"); + log_fatal("Stopping\n"); ++unrecoverable_error; goto bail; /* LCOV_EXCL_STOP */ } - msg_tag("symlinkfixed:%s:%s: Fixed symlink error\n", disk->name, esc(link->sub)); + log_tag("symlinkfixed:%s:%s: Fixed symlink error\n", disk->name, esc(link->sub)); ++recovered_error; } - msg_tag("status:recovered:%s:%s\n", disk->name, esc(link->sub)); + log_tag("status:recovered:%s:%s\n", disk->name, esc(link->sub)); msg_info("recovered %s%s\n", disk->dir, link->sub); } } @@ -1634,13 +1634,13 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret == -1) { unsuccesful = 1; - msg_warning("Error stating dir '%s'. %s.\n", path, strerror(errno)); - msg_tag("dir_error:%s:%s: Dir stat error\n", disk->name, esc(dir->sub)); + log_error("Error stating dir '%s'. %s.\n", path, strerror(errno)); + log_tag("dir_error:%s:%s: Dir stat error\n", disk->name, esc(dir->sub)); ++error; } else if (!S_ISDIR(st.st_mode)) { unsuccesful = 1; - msg_tag("dir_error:%s:%s: Dir error for not directory\n", disk->name, esc(dir->sub)); + log_tag("dir_error:%s:%s: Dir error for not directory\n", disk->name, esc(dir->sub)); ++error; } @@ -1649,8 +1649,8 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = mkancestor(path); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); - msg_error("Stopping\n"); + log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + log_fatal("Stopping\n"); ++unrecoverable_error; goto bail; /* LCOV_EXCL_STOP */ @@ -1660,23 +1660,23 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error creating dir '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error creating dir '%s'. %s.\n", path, strerror(errno)); if (errno == EACCES) { - msg_error("WARNING! Please give write permission to the dir.\n"); + log_fatal("WARNING! Please give write permission to the dir.\n"); } else { /* we do not use DANGER because it could be ENOSPC which is not always correctly reported */ - msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); } - msg_error("Stopping\n"); + log_fatal("Stopping\n"); ++unrecoverable_error; goto bail; /* LCOV_EXCL_STOP */ } - msg_tag("dir_fixed:%s:%s: Fixed dir error\n", disk->name, esc(dir->sub)); + log_tag("dir_fixed:%s:%s: Fixed dir error\n", disk->name, esc(dir->sub)); ++recovered_error; - msg_tag("status:recovered:%s:%s\n", disk->name, esc(dir->sub)); + log_tag("status:recovered:%s:%s\n", disk->name, esc(dir->sub)); msg_info("recovered %s%s\n", disk->dir, dir->sub); } } @@ -1690,7 +1690,7 @@ bail: ret = handle_close(&handle[j]); if (ret == -1) { /* LCOV_EXCL_START */ - msg_error("DANGER! Unexpected close error in a data disk.\n"); + log_fatal("DANGER! Unexpected close error in a data disk.\n"); ++unrecoverable_error; /* continue, as we are already exiting */ /* LCOV_EXCL_STOP */ @@ -1738,8 +1738,8 @@ bail: ret = remove(path); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error removing '%s'. %s.\n", path, strerror(errno)); - msg_error("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); + log_fatal("Error removing '%s'. %s.\n", path, strerror(errno)); + log_fatal("WARNING! Without a working data disk, it isn't possible to fix errors on it.\n"); ++unrecoverable_error; /* continue, as we are already exiting */ /* LCOV_EXCL_STOP */ @@ -1768,36 +1768,36 @@ bail: } if (error && !fix) - msg_error("WARNING! There are errors!\n"); + log_fatal("WARNING! There are errors!\n"); if (unrecoverable_error) - msg_error("DANGER! There are unrecoverable errors!\n"); + log_fatal("DANGER! There are unrecoverable errors!\n"); - msg_tag("summary:error:%u\n", error); + log_tag("summary:error:%u\n", error); if (fix) - msg_tag("summary:error_recovered:%u\n", recovered_error); + log_tag("summary:error_recovered:%u\n", recovered_error); if (!state->opt.auditonly) - msg_tag("summary:error_unrecoverable:%u\n", unrecoverable_error); + log_tag("summary:error_unrecoverable:%u\n", unrecoverable_error); if (fix) { if (error + recovered_error + unrecoverable_error == 0) - msg_tag("summary:exit:ok\n"); + log_tag("summary:exit:ok\n"); else if (unrecoverable_error == 0) - msg_tag("summary:exit:recovered\n"); + log_tag("summary:exit:recovered\n"); else - msg_tag("summary:exit:unrecoverable\n"); + log_tag("summary:exit:unrecoverable\n"); } else if (!state->opt.auditonly) { if (error + unrecoverable_error == 0) - msg_tag("summary:exit:ok\n"); + log_tag("summary:exit:ok\n"); else if (unrecoverable_error == 0) - msg_tag("summary:exit:recoverable\n"); + log_tag("summary:exit:recoverable\n"); else - msg_tag("summary:exit:unrecoverable\n"); + log_tag("summary:exit:unrecoverable\n"); } else { /* audit only */ if (error == 0) - msg_tag("summary:exit:ok\n"); + log_tag("summary:exit:ok\n"); else - msg_tag("summary:exit:error\n"); + log_tag("summary:exit:error\n"); } - msg_flush(); + log_flush(); free(failed); free(failed_map); @@ -1848,7 +1848,7 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b if (blockstart > blockmax) { /* LCOV_EXCL_START */ - msg_error("Error in the specified starting block %u. It's bigger than the parity size %u.\n", blockstart, blockmax); + log_fatal("Error in the specified starting block %u. It's bigger than the parity size %u.\n", blockstart, blockmax); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1866,7 +1866,7 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b ret = parity_create(parity_ptr[l], state->parity[l].path, &out_size, state->file_mode); if (ret == -1) { /* LCOV_EXCL_START */ - msg_error("WARNING! Without an accessible %s file, it isn't possible to fix any error.\n", lev_name(l)); + log_fatal("WARNING! Without an accessible %s file, it isn't possible to fix any error.\n", lev_name(l)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1874,7 +1874,7 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b ret = parity_chsize(parity_ptr[l], size, &out_size, state->opt.skip_fallocate); if (ret == -1) { /* LCOV_EXCL_START */ - msg_error("WARNING! Without an accessible %s file, it isn't possible to sync.\n", lev_name(l)); + log_fatal("WARNING! Without an accessible %s file, it isn't possible to sync.\n", lev_name(l)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1923,7 +1923,7 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b ret = parity_close(parity_ptr[l]); /* LCOV_EXCL_START */ if (ret == -1) { - msg_error("DANGER! Unexpected close error in %s disk.\n", lev_name(l)); + log_fatal("DANGER! Unexpected close error in %s disk.\n", lev_name(l)); ++error; /* continue, as we are already exiting */ } diff --git a/cmdline/device.c b/cmdline/device.c index 028ba097..970f5850 100644 --- a/cmdline/device.c +++ b/cmdline/device.c @@ -794,22 +794,22 @@ static void state_smart(unsigned n, tommy_list* low) printf("\n"); - msg_tag("smart:%s:%s\n", devinfo->file, devinfo->name); + log_tag("smart:%s:%s\n", devinfo->file, devinfo->name); if (devinfo->smart_serial[0]) - msg_tag("attr:%s:%s:serial:%s\n", devinfo->file, devinfo->name, esc(devinfo->smart_serial)); + log_tag("attr:%s:%s:serial:%s\n", devinfo->file, devinfo->name, esc(devinfo->smart_serial)); if (afr != 0) - msg_tag("attr:%s:%s:afr:%g\n", devinfo->file, devinfo->name, afr); + log_tag("attr:%s:%s:afr:%g\n", devinfo->file, devinfo->name, afr); if (devinfo->smart[SMART_SIZE] != SMART_UNASSIGNED) - msg_tag("attr:%s:%s:size:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_SIZE]); + log_tag("attr:%s:%s:size:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_SIZE]); if (devinfo->smart[SMART_ERROR] != SMART_UNASSIGNED) - msg_tag("attr:%s:%s:error:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_ERROR]); + log_tag("attr:%s:%s:error:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_ERROR]); if (devinfo->smart[SMART_ROTATION_RATE] != SMART_UNASSIGNED) - msg_tag("attr:%s:%s:rotationrate:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_ROTATION_RATE]); + log_tag("attr:%s:%s:rotationrate:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_ROTATION_RATE]); if (devinfo->smart[SMART_FLAGS] != SMART_UNASSIGNED) - msg_tag("attr:%s:%s:flags:%" PRIu64 ":%" PRIx64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_FLAGS], devinfo->smart[SMART_FLAGS]); + log_tag("attr:%s:%s:flags:%" PRIu64 ":%" PRIx64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_FLAGS], devinfo->smart[SMART_FLAGS]); for (j = 0; j < 256; ++j) if (devinfo->smart[j] != SMART_UNASSIGNED) - msg_tag("attr:%s:%s:%u:%" PRIu64 ":%" PRIx64 "\n", devinfo->file, devinfo->name, j, devinfo->smart[j], devinfo->smart[j]); + log_tag("attr:%s:%s:%u:%" PRIu64 ":%" PRIx64 "\n", devinfo->file, devinfo->name, j, devinfo->smart[j], devinfo->smart[j]); } printf("\n"); @@ -826,7 +826,7 @@ static void state_smart(unsigned n, tommy_list* low) p_at_least_one_failure = poisson_prob_n_or_more_failures(array_failure_rate, 1); printf("Probability that at least one disk is going to fail in the next year is %.0f%%.\n", p_at_least_one_failure * 100); - msg_tag("summary:array_failure:%g:%g\n", array_failure_rate, p_at_least_one_failure); + log_tag("summary:array_failure:%g:%g\n", array_failure_rate, p_at_least_one_failure); /* prints extra stats only in verbose mode */ if (msg_level < MSG_VERBOSE) @@ -988,7 +988,7 @@ void state_device(struct snapraid_state* state, int operation) case DEVICE_LIST : ope = "List"; break; case DEVICE_SMART : ope = "SMART"; break; } - msg_error("%s unsupported in this platform.\n", ope); + log_fatal("%s unsupported in this platform.\n", ope); } else { if (operation == DEVICE_LIST) { for (i = tommy_list_head(&low); i != 0; i = i->next) { diff --git a/cmdline/dry.c b/cmdline/dry.c index 96318b43..f894ebac 100644 --- a/cmdline/dry.c +++ b/cmdline/dry.c @@ -82,20 +82,20 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit ret = handle_close(&handle[j]); if (ret == -1) { /* LCOV_EXCL_START */ - msg_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); - msg_error("DANGER! Unexpected close error in a data disk, it isn't possible to dry.\n"); - msg_error("Stopping at block %u\n", i); + log_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); + log_fatal("DANGER! Unexpected close error in a data disk, it isn't possible to dry.\n"); + log_fatal("Stopping at block %u\n", i); ++error; goto bail; /* LCOV_EXCL_STOP */ } /* open the file only for reading */ - ret = handle_open(&handle[j], block_file_get(block), state->file_mode, msg_error, 0); + ret = handle_open(&handle[j], block_file_get(block), state->file_mode, log_fatal, 0); if (ret == -1) { /* LCOV_EXCL_START */ - msg_error("DANGER! Unexpected open error in a data disk, it isn't possible to dry.\n"); - msg_error("Stopping at block %u\n", i); + log_fatal("DANGER! Unexpected open error in a data disk, it isn't possible to dry.\n"); + log_fatal("Stopping at block %u\n", i); ++error; goto bail; /* LCOV_EXCL_STOP */ @@ -103,9 +103,9 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit } /* read from the file */ - read_size = handle_read(&handle[j], block, buffer_aligned, state->block_size, msg_warning, 0); + read_size = handle_read(&handle[j], block, buffer_aligned, state->block_size, log_error, 0); if (read_size == -1) { - msg_tag("error:%u:%s:%s: Read error at position %u\n", i, disk->name, esc(block_file_get(block)->sub), block_file_pos(block)); + log_tag("error:%u:%s:%s: Read error at position %u\n", i, disk->name, esc(block_file_get(block)->sub), block_file_pos(block)); ++error; continue; } @@ -122,9 +122,9 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit /* until now is CPU */ state_usage_cpu(state); - ret = parity_read(parity[l], i, buffer_aligned, state->block_size, msg_warning); + ret = parity_read(parity[l], i, buffer_aligned, state->block_size, log_error); if (ret == -1) { - msg_tag("parity_error:%u:%s: Read error\n", i, lev_config_name(l)); + log_tag("parity_error:%u:%s: Read error\n", i, lev_config_name(l)); ++error; } @@ -156,8 +156,8 @@ bail: ret = handle_close(&handle[j]); if (ret == -1) { /* LCOV_EXCL_START */ - msg_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); - msg_error("DANGER! Unexpected close error in a data disk.\n"); + log_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); + log_fatal("DANGER! Unexpected close error in a data disk.\n"); ++error; /* continue, as we are already exiting */ /* LCOV_EXCL_STOP */ @@ -172,7 +172,7 @@ bail: } if (error) - msg_error("DANGER! Unexpected errors!\n"); + log_fatal("DANGER! Unexpected errors!\n"); free(handle); free(buffer_alloc); @@ -199,7 +199,7 @@ void state_dry(struct snapraid_state* state, block_off_t blockstart, block_off_t if (blockstart > blockmax) { /* LCOV_EXCL_START */ - msg_error("Error in the specified starting block %u. It's bigger than the parity size %u.\n", blockstart, blockmax); + log_fatal("Error in the specified starting block %u. It's bigger than the parity size %u.\n", blockstart, blockmax); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/dup.c b/cmdline/dup.c index a4ff67cd..c7de7497 100644 --- a/cmdline/dup.c +++ b/cmdline/dup.c @@ -125,7 +125,7 @@ void state_dup(struct snapraid_state* state) if (dup) { ++count; size += dup->file->size; - msg_tag("dup:%s:%s:%s:%s:%" PRIu64 ": dup\n", disk->name, esc(file->sub), dup->disk->name, esc(dup->file->sub), dup->file->size); + log_tag("dup:%s:%s:%s:%s:%" PRIu64 ": dup\n", disk->name, esc(file->sub), dup->disk->name, esc(dup->file->sub), dup->file->size); printf("%12" PRIu64 " %s%s = %s%s\n", file->size, disk->dir, file->sub, dup->disk->dir, dup->file->sub); hash_free(hash); } else { @@ -144,13 +144,13 @@ void state_dup(struct snapraid_state* state) else msg_status("No duplicates\n"); - msg_tag("summary:dup_count:%u\n", count); - msg_tag("summary:dup_size:%" PRIu64 "\n", size); + log_tag("summary:dup_count:%u\n", count); + log_tag("summary:dup_size:%" PRIu64 "\n", size); if (count == 0) { - msg_tag("summary:exit:unique\n"); + log_tag("summary:exit:unique\n"); } else { - msg_tag("summary:exit:dup\n"); + log_tag("summary:exit:dup\n"); } - msg_flush(); + log_flush(); } diff --git a/cmdline/elem.c b/cmdline/elem.c index b8c04575..304b1f00 100644 --- a/cmdline/elem.c +++ b/cmdline/elem.c @@ -277,7 +277,7 @@ int filter_existence(int filter_missing, const char* dir, const char* sub) if (errno == ENOENT) return 0; /* LCOV_EXCL_START */ - msg_error("Error in stat file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error in stat file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -342,7 +342,7 @@ block_off_t block_file_pos(struct snapraid_block* block) if (block < file->blockvec || block >= file->blockvec + file->blockmax) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in block %u ownership\n", block->parity_pos); + log_fatal("Internal inconsistency in block %u ownership\n", block->parity_pos); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -456,21 +456,21 @@ void file_copy(struct snapraid_file* src_file, struct snapraid_file* dst_file) if (src_file->size != dst_file->size) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in copy file with different size\n"); + log_fatal("Internal inconsistency in copy file with different size\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (src_file->mtime_sec != dst_file->mtime_sec) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in copy file with different mtime_sec\n"); + log_fatal("Internal inconsistency in copy file with different mtime_sec\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (src_file->mtime_nsec != dst_file->mtime_nsec) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in copy file with different mtime_nsec\n"); + log_fatal("Internal inconsistency in copy file with different mtime_nsec\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -748,7 +748,7 @@ int disk_is_empty(struct snapraid_disk* disk, block_off_t blockmax) return 0; default : /* LCOV_EXCL_START */ - msg_error("Internal inconsistency for used block in disk '%s' without files\n", disk->name); + log_fatal("Internal inconsistency for used block in disk '%s' without files\n", disk->name); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/elem.h b/cmdline/elem.h index 5df2adff..c9a79d5a 100644 --- a/cmdline/elem.h +++ b/cmdline/elem.h @@ -498,7 +498,7 @@ static inline void block_file_set(struct snapraid_block* block, struct snapraid_ /* ensure that the pointer doesn't use the flag space */ if ((ptr & (uintptr_t)BLOCK_STATE_MASK) != 0) { /* LCOV_EXCL_START */ - msg_error("Internal error for pointer not aligned\n"); + log_fatal("Internal error for pointer not aligned\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -525,7 +525,7 @@ static inline void block_state_set(struct snapraid_block* block, unsigned state) /* ensure that the state can be stored inside the file pointer */ if ((state & BLOCK_STATE_MASK) != state) { /* LCOV_EXCL_START */ - msg_error("Internal error when setting the block state %u\n", state); + log_fatal("Internal error when setting the block state %u\n", state); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/handle.c b/cmdline/handle.c index 887f0f99..bfb0506c 100644 --- a/cmdline/handle.c +++ b/cmdline/handle.c @@ -90,7 +90,7 @@ int handle_create(struct snapraid_handle* handle, struct snapraid_file* file, in handle->f = -1; handle->valid_size = 0; - msg_error("Error opening file '%s'. %s.\n", handle->path, strerror(errno)); + log_fatal("Error opening file '%s'. %s.\n", handle->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -102,7 +102,7 @@ int handle_create(struct snapraid_handle* handle, struct snapraid_file* file, in ret = fstat(handle->f, &handle->st); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error accessing file '%s'. %s.\n", handle->path, strerror(errno)); + log_fatal("Error accessing file '%s'. %s.\n", handle->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -116,7 +116,7 @@ int handle_create(struct snapraid_handle* handle, struct snapraid_file* file, in ret = posix_fadvise(handle->f, 0, 0, POSIX_FADV_SEQUENTIAL); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error advising file '%s'. %s.\n", handle->path, strerror(ret)); + log_fatal("Error advising file '%s'. %s.\n", handle->path, strerror(ret)); return -1; /* LCOV_EXCL_STOP */ } @@ -134,9 +134,9 @@ int handle_truncate(struct snapraid_handle* handle, struct snapraid_file* file) if (ret != 0) { /* LCOV_EXCL_START */ if (errno == EACCES) { - msg_error("Failed to truncate file '%s' for missing write permission.\n", handle->path); + log_fatal("Failed to truncate file '%s' for missing write permission.\n", handle->path); } else { - msg_error("Error truncating file '%s'. %s.\n", handle->path, strerror(errno)); + log_fatal("Error truncating file '%s'. %s.\n", handle->path, strerror(errno)); } return -1; /* LCOV_EXCL_STOP */ @@ -229,7 +229,7 @@ int handle_close(struct snapraid_handle* handle) ret = close(handle->f); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error closing file '%s'. %s.\n", handle->file->sub, strerror(errno)); + log_fatal("Error closing file '%s'. %s.\n", handle->file->sub, strerror(errno)); /* invalidate for error */ handle->file = 0; @@ -338,7 +338,7 @@ int handle_write(struct snapraid_handle* handle, struct snapraid_block* block, u #else if (lseek(handle->f, offset, SEEK_SET) != offset) { /* LCOV_EXCL_START */ - msg_error("Error seeking file '%s'. %s.\n", handle->path, strerror(errno)); + log_fatal("Error seeking file '%s'. %s.\n", handle->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -347,7 +347,7 @@ int handle_write(struct snapraid_handle* handle, struct snapraid_block* block, u #endif if (write_ret != (ssize_t)write_size) { /* conversion is safe because block_size is always small */ /* LCOV_EXCL_START */ - msg_error("Error writing file '%s'. %s.\n", handle->path, strerror(errno)); + log_fatal("Error writing file '%s'. %s.\n", handle->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -375,7 +375,7 @@ int handle_utime(struct snapraid_handle* handle) if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error timing file '%s'. %s.\n", handle->file->sub, strerror(errno)); + log_fatal("Error timing file '%s'. %s.\n", handle->file->sub, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -423,7 +423,7 @@ struct snapraid_handle* handle_map(struct snapraid_state* state, unsigned* handl } if (k == 0) { /* LCOV_EXCL_START */ - msg_error("Internal error for inconsistent disk mapping.\n"); + log_fatal("Internal error for inconsistent disk mapping.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/import.c b/cmdline/import.c index c4dfb715..566cba8f 100644 --- a/cmdline/import.c +++ b/cmdline/import.c @@ -78,7 +78,7 @@ static void import_file(struct snapraid_state* state, const char* path, uint64_t f = open(path, flags); if (f == -1) { /* LCOV_EXCL_START */ - msg_error("Error opening file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error opening file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -89,7 +89,7 @@ static void import_file(struct snapraid_state* state, const char* path, uint64_t ret = posix_fadvise(f, 0, 0, POSIX_FADV_SEQUENTIAL); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error advising file '%s'. %s.\n", path, strerror(ret)); + log_fatal("Error advising file '%s'. %s.\n", path, strerror(ret)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -106,7 +106,7 @@ static void import_file(struct snapraid_state* state, const char* path, uint64_t ret = read(f, buffer, read_size); if (ret < 0 || (unsigned)ret != read_size) { /* LCOV_EXCL_START */ - msg_error("Error reading file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error reading file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -132,7 +132,7 @@ static void import_file(struct snapraid_state* state, const char* path, uint64_t ret = close(f); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error closing file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error closing file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -174,14 +174,14 @@ int state_import_fetch(struct snapraid_state* state, int rehash, struct snapraid f = open(path, O_RDONLY | O_BINARY); if (f == -1) { /* LCOV_EXCL_START */ - msg_error("Error opening file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error opening file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (lseek(f, block->offset, SEEK_SET) != block->offset) { /* LCOV_EXCL_START */ - msg_error("Error seeking file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error seeking file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -189,7 +189,7 @@ int state_import_fetch(struct snapraid_state* state, int rehash, struct snapraid ret = read(f, buffer, read_size); if (ret < 0 || (unsigned)ret != read_size) { /* LCOV_EXCL_START */ - msg_error("Error reading file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error reading file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -197,7 +197,7 @@ int state_import_fetch(struct snapraid_state* state, int rehash, struct snapraid ret = close(f); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error closing file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error closing file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -215,8 +215,8 @@ int state_import_fetch(struct snapraid_state* state, int rehash, struct snapraid if (memcmp(buffer_hash, hash, HASH_SIZE) != 0) { /* LCOV_EXCL_START */ - msg_error("Error in data reading file '%s'.\n", path); - msg_error("Please don't change imported files while running.\n"); + log_fatal("Error in data reading file '%s'.\n", path); + log_fatal("Please don't change imported files while running.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -231,7 +231,7 @@ static void import_dir(struct snapraid_state* state, const char* dir) d = opendir(dir); if (!d) { /* LCOV_EXCL_START */ - msg_error("Error opening directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal("Error opening directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -247,7 +247,7 @@ static void import_dir(struct snapraid_state* state, const char* dir) dd = readdir(d); if (dd == 0 && errno != 0) { /* LCOV_EXCL_START */ - msg_error("Error reading directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal("Error reading directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -274,7 +274,7 @@ static void import_dir(struct snapraid_state* state, const char* dir) if (st.st_mode == 0) { if (lstat(path_next, &st) != 0) { /* LCOV_EXCL_START */ - msg_error("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -283,7 +283,7 @@ static void import_dir(struct snapraid_state* state, const char* dir) /* get lstat info about the file */ if (lstat(path_next, &st) != 0) { /* LCOV_EXCL_START */ - msg_error("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -299,7 +299,7 @@ static void import_dir(struct snapraid_state* state, const char* dir) if (closedir(d) != 0) { /* LCOV_EXCL_START */ - msg_error("Error closing directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal("Error closing directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/list.c b/cmdline/list.c index 60ef441e..3d0dbe9a 100644 --- a/cmdline/list.c +++ b/cmdline/list.c @@ -59,7 +59,7 @@ void state_list(struct snapraid_state* state) ++file_count; file_size += file->size; - msg_tag("file:%s:%s:%" PRIu64 ":%" PRIi64 ":%u:%" PRIi64 "\n", disk->name, esc(file->sub), file->size, file->mtime_sec, file->mtime_nsec, file->inode); + log_tag("file:%s:%s:%" PRIu64 ":%" PRIi64 ":%u:%" PRIi64 "\n", disk->name, esc(file->sub), file->size, file->mtime_sec, file->mtime_nsec, file->inode); t = file->mtime_sec; #if HAVE_LOCALTIME_R @@ -98,7 +98,7 @@ void state_list(struct snapraid_state* state) ++link_count; - msg_tag("link_%s:%s:%s:%s\n", type, disk->name, esc(link->sub), esc(link->linkto)); + log_tag("link_%s:%s:%s:%s\n", type, disk->name, esc(link->sub), esc(link->linkto)); printf("%12s ", type); printf(" "); @@ -112,10 +112,10 @@ void state_list(struct snapraid_state* state) msg_status("%8u files, for %" PRIu64 " GB\n", file_count, file_size / GIGA); msg_status("%8u links\n", link_count); - msg_tag("summary:file_count:%u\n", file_count); - msg_tag("summary:file_size:%" PRIu64 "\n", file_size); - msg_tag("summary:link_count:%u\n", link_count); - msg_tag("summary:exit:ok\n"); - msg_flush(); + log_tag("summary:file_count:%u\n", file_count); + log_tag("summary:file_size:%" PRIu64 "\n", file_size); + log_tag("summary:link_count:%u\n", link_count); + log_tag("summary:exit:ok\n"); + log_flush(); } diff --git a/cmdline/mingw.c b/cmdline/mingw.c index 9a7214e1..ee688ba5 100644 --- a/cmdline/mingw.c +++ b/cmdline/mingw.c @@ -185,19 +185,19 @@ void os_init(int opt) ntdll = GetModuleHandle("NTDLL.DLL"); if (!ntdll) { - msg_error("Error loading the NTDLL module.\n"); + log_fatal("Error loading the NTDLL module.\n"); exit(EXIT_FAILURE); } kernel32 = GetModuleHandle("KERNEL32.DLL"); if (!kernel32) { - msg_error("Error loading the KERNEL32 module.\n"); + log_fatal("Error loading the KERNEL32 module.\n"); exit(EXIT_FAILURE); } dll_advapi32 = LoadLibrary("ADVAPI32.DLL"); if (!dll_advapi32) { - msg_error("Error loading the ADVAPI32 module.\n"); + log_fatal("Error loading the ADVAPI32 module.\n"); exit(EXIT_FAILURE); } @@ -210,7 +210,7 @@ void os_init(int opt) ptr_RtlGenRandom = (void*)GetProcAddress(dll_advapi32, "SystemFunction036"); if (!ptr_RtlGenRandom) { - msg_error("Error loading RtlGenRandom() from the ADVAPI32 module.\n"); + log_fatal("Error loading RtlGenRandom() from the ADVAPI32 module.\n"); exit(EXIT_FAILURE); } @@ -275,7 +275,7 @@ static wchar_t* u8tou16(const char* src) ret = MultiByteToWideChar(CP_UTF8, 0, src, -1, conv_utf16_buffer[roll], sizeof(conv_utf16_buffer[0]) / sizeof(wchar_t)); if (ret <= 0) { - msg_error("Error converting name '%s' from UTF-8 to UTF-16\n", src); + log_fatal("Error converting name '%s' from UTF-8 to UTF-16\n", src); exit(EXIT_FAILURE); } @@ -298,7 +298,7 @@ static char* u16tou8ex(const wchar_t* src, size_t number_of_wchar, size_t* resul ret = WideCharToMultiByte(CP_UTF8, 0, src, number_of_wchar, conv_utf8_buffer[roll], sizeof(conv_utf8_buffer[0]), 0, 0); if (ret <= 0) { - msg_error("Error converting from UTF-16 to UTF-8\n"); + log_fatal("Error converting from UTF-16 to UTF-8\n"); exit(EXIT_FAILURE); } @@ -393,7 +393,7 @@ static wchar_t* convert_arg(const char* src, int only_if_required) ret = MultiByteToWideChar(CP_UTF8, 0, src, -1, dst, sizeof(conv_utf16_buffer[0]) / sizeof(wchar_t) - count); if (ret <= 0) { - msg_error("Error converting name '%s' from UTF-8 to UTF-16\n", src); + log_fatal("Error converting name '%s' from UTF-8 to UTF-16\n", src); exit(EXIT_FAILURE); } @@ -627,7 +627,7 @@ static void windows_finddata2dirent(const WIN32_FIND_DATAW* info, struct windows name = u16tou8ex(info->cFileName, wcslen(info->cFileName), &len); if (len + 1 >= sizeof(dirent->d_name)) { - msg_error("Name too long\n"); + log_fatal("Name too long\n"); exit(EXIT_FAILURE); } @@ -645,7 +645,7 @@ static void windows_stream2dirent(const BY_HANDLE_FILE_INFORMATION* info, const name = u16tou8ex(stream->FileName, stream->FileNameLength / 2, &len); if (len + 1 >= sizeof(dirent->d_name)) { - msg_error("Name too long\n"); + log_fatal("Name too long\n"); exit(EXIT_FAILURE); } @@ -696,7 +696,7 @@ static void windows_errno(DWORD error) errno = EPERM; break; default : - msg_error("Unexpected Windows error %d.\n", (int)error); + log_fatal("Unexpected Windows error %d.\n", (int)error); errno = EIO; break; } @@ -1000,8 +1000,8 @@ int windows_fsync(int fd) * this error, but not enough sure to ignore it. * So, we use now an extended error reporting. */ - msg_error("Unexpected Windows INVALID_HANDLE error in FlushFileBuffers().\n"); - msg_error("Are you using ATA-over-Ethernet ? Please report it.\n"); + log_fatal("Unexpected Windows INVALID_HANDLE error in FlushFileBuffers().\n"); + log_fatal("Are you using ATA-over-Ethernet ? Please report it.\n"); /* normal error processing */ windows_errno(error); @@ -1132,7 +1132,7 @@ static windows_dir* windows_opendir_find(const char* dir) dirstream = malloc(sizeof(windows_dir)); if (!dirstream) { - msg_error("Low memory\n"); + log_fatal("Low memory\n"); exit(EXIT_FAILURE); } @@ -1269,7 +1269,7 @@ static windows_dir* windows_opendir_stream(const char* dir) dirstream = malloc(sizeof(windows_dir)); if (!dirstream) { - msg_error("Low memory\n"); + log_fatal("Low memory\n"); exit(EXIT_FAILURE); } @@ -1279,7 +1279,7 @@ static windows_dir* windows_opendir_stream(const char* dir) dirstream->buffer_size = 64 * 1024; dirstream->buffer = malloc(dirstream->buffer_size); if (!dirstream->buffer) { - msg_error("Low memory\n"); + log_fatal("Low memory\n"); exit(EXIT_FAILURE); } @@ -1756,7 +1756,7 @@ retry: * https://sourceforge.net/p/snapraid/discussion/1677233/thread/a7c25ba9/ */ if (err == ERROR_NO_SYSTEM_RESOURCES) { - msg_error("Unexpected Windows ERROR_NO_SYSTEM_RESOURCES in pread(), retrying...\n"); + log_fatal("Unexpected Windows ERROR_NO_SYSTEM_RESOURCES in pread(), retrying...\n"); Sleep(50); goto retry; } @@ -1796,7 +1796,7 @@ retry: DWORD err = GetLastError(); /* See windows_pread() for comments on this error management */ if (err == ERROR_NO_SYSTEM_RESOURCES) { - msg_error("Unexpected Windows ERROR_NO_SYSTEM_RESOURCES in pwrite(), retrying...\n"); + log_fatal("Unexpected Windows ERROR_NO_SYSTEM_RESOURCES in pwrite(), retrying...\n"); Sleep(50); goto retry; } @@ -1971,7 +1971,7 @@ static int smartctl_scan(FILE* f, tommy_list* list) /* remove extraneous chars */ s = polish(buf); - msg_tag("smartctl:scan::text: %s\n", s); + log_tag("smartctl:scan::text: %s\n", s); if (*s == '/') { char* sep = strchr(s, ' '); @@ -2029,12 +2029,12 @@ static int devscan(tommy_list* list) snwprintf(cmd, sizeof(cmd), L"\"%lssmartctl.exe\" --scan-open -d pd", exedir); - msg_tag("smartctl:scan::run: %s\n", u16tou8(cmd)); + log_tag("smartctl:scan::run: %s\n", u16tou8(cmd)); f = _wpopen(cmd, L"rt"); if (!f) { /* LCOV_EXCL_START */ - msg_error("Failed to run '%s' (from popen).\n", u16tou8(cmd)); + log_fatal("Failed to run '%s' (from popen).\n", u16tou8(cmd)); return -1; /* LCOV_EXCL_STOP */ } @@ -2048,17 +2048,17 @@ static int devscan(tommy_list* list) ret = pclose(f); - msg_tag("smartctl:scan::ret: %x\n", ret); + log_tag("smartctl:scan::ret: %x\n", ret); if (ret == -1) { /* LCOV_EXCL_START */ - msg_error("Failed to run '%s' (from pclose).\n", u16tou8(cmd)); + log_fatal("Failed to run '%s' (from pclose).\n", u16tou8(cmd)); return -1; /* LCOV_EXCL_STOP */ } if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Failed to run '%s' with return code %xh.\n", u16tou8(cmd), ret); + log_fatal("Failed to run '%s' with return code %xh.\n", u16tou8(cmd), ret); return -1; /* LCOV_EXCL_STOP */ } @@ -2091,12 +2091,12 @@ static int devsmart(uint64_t device, const char* name, const char* custom, uint6 count = 0; retry: - msg_tag("smartctl:%s:%s:run: %s\n", file, name, u16tou8(cmd)); + log_tag("smartctl:%s:%s:run: %s\n", file, name, u16tou8(cmd)); f = _wpopen(cmd, L"rt"); if (!f) { /* LCOV_EXCL_START */ - msg_error("Failed to run '%s' (from popen).\n", u16tou8(cmd)); + log_fatal("Failed to run '%s' (from popen).\n", u16tou8(cmd)); return -1; /* LCOV_EXCL_STOP */ } @@ -2110,11 +2110,11 @@ retry: ret = pclose(f); - msg_tag("smartctl:%s:%s:ret: %x\n", file, name, ret); + log_tag("smartctl:%s:%s:ret: %x\n", file, name, ret); if (ret == -1) { /* LCOV_EXCL_START */ - msg_error("Failed to run '%s' (from pclose).\n", u16tou8(cmd)); + log_fatal("Failed to run '%s' (from pclose).\n", u16tou8(cmd)); return -1; /* LCOV_EXCL_STOP */ } @@ -2176,12 +2176,12 @@ static int devdown(uint64_t device, const char* name, const char* custom) count = 0; retry: - msg_tag("smartctl:%s:%s:run: %s\n", file, name, u16tou8(cmd)); + log_tag("smartctl:%s:%s:run: %s\n", file, name, u16tou8(cmd)); f = _wpopen(cmd, L"rt"); if (!f) { /* LCOV_EXCL_START */ - msg_error("Failed to run '%s' (from popen).\n", u16tou8(cmd)); + log_fatal("Failed to run '%s' (from popen).\n", u16tou8(cmd)); return -1; /* LCOV_EXCL_STOP */ } @@ -2195,11 +2195,11 @@ retry: ret = pclose(f); - msg_tag("smartctl:%s:%s:ret: %x\n", file, name, ret); + log_tag("smartctl:%s:%s:ret: %x\n", file, name, ret); if (ret == -1) { /* LCOV_EXCL_START */ - msg_error("Failed to run '%s' (from pclose).\n", u16tou8(cmd)); + log_fatal("Failed to run '%s' (from pclose).\n", u16tou8(cmd)); return -1; /* LCOV_EXCL_STOP */ } @@ -2225,7 +2225,7 @@ retry: if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Failed to run '%s' with return code %xh.\n", u16tou8(cmd), ret); + log_fatal("Failed to run '%s' with return code %xh.\n", u16tou8(cmd), ret); return -1; /* LCOV_EXCL_STOP */ } @@ -2274,7 +2274,7 @@ static void* thread_spinup(void* arg) /* we cannot use FindFirstFile because it doesn't allow to open the root dir */ if (lstat_sync(devinfo->mount, &st, 0) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed to stat path '%s'. %s.\n", devinfo->mount, strerror(errno)); + log_fatal("Failed to stat path '%s'. %s.\n", devinfo->mount, strerror(errno)); return (void*)-1; /* LCOV_EXCL_STOP */ } @@ -2284,7 +2284,7 @@ static void* thread_spinup(void* arg) if (devresolve(devinfo->mount, devinfo->file, sizeof(devinfo->file), devinfo->wfile, sizeof(devinfo->wfile)) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed to resolve path '%s'.\n", devinfo->mount); + log_fatal("Failed to resolve path '%s'.\n", devinfo->mount); return (void*)-1; /* LCOV_EXCL_STOP */ } @@ -2348,7 +2348,7 @@ static int device_thread(tommy_list* list, void* (*func)(void* arg)) if (pthread_create(&devinfo->thread, 0, func, devinfo) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed to create thread.\n"); + log_fatal("Failed to create thread.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2361,7 +2361,7 @@ static int device_thread(tommy_list* list, void* (*func)(void* arg)) if (pthread_join(devinfo->thread, &retval) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed to join thread.\n"); + log_fatal("Failed to join thread.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2391,7 +2391,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation) if (devresolve(devinfo->mount, devinfo->file, sizeof(devinfo->file), devinfo->wfile, sizeof(devinfo->wfile)) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed to resolve path '%s'.\n", devinfo->mount); + log_fatal("Failed to resolve path '%s'.\n", devinfo->mount); return -1; /* LCOV_EXCL_STOP */ } @@ -2399,7 +2399,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation) /* expand the tree of devices */ if (devtree(devinfo->name, devinfo->smartctl, devinfo->wfile, devinfo, low) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed to expand device '%s'.\n", devinfo->file); + log_fatal("Failed to expand device '%s'.\n", devinfo->file); return -1; /* LCOV_EXCL_STOP */ } @@ -2427,7 +2427,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation) if (operation == DEVICE_SMART) { if (devscan(low) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed to list other devices.\n"); + log_fatal("Failed to list other devices.\n"); return -1; /* LCOV_EXCL_STOP */ } diff --git a/cmdline/mktest.c b/cmdline/mktest.c index 4abec970..76f011c9 100644 --- a/cmdline/mktest.c +++ b/cmdline/mktest.c @@ -149,7 +149,7 @@ void cmd_generate_file(const char* path, int size) if (remove(path) != 0) { if (errno != ENOENT) { /* LCOV_EXCL_START */ - msg_error("Error removing file %s\n", path); + log_fatal("Error removing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -171,21 +171,21 @@ void cmd_generate_file(const char* path, int size) f = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_NOFOLLOW, 0600); if (f < 0) { /* LCOV_EXCL_START */ - msg_error("Error creating file %s\n", path); + log_fatal("Error creating file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (write(f, data, size) != size) { /* LCOV_EXCL_START */ - msg_error("Error writing file %s\n", path); + log_fatal("Error writing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (close(f) != 0) { /* LCOV_EXCL_START */ - msg_error("Error closing file %s\n", path); + log_fatal("Error closing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -203,7 +203,7 @@ void cmd_generate_symlink(const char* path, const char* linkto) if (remove(path) != 0) { if (errno != ENOENT) { /* LCOV_EXCL_START */ - msg_error("Error removing file %s\n", path); + log_fatal("Error removing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -211,7 +211,7 @@ void cmd_generate_symlink(const char* path, const char* linkto) if (symlink(linkto, path) != 0) { /* LCOV_EXCL_START */ - msg_error("Error writing symlink %s\n", path); + log_fatal("Error writing symlink %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -236,7 +236,7 @@ void cmd_generate(int disk, int size) if (mkdir(path, 0777) != 0) { if (errno != EEXIST) { /* LCOV_EXCL_START */ - msg_error("Error creating directory %s\n", path); + log_fatal("Error creating directory %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -294,7 +294,7 @@ void cmd_write(const char* path, int size) if (lstat(path, &st) != 0) { /* LCOV_EXCL_START */ - msg_error("Error accessing %s\n", path); + log_fatal("Error accessing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -321,28 +321,28 @@ void cmd_write(const char* path, int size) f = open(path, O_WRONLY | O_BINARY | O_NOFOLLOW); if (f < 0) { /* LCOV_EXCL_START */ - msg_error("Error creating file %s\n", path); + log_fatal("Error creating file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (lseek(f, off, SEEK_SET) != off) { /* LCOV_EXCL_START */ - msg_error("Error seeking file %s\n", path); + log_fatal("Error seeking file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (write(f, data, size) != size) { /* LCOV_EXCL_START */ - msg_error("Error writing file %s\n", path); + log_fatal("Error writing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (close(f) != 0) { /* LCOV_EXCL_START */ - msg_error("Error closing file %s\n", path); + log_fatal("Error closing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -370,7 +370,7 @@ void cmd_damage(const char* path, int size) if (lstat(path, &st) != 0) { /* LCOV_EXCL_START */ - msg_error("Error accessing %s\n", path); + log_fatal("Error accessing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -398,21 +398,21 @@ void cmd_damage(const char* path, int size) f = open(path, O_RDWR | O_BINARY | O_NOFOLLOW); if (f < 0) { /* LCOV_EXCL_START */ - msg_error("Error creating file %s\n", path); + log_fatal("Error creating file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (lseek(f, off, SEEK_SET) != off) { /* LCOV_EXCL_START */ - msg_error("Error seeking file %s\n", path); + log_fatal("Error seeking file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (read(f, data, size) != size) { /* LCOV_EXCL_START */ - msg_error("Error writing file %s\n", path); + log_fatal("Error writing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -421,28 +421,28 @@ void cmd_damage(const char* path, int size) if (lseek(f, off, SEEK_SET) != off) { /* LCOV_EXCL_START */ - msg_error("Error seeking file %s\n", path); + log_fatal("Error seeking file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (write(f, data, size) != size) { /* LCOV_EXCL_START */ - msg_error("Error writing file %s\n", path); + log_fatal("Error writing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (fallback(f, &st) != 0) { /* LCOV_EXCL_START */ - msg_error("Error setting time for file %s\n", path); + log_fatal("Error setting time for file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (close(f) != 0) { /* LCOV_EXCL_START */ - msg_error("Error closing file %s\n", path); + log_fatal("Error closing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -462,7 +462,7 @@ void cmd_append(const char* path, int size) if (lstat(path, &st) != 0) { /* LCOV_EXCL_START */ - msg_error("Error accessing %s\n", path); + log_fatal("Error accessing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -478,21 +478,21 @@ void cmd_append(const char* path, int size) f = open(path, O_WRONLY | O_APPEND | O_BINARY | O_NOFOLLOW); if (f < 0) { /* LCOV_EXCL_START */ - msg_error("Error opening file %s\n", path); + log_fatal("Error opening file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (write(f, data, size) != size) { /* LCOV_EXCL_START */ - msg_error("Error writing file %s\n", path); + log_fatal("Error writing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (close(f) != 0) { /* LCOV_EXCL_START */ - msg_error("Error closing file %s\n", path); + log_fatal("Error closing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -513,7 +513,7 @@ void cmd_truncate(const char* path, int size) if (lstat(path, &st) != 0) { /* LCOV_EXCL_START */ - msg_error("Error accessing %s\n", path); + log_fatal("Error accessing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -536,21 +536,21 @@ void cmd_truncate(const char* path, int size) f = open(path, O_WRONLY | O_BINARY | O_NOFOLLOW); if (f < 0) { /* LCOV_EXCL_START */ - msg_error("Error opening file %s\n", path); + log_fatal("Error opening file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (ftruncate(f, off) != 0) { /* LCOV_EXCL_START */ - msg_error("Error truncating file %s\n", path); + log_fatal("Error truncating file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (close(f) != 0) { /* LCOV_EXCL_START */ - msg_error("Error closing file %s\n", path); + log_fatal("Error closing file %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -565,7 +565,7 @@ void cmd_delete(const char* path) { if (remove(path) != 0) { /* LCOV_EXCL_START */ - msg_error("Error removing %s\n", path); + log_fatal("Error removing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -584,7 +584,7 @@ void cmd_change(const char* path, int size) if (lstat(path, &st) != 0) { /* LCOV_EXCL_START */ - msg_error("Error accessing %s\n", path); + log_fatal("Error accessing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -595,7 +595,7 @@ void cmd_change(const char* path, int size) /* delete */ if (remove(path) != 0) { /* LCOV_EXCL_START */ - msg_error("Error removing %s\n", path); + log_fatal("Error removing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -605,7 +605,7 @@ void cmd_change(const char* path, int size) if (remove(path) != 0) { /* LCOV_EXCL_START */ - msg_error("Error removing %s\n", path); + log_fatal("Error removing %s\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/nano.c b/cmdline/nano.c index 7a449aba..6a45c529 100644 --- a/cmdline/nano.c +++ b/cmdline/nano.c @@ -56,7 +56,7 @@ void state_nano(struct snapraid_state* state) /* get a random nanosecond value */ if (randomize(&nano, sizeof(nano)) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed to get random values.\n"); + log_fatal("Failed to get random values.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -69,7 +69,7 @@ void state_nano(struct snapraid_state* state) f = open(path, O_RDONLY | O_BINARY | O_NOFOLLOW); if (f == -1) { /* LCOV_EXCL_START */ - msg_error("Error opening file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error opening file '%s'. %s.\n", path, strerror(errno)); continue; /* LCOV_EXCL_STOP */ } @@ -80,7 +80,7 @@ void state_nano(struct snapraid_state* state) if (ret == -1) { /* LCOV_EXCL_START */ close(f); - msg_error("Error accessing file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error accessing file '%s'. %s.\n", path, strerror(errno)); continue; /* LCOV_EXCL_STOP */ } @@ -90,7 +90,7 @@ void state_nano(struct snapraid_state* state) if (ret != 0) { /* LCOV_EXCL_START */ close(f); - msg_error("Error timing file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error timing file '%s'. %s.\n", path, strerror(errno)); continue; /* LCOV_EXCL_STOP */ } @@ -102,7 +102,7 @@ void state_nano(struct snapraid_state* state) if (ret == -1) { /* LCOV_EXCL_START */ close(f); - msg_error("Error accessing file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error accessing file '%s'. %s.\n", path, strerror(errno)); continue; /* LCOV_EXCL_STOP */ } @@ -111,7 +111,7 @@ void state_nano(struct snapraid_state* state) ret = close(f); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error closing file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error closing file '%s'. %s.\n", path, strerror(errno)); continue; /* LCOV_EXCL_STOP */ } @@ -125,7 +125,7 @@ void state_nano(struct snapraid_state* state) /* state changed, we need to update it */ state->need_write = 1; - msg_tag("nano:%s:%s\n", disk->name, esc(file->sub)); + log_tag("nano:%s:%s\n", disk->name, esc(file->sub)); msg_info("nano %s%s\n", disk->dir, file->sub); } } diff --git a/cmdline/parity.c b/cmdline/parity.c index 1075ed6d..902be1af 100644 --- a/cmdline/parity.c +++ b/cmdline/parity.c @@ -135,14 +135,13 @@ void parity_overflow(struct snapraid_state* state, data_off_t size) if (file->blockmax > 0) { if (file->blockvec[file->blockmax - 1].parity_pos >= blockalloc) { - msg_tag("outofparity:%s:%s\n", disk->name, esc(file->sub)); + log_tag("outofparity:%s:%s\n", disk->name, esc(file->sub)); if (first) { first = 0; - msg_error("\nYour data requires more parity than the available space.\n"); - msg_error("Please move the files 'outofparity' to another data disk:\n"); + log_fatal("\nYour data requires more parity than the available space.\n"); + log_fatal("Please move the files 'outofparity' to another data disk:\n"); } - msg_error("outofparity %s%s\n", disk->dir, file->sub); - msg_flush(); + log_fatal("outofparity %s%s\n", disk->dir, file->sub); } } } @@ -164,7 +163,7 @@ int parity_create(struct snapraid_parity_handle* parity, const char* path, data_ parity->f = open(parity->path, flags, 0600); if (parity->f == -1) { /* LCOV_EXCL_START */ - msg_error("Error opening parity file '%s'. %s.\n", parity->path, strerror(errno)); + log_fatal("Error opening parity file '%s'. %s.\n", parity->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -173,7 +172,7 @@ int parity_create(struct snapraid_parity_handle* parity, const char* path, data_ ret = fstat(parity->f, &parity->st); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error accessing parity file '%s'. %s.\n", parity->path, strerror(errno)); + log_fatal("Error accessing parity file '%s'. %s.\n", parity->path, strerror(errno)); goto bail; /* LCOV_EXCL_STOP */ } @@ -184,7 +183,7 @@ int parity_create(struct snapraid_parity_handle* parity, const char* path, data_ ret = posix_fadvise(parity->f, 0, 0, POSIX_FADV_SEQUENTIAL); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error advising parity file '%s'. %s.\n", parity->path, strerror(ret)); + log_fatal("Error advising parity file '%s'. %s.\n", parity->path, strerror(ret)); goto bail; /* LCOV_EXCL_STOP */ } @@ -260,7 +259,7 @@ int parity_chsize(struct snapraid_parity_handle* parity, data_off_t size, data_o ret = fstat(parity->f, &parity->st); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error accessing parity file '%s'. %s.\n", parity->path, strerror(errno)); + log_fatal("Error accessing parity file '%s'. %s.\n", parity->path, strerror(errno)); goto bail; /* LCOV_EXCL_STOP */ } @@ -272,9 +271,9 @@ int parity_chsize(struct snapraid_parity_handle* parity, data_off_t size, data_o if (f_ret != 0) { /* LCOV_EXCL_START */ if (f_errno == ENOSPC) { - msg_error("Failed to grow parity file '%s' to size %" PRIu64 " using %s due lack of space.\n", parity->path, size, call); + log_fatal("Failed to grow parity file '%s' to size %" PRIu64 " using %s due lack of space.\n", parity->path, size, call); } else { - msg_error("Error growing parity file '%s' to size %" PRIu64 " using %s. Do you have enough space? %s.\n", parity->path, size, call, strerror(f_errno)); + log_fatal("Error growing parity file '%s' to size %" PRIu64 " using %s. Do you have enough space? %s.\n", parity->path, size, call, strerror(f_errno)); } goto bail; /* LCOV_EXCL_STOP */ @@ -294,7 +293,7 @@ int parity_chsize(struct snapraid_parity_handle* parity, data_off_t size, data_o ret = fstat(parity->f, &parity->st); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error accessing parity file '%s'. %s.\n", parity->path, strerror(errno)); + log_fatal("Error accessing parity file '%s'. %s.\n", parity->path, strerror(errno)); goto bail; /* LCOV_EXCL_STOP */ } @@ -305,7 +304,7 @@ int parity_chsize(struct snapraid_parity_handle* parity, data_off_t size, data_o /* now check the error */ if (f_ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error truncating parity file '%s' to size %" PRIu64 ". %s.\n", parity->path, size, strerror(f_errno)); + log_fatal("Error truncating parity file '%s' to size %" PRIu64 ". %s.\n", parity->path, size, strerror(f_errno)); goto bail; /* LCOV_EXCL_STOP */ } @@ -338,7 +337,7 @@ int parity_open(struct snapraid_parity_handle* parity, const char* path, int mod flags |= O_SEQUENTIAL; parity->f = open_noatime(parity->path, flags); if (parity->f == -1) { - msg_error("Error opening parity file '%s'. %s.\n", parity->path, strerror(errno)); + log_fatal("Error opening parity file '%s'. %s.\n", parity->path, strerror(errno)); return -1; } @@ -346,7 +345,7 @@ int parity_open(struct snapraid_parity_handle* parity, const char* path, int mod ret = fstat(parity->f, &parity->st); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error accessing parity file '%s'. %s.\n", parity->path, strerror(errno)); + log_fatal("Error accessing parity file '%s'. %s.\n", parity->path, strerror(errno)); goto bail; /* LCOV_EXCL_STOP */ } @@ -360,7 +359,7 @@ int parity_open(struct snapraid_parity_handle* parity, const char* path, int mod ret = posix_fadvise(parity->f, 0, 0, POSIX_FADV_SEQUENTIAL); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error advising parity file '%s'. %s.\n", parity->path, strerror(ret)); + log_fatal("Error advising parity file '%s'. %s.\n", parity->path, strerror(ret)); goto bail; /* LCOV_EXCL_STOP */ } @@ -389,7 +388,7 @@ int parity_sync(struct snapraid_parity_handle* parity) ret = fsync(parity->f); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error synching parity file '%s'. %s.\n", parity->path, strerror(errno)); + log_fatal("Error synching parity file '%s'. %s.\n", parity->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -412,7 +411,7 @@ int parity_close(struct snapraid_parity_handle* parity) /* This is a serious error, as it may be the result of a failed write */ /* identified at later time. */ /* In a normal filesystem (not NFS) it should never happen */ - msg_error("Error closing parity file '%s'. %s.\n", parity->path, strerror(errno)); + log_fatal("Error closing parity file '%s'. %s.\n", parity->path, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -437,9 +436,9 @@ int parity_write(struct snapraid_parity_handle* parity, block_off_t pos, unsigne if (lseek(parity->f, offset, SEEK_SET) != offset) { /* LCOV_EXCL_START */ if (errno == ENOSPC) { - msg_error("Failed to grow parity file '%s' using lseek due lack of space.\n", parity->path); + log_fatal("Failed to grow parity file '%s' using lseek due lack of space.\n", parity->path); } else { - msg_error("Error seeking file '%s'. %s.\n", parity->path, strerror(errno)); + log_fatal("Error seeking file '%s'. %s.\n", parity->path, strerror(errno)); } return -1; /* LCOV_EXCL_STOP */ @@ -450,9 +449,9 @@ int parity_write(struct snapraid_parity_handle* parity, block_off_t pos, unsigne if (write_ret != (ssize_t)block_size) { /* conversion is safe because block_size is always small */ /* LCOV_EXCL_START */ if (errno == ENOSPC) { - msg_error("Failed to grow parity file '%s' using write due lack of space.\n", parity->path); + log_fatal("Failed to grow parity file '%s' using write due lack of space.\n", parity->path); } else { - msg_error("Error writing file '%s'. %s.\n", parity->path, strerror(errno)); + log_fatal("Error writing file '%s'. %s.\n", parity->path, strerror(errno)); } return -1; /* LCOV_EXCL_STOP */ diff --git a/cmdline/pool.c b/cmdline/pool.c index 743be52f..775f355a 100644 --- a/cmdline/pool.c +++ b/cmdline/pool.c @@ -33,7 +33,7 @@ static int clean_dir(struct snapraid_state* state, const char* dir) d = opendir(dir); if (!d) { /* LCOV_EXCL_START */ - msg_error("Error opening pool directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal("Error opening pool directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -49,7 +49,7 @@ static int clean_dir(struct snapraid_state* state, const char* dir) dd = readdir(d); if (dd == 0 && errno != 0) { /* LCOV_EXCL_START */ - msg_error("Error reading pool directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal("Error reading pool directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -73,7 +73,7 @@ static int clean_dir(struct snapraid_state* state, const char* dir) if (st.st_mode == 0) { if (lstat(path_next, &st) != 0) { /* LCOV_EXCL_START */ - msg_error("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -82,7 +82,7 @@ static int clean_dir(struct snapraid_state* state, const char* dir) /* get lstat info about the file */ if (lstat(path_next, &st) != 0) { /* LCOV_EXCL_START */ - msg_error("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -95,7 +95,7 @@ static int clean_dir(struct snapraid_state* state, const char* dir) ret = remove(path_next); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Error removing symlink '%s'. %s.\n", path_next, strerror(errno)); + log_fatal("Error removing symlink '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -113,13 +113,13 @@ static int clean_dir(struct snapraid_state* state, const char* dir) /* in Windows just ignore EACCES errors removing directories */ /* because it could happen that the directory is in use */ /* and it cannot be removed */ - msg_error("Directory '%s' not removed because it's in use.\n", path_next); + log_fatal("Directory '%s' not removed because it's in use.\n", path_next); ignored = 1; } else #endif { /* LCOV_EXCL_START */ - msg_error("Error removing pool directory '%s'. %s.\n", path_next, strerror(errno)); + log_fatal("Error removing pool directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -136,7 +136,7 @@ static int clean_dir(struct snapraid_state* state, const char* dir) if (closedir(d) != 0) { /* LCOV_EXCL_START */ - msg_error("Error closing pool directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal("Error closing pool directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -181,17 +181,17 @@ static void make_link(const char* pool_dir, const char* share_dir, struct snapra ret = symlink(linkto_exported, path); if (ret != 0) { if (errno == EEXIST) { - msg_error("WARNING! Duplicate pooling for '%s'\n", path); + log_fatal("WARNING! Duplicate pooling for '%s'\n", path); #ifdef _WIN32 } else if (errno == EPERM) { /* LCOV_EXCL_START */ - msg_error("You must run as Adminstrator to be able to create symlinks.\n"); + log_fatal("You must run as Adminstrator to be able to create symlinks.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ #endif } else { /* LCOV_EXCL_START */ - msg_error("Error writing symlink '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error writing symlink '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -207,7 +207,7 @@ void state_pool(struct snapraid_state* state) if (state->pool[0] == 0) { /* LCOV_EXCL_START */ - msg_error("To use the 'pool' command you must set the pool directory in the configuration file\n"); + log_fatal("To use the 'pool' command you must set the pool directory in the configuration file\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -255,8 +255,8 @@ void state_pool(struct snapraid_state* state) else msg_status("No link created\n"); - msg_tag("summary:link_count::%u\n", count); - msg_tag("summary:exit:ok\n"); - msg_flush(); + log_tag("summary:link_count::%u\n", count); + log_tag("summary:exit:ok\n"); + log_flush(); } diff --git a/cmdline/rehash.c b/cmdline/rehash.c index 79151648..f62c659d 100644 --- a/cmdline/rehash.c +++ b/cmdline/rehash.c @@ -38,14 +38,14 @@ void state_rehash(struct snapraid_state* state) /* check if a rehash is already in progress */ if (state->prevhash != HASH_UNDEFINED) { /* LCOV_EXCL_START */ - msg_error("You already have a rehash in progress.\n"); + log_fatal("You already have a rehash in progress.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (state->hash == state->besthash) { /* LCOV_EXCL_START */ - msg_error("You are already using the best hash for your platform.\n"); + log_fatal("You are already using the best hash for your platform.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -58,7 +58,7 @@ void state_rehash(struct snapraid_state* state) state->hash = state->besthash; if (randomize(state->hashseed, HASH_SIZE) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed to get random values.\n"); + log_fatal("Failed to get random values.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -76,7 +76,7 @@ void state_rehash(struct snapraid_state* state) if (info_get_rehash(info)) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency for a rehash already in progress\n"); + log_fatal("Internal inconsistency for a rehash already in progress\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/scan.c b/cmdline/scan.c index 96d686ff..055cfed1 100644 --- a/cmdline/scan.c +++ b/cmdline/scan.c @@ -95,7 +95,7 @@ static void scan_link(struct snapraid_scan* scan, int is_diff, const char* sub, /* check if multiple files have the same name */ if (link_flag_has(link, FILE_IS_PRESENT)) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency for link '%s%s'\n", disk->dir, sub); + log_fatal("Internal inconsistency for link '%s%s'\n", disk->dir, sub); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -109,7 +109,7 @@ static void scan_link(struct snapraid_scan* scan, int is_diff, const char* sub, ++scan->count_equal; if (state->opt.gui) { - msg_tag("scan:equal:%s:%s\n", disk->name, esc(link->sub)); + log_tag("scan:equal:%s:%s\n", disk->name, esc(link->sub)); } } else { /* it's an update */ @@ -119,7 +119,7 @@ static void scan_link(struct snapraid_scan* scan, int is_diff, const char* sub, ++scan->count_change; - msg_tag("scan:update:%s:%s\n", disk->name, esc(link->sub)); + log_tag("scan:update:%s:%s\n", disk->name, esc(link->sub)); if (is_diff) { printf("update %s%s\n", disk->dir, link->sub); } @@ -136,7 +136,7 @@ static void scan_link(struct snapraid_scan* scan, int is_diff, const char* sub, /* create the new link */ ++scan->count_insert; - msg_tag("scan:add:%s:%s\n", disk->name, esc(sub)); + log_tag("scan:add:%s:%s\n", disk->name, esc(sub)); if (is_diff) { printf("add %s%s\n", disk->dir, sub); } @@ -214,7 +214,7 @@ static void scan_file_deallocate(struct snapraid_scan* scan, struct snapraid_fil break; default : /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in deallocating for block %u state %u\n", block->parity_pos, block_state); + log_fatal("Internal inconsistency in deallocating for block %u state %u\n", block->parity_pos, block_state); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -306,7 +306,7 @@ static void scan_file_delayed_insert(struct snapraid_scan* scan, struct snapraid if (filephy(path_next, file->size, &file->physical) != 0) { /* LCOV_EXCL_START */ - msg_error("Error in getting the physical offset of file '%s'. %s.\n", path_next, strerror(errno)); + log_fatal("Error in getting the physical offset of file '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -348,7 +348,7 @@ static void scan_file_refresh(struct snapraid_scan* scan, const char* sub, struc if (lstat_sync(path_next, &synced_st, physical) != 0) { /* LCOV_EXCL_START */ - msg_error("Error in stat file '%s'. %s.\n", path_next, strerror(errno)); + log_fatal("Error in stat file '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -366,8 +366,8 @@ static void scan_file_refresh(struct snapraid_scan* scan, const char* sub, struc * Why is the file size reported incorrectly for files that are still being written to? * http://blogs.msdn.com/b/oldnewthing/archive/2011/12/26/10251026.aspx */ - msg_error("WARNING! Detected uncached time change for file '%s'\n", sub); - msg_error("It's better if you run SnapRAID without other processes running.\n"); + log_fatal("WARNING! Detected uncached time change for file '%s'\n", sub); + log_fatal("It's better if you run SnapRAID without other processes running.\n"); #endif st->st_mtime = synced_st.st_mtime; st->st_mtimensec = synced_st.st_mtimensec; @@ -375,15 +375,15 @@ static void scan_file_refresh(struct snapraid_scan* scan, const char* sub, struc if (st->st_size != synced_st.st_size) { #ifndef _WIN32 - msg_error("WARNING! Detected uncached size change for file '%s'\n", sub); - msg_error("It's better if you run SnapRAID without other processes running.\n"); + log_fatal("WARNING! Detected uncached size change for file '%s'\n", sub); + log_fatal("It's better if you run SnapRAID without other processes running.\n"); #endif st->st_size = synced_st.st_size; } if (st->st_ino != synced_st.st_ino) { - msg_error("DANGER! Detected uncached inode change for file '%s'\n", sub); - msg_error("Please ensure to run SnapRAID without other processes running.\n"); + log_fatal("DANGER! Detected uncached inode change for file '%s'\n", sub); + log_fatal("Please ensure to run SnapRAID without other processes running.\n"); /* at this point, it's too late to change inode */ /* and having inconsistent inodes may result to internal failures */ /* so, it's better to abort */ @@ -611,7 +611,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, #if HAVE_STRUCT_STAT_ST_NLINK if (st->st_nlink <= 1) { /* LCOV_EXCL_START */ - msg_error("Internal inode '%" PRIu64 "' inconsistency for file '%s%s' already present\n", (uint64_t)st->st_ino, disk->dir, sub); + log_fatal("Internal inode '%" PRIu64 "' inconsistency for file '%s%s' already present\n", (uint64_t)st->st_ino, disk->dir, sub); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -639,7 +639,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, /* if the path is different, it means a moved file with the same inode */ ++scan->count_move; - msg_tag("scan:move:%s:%s:%s\n", disk->name, esc(file->sub), esc(sub)); + log_tag("scan:move:%s:%s:%s\n", disk->name, esc(file->sub), esc(sub)); if (is_diff) { printf("move %s%s -> %s%s\n", disk->dir, file->sub, disk->dir, sub); } @@ -660,7 +660,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, ++scan->count_equal; if (state->opt.gui) { - msg_tag("scan:equal:%s:%s\n", disk->name, esc(file->sub)); + log_tag("scan:equal:%s:%s\n", disk->name, esc(file->sub)); } } @@ -679,7 +679,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, /* for sure it cannot be already present */ if (file_flag_has(file, FILE_IS_PRESENT)) { /* LCOV_EXCL_START */ - msg_error("Internal inode '%" PRIu64 "' inconsistency for files '%s%s' and '%s%s' matching and already present but different\n", file->inode, disk->dir, sub, disk->dir, file->sub); + log_fatal("Internal inode '%" PRIu64 "' inconsistency for files '%s%s' and '%s%s' matching and already present but different\n", file->inode, disk->dir, sub, disk->dir, file->sub); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -729,7 +729,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, /* here the inode has to be different, otherwise we would have found it before */ if (file->inode == st->st_ino) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in inode '%" PRIu64 "' for files '%s%s' as unexpected matching\n", file->inode, disk->dir, sub); + log_fatal("Internal inconsistency in inode '%" PRIu64 "' for files '%s%s' as unexpected matching\n", file->inode, disk->dir, sub); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -738,7 +738,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, /* for sure it cannot be already present */ if (file_flag_has(file, FILE_IS_PRESENT)) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in path for file '%s%s' matching and already present\n", disk->dir, sub); + log_fatal("Internal inconsistency in path for file '%s%s' matching and already present\n", disk->dir, sub); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -776,7 +776,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, /* like when restoring a backup that restores also the timestamp */ ++scan->count_restore; - msg_tag("scan:restore:%s:%s\n", disk->name, esc(sub)); + log_tag("scan:restore:%s:%s\n", disk->name, esc(sub)); if (is_diff) { printf("restore %s%s\n", disk->dir, sub); } @@ -799,7 +799,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, ++scan->count_equal; if (state->opt.gui) { - msg_tag("scan:equal:%s:%s\n", disk->name, esc(file->sub)); + log_tag("scan:equal:%s:%s\n", disk->name, esc(file->sub)); } } @@ -831,11 +831,11 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, if (is_original_file_size_different_than_zero && st->st_size == 0) { if (!state->opt.force_zero) { /* LCOV_EXCL_START */ - msg_error("The file '%s%s' has unexpected zero size!\n", disk->dir, sub); - msg_error("It's possible that after a kernel crash this file was lost,\n"); - msg_error("and you can use 'snapraid --filter %s fix' to recover it.\n", sub); + log_fatal("The file '%s%s' has unexpected zero size!\n", disk->dir, sub); + log_fatal("It's possible that after a kernel crash this file was lost,\n"); + log_fatal("and you can use 'snapraid --filter %s fix' to recover it.\n", sub); if (!is_diff) { - msg_error("If this an expected condition you can '%s' anyway using 'snapraid --force-zero %s'\n", state->command, state->command); + log_fatal("If this an expected condition you can '%s' anyway using 'snapraid --force-zero %s'\n", state->command, state->command); exit(EXIT_FAILURE); } /* LCOV_EXCL_STOP */ @@ -876,7 +876,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, /* revert old counter and use the copy one */ ++scan->count_copy; - msg_tag("scan:copy:%s:%s:%s:%s\n", other_disk->name, esc(other_file->sub), disk->name, esc(file->sub)); + log_tag("scan:copy:%s:%s:%s:%s\n", other_disk->name, esc(other_file->sub), disk->name, esc(file->sub)); if (is_diff) { printf("copy %s%s -> %s%s\n", other_disk->dir, other_file->sub, disk->dir, file->sub); } @@ -895,14 +895,14 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, if (is_file_already_present) { ++scan->count_change; - msg_tag("scan:update:%s:%s\n", disk->name, esc(sub)); + log_tag("scan:update:%s:%s\n", disk->name, esc(sub)); if (is_diff) { printf("update %s%s\n", disk->dir, sub); } } else { ++scan->count_insert; - msg_tag("scan:add:%s:%s\n", disk->name, esc(sub)); + log_tag("scan:add:%s:%s\n", disk->name, esc(sub)); if (is_diff) { printf("add %s%s\n", disk->dir, sub); } @@ -967,7 +967,7 @@ static void scan_emptydir(struct snapraid_scan* scan, const char* sub) /* check if multiple files have the same name */ if (dir_flag_has(dir, FILE_IS_PRESENT)) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency for dir '%s%s'\n", disk->dir, sub); + log_fatal("Internal inconsistency for dir '%s%s'\n", disk->dir, sub); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1045,7 +1045,7 @@ struct stat* dstat(const char* file, struct stat* st) { if (lstat(file, st) != 0) { /* LCOV_EXCL_START */ - msg_error("Error in stat file/directory '%s'. %s.\n", file, strerror(errno)); + log_fatal("Error in stat file/directory '%s'. %s.\n", file, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1071,8 +1071,8 @@ static int scan_dir(struct snapraid_scan* scan, int is_diff, const char* dir, co d = opendir(dir); if (!d) { /* LCOV_EXCL_START */ - msg_error("Error opening directory '%s'. %s.\n", dir, strerror(errno)); - msg_error("You can exclude it in the config file with:\n\texclude /%s\n", sub); + log_fatal("Error opening directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal("You can exclude it in the config file with:\n\texclude /%s\n", sub); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1091,8 +1091,8 @@ static int scan_dir(struct snapraid_scan* scan, int is_diff, const char* dir, co dd = readdir(d); if (dd == 0 && errno != 0) { /* LCOV_EXCL_START */ - msg_error("Error reading directory '%s'. %s.\n", dir, strerror(errno)); - msg_error("You can exclude it in the config file with:\n\texclude /%s\n", sub); + log_fatal("Error reading directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal("You can exclude it in the config file with:\n\texclude /%s\n", sub); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1111,7 +1111,7 @@ static int scan_dir(struct snapraid_scan* scan, int is_diff, const char* dir, co /* check for not supported file names */ if (name[0] == 0) { /* LCOV_EXCL_START */ - msg_error("Unsupported name '%s' in file '%s'.\n", name, path_next); + log_fatal("Unsupported name '%s' in file '%s'.\n", name, path_next); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1152,7 +1152,7 @@ static int scan_dir(struct snapraid_scan* scan, int is_diff, const char* dir, co if (closedir(d) != 0) { /* LCOV_EXCL_START */ - msg_error("Error closing directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal("Error closing directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1219,7 +1219,7 @@ static int scan_dir(struct snapraid_scan* scan, int is_diff, const char* dir, co if (st->st_mode == 0) { if (lstat(path_next, st) != 0) { /* LCOV_EXCL_START */ - msg_error("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1249,7 +1249,7 @@ static int scan_dir(struct snapraid_scan* scan, int is_diff, const char* dir, co if (st->st_ino == 0) { if (lstat_sync(path_next, st, 0) != 0) { /* LCOV_EXCL_START */ - msg_error("Error in stat file '%s'. %s.\n", path_next, strerror(errno)); + log_fatal("Error in stat file '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1269,13 +1269,13 @@ static int scan_dir(struct snapraid_scan* scan, int is_diff, const char* dir, co ret = readlink(path_next, subnew, sizeof(subnew)); if (ret >= PATH_MAX) { /* LCOV_EXCL_START */ - msg_error("Error in readlink file '%s'. Symlink too long.\n", path_next); + log_fatal("Error in readlink file '%s'. Symlink too long.\n", path_next); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Error in readlink file '%s'. %s.\n", path_next, strerror(errno)); + log_fatal("Error in readlink file '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1299,7 +1299,7 @@ static int scan_dir(struct snapraid_scan* scan, int is_diff, const char* dir, co /* in Unix don't follow mount points in different devices */ /* in Windows we are already skipping them reporting them as special files */ if ((uint64_t)st->st_dev != disk->device) { - msg_error("WARNING! Ignoring mount point '%s' because it appears to be in a different device\n", path_next); + log_fatal("WARNING! Ignoring mount point '%s' because it appears to be in a different device\n", path_next); } else #endif { @@ -1325,7 +1325,7 @@ static int scan_dir(struct snapraid_scan* scan, int is_diff, const char* dir, co if (!st) st = DSTAT(path_next, dd, &st_buf); - msg_error("WARNING! Ignoring special '%s' file '%s'\n", stat_desc(st), path_next); + log_fatal("WARNING! Ignoring special '%s' file '%s'\n", stat_desc(st), path_next); } else { msg_verbose("Excluding special file '%s' for rule '%s'\n", path_next, filter_type(reason, out, sizeof(out))); } @@ -1387,7 +1387,7 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) ret = fsinfo(disk->dir, &has_persistent_inode, 0, 0); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Error accessing disk '%s' to get filesystem info. %s.\n", disk->dir, strerror(errno)); + log_fatal("Error accessing disk '%s' to get filesystem info. %s.\n", disk->dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1447,7 +1447,7 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) if (!file_flag_has(file, FILE_IS_PRESENT)) { ++scan->count_remove; - msg_tag("scan:remove:%s:%s\n", disk->name, esc(file->sub)); + log_tag("scan:remove:%s:%s\n", disk->name, esc(file->sub)); if (is_diff) { printf("remove %s%s\n", disk->dir, file->sub); } @@ -1468,7 +1468,7 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) if (!link_flag_has(link, FILE_IS_PRESENT)) { ++scan->count_remove; - msg_tag("scan:remove:%s:%s\n", disk->name, esc(link->sub)); + log_tag("scan:remove:%s:%s\n", disk->name, esc(link->sub)); if (is_diff) { printf("remove %s%s\n", disk->dir, link->sub); } @@ -1529,7 +1529,7 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) /* if verbose, prints the list of duplicates real offsets */ /* other cases are for offsets not supported, so we don't need to report them file by file */ if (phy_last >= FILEPHY_REAL_OFFSET) { - msg_error("WARNING! Files '%s%s' and '%s%s' have the same physical offset %" PRId64 ".\n", disk->dir, phy_file_last->sub, disk->dir, file->sub, phy_last); + log_fatal("WARNING! Files '%s%s' and '%s%s' have the same physical offset %" PRId64 ".\n", disk->dir, phy_file_last->sub, disk->dir, file->sub, phy_last); } ++phy_dup; } @@ -1586,20 +1586,20 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) if (scan->count_equal == 0 && scan->count_move == 0 && scan->count_restore == 0 && (scan->count_remove != 0 || scan->count_change != 0)) { if (!done) { done = 1; - msg_error("WARNING! All the files previously present in disk '%s' at dir '%s'", disk->name, disk->dir); + log_fatal("WARNING! All the files previously present in disk '%s' at dir '%s'", disk->name, disk->dir); } else { - msg_error(", disk '%s' at dir '%s'", disk->name, disk->dir); + log_fatal(", disk '%s' at dir '%s'", disk->name, disk->dir); } } } if (done) { - msg_error("\nare now missing or rewritten!\n"); - msg_error("This could happen when deleting all the files from a disk,\n"); - msg_error("and restoring them with a program that it's not setting\n"); - msg_error("correctly the timestamps.\n"); - msg_error("It's also possible that you have some disks not mounted.\n"); + log_fatal("\nare now missing or rewritten!\n"); + log_fatal("This could happen when deleting all the files from a disk,\n"); + log_fatal("and restoring them with a program that it's not setting\n"); + log_fatal("correctly the timestamps.\n"); + log_fatal("It's also possible that you have some disks not mounted.\n"); if (!is_diff) { - msg_error("If you want to '%s' anyway, use 'snapraid --force-empty %s'.", state->command, state->command); + log_fatal("If you want to '%s' anyway, use 'snapraid --force-empty %s'.", state->command, state->command); exit(EXIT_FAILURE); } } @@ -1614,14 +1614,14 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) if (disk->has_unreliable_physical) { if (!done) { done = 1; - msg_error("WARNING! Physical offsets not supported for disk '%s'", disk->name); + log_fatal("WARNING! Physical offsets not supported for disk '%s'", disk->name); } else { - msg_error(", '%s'", disk->name); + log_fatal(", '%s'", disk->name); } } } if (done) { - msg_error(". Files order won't be optimal.\n"); + log_fatal(". Files order won't be optimal.\n"); } } @@ -1633,14 +1633,14 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) if (disk->has_volatile_inodes) { if (!done) { done = 1; - msg_error("WARNING! Inodes are not persistent for disks: '%s'", disk->name); + log_fatal("WARNING! Inodes are not persistent for disks: '%s'", disk->name); } else { - msg_error(", '%s'", disk->name); + log_fatal(", '%s'", disk->name); } } } if (done) { - msg_error(". Move operations won't be optimal.\n"); + log_fatal(". Move operations won't be optimal.\n"); } /* checks for disks with changed UUID */ @@ -1655,14 +1655,14 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) if (disk->has_different_uuid && !disk->had_empty_uuid) { if (!done) { done = 1; - msg_error("WARNING! UUID is changed for disks: '%s'", disk->name); + log_fatal("WARNING! UUID is changed for disks: '%s'", disk->name); } else { - msg_error(", '%s'", disk->name); + log_fatal(", '%s'", disk->name); } } } if (done) { - msg_error(". Move operations won't be optimal.\n"); + log_fatal(". Move operations won't be optimal.\n"); } /* checks for disks with unsupported UUID */ @@ -1673,14 +1673,14 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) if (disk->has_unsupported_uuid) { if (!done) { done = 1; - msg_error("WARNING! UUID is unsupported for disks: '%s'", disk->name); + log_fatal("WARNING! UUID is unsupported for disks: '%s'", disk->name); } else { - msg_error(", '%s'", disk->name); + log_fatal(", '%s'", disk->name); } } } if (done) { - msg_error(". Move operations won't be optimal.\n"); + log_fatal(". Move operations won't be optimal.\n"); } total.count_equal = 0; @@ -1717,13 +1717,13 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) msg("%8u removed\n", total.count_remove); msg("%8u added\n", total.count_insert); - msg_tag("summary:equal:%u\n", total.count_equal); - msg_tag("summary:moved:%u\n", total.count_move); - msg_tag("summary:copied:%u\n", total.count_copy); - msg_tag("summary:restored:%u\n", total.count_restore); - msg_tag("summary:updated:%u\n", total.count_change); - msg_tag("summary:removed:%u\n", total.count_remove); - msg_tag("summary:added:%u\n", total.count_insert); + log_tag("summary:equal:%u\n", total.count_equal); + log_tag("summary:moved:%u\n", total.count_move); + log_tag("summary:copied:%u\n", total.count_copy); + log_tag("summary:restored:%u\n", total.count_restore); + log_tag("summary:updated:%u\n", total.count_change); + log_tag("summary:removed:%u\n", total.count_remove); + log_tag("summary:added:%u\n", total.count_insert); no_difference = !total.count_move && !total.count_copy && !total.count_restore && !total.count_change && !total.count_remove && !total.count_insert; @@ -1737,11 +1737,11 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) } if (no_difference) { - msg_tag("summary:exit:equal\n"); + log_tag("summary:exit:equal\n"); } else { - msg_tag("summary:exit:diff\n"); + log_tag("summary:exit:diff\n"); } - msg_flush(); + log_flush(); tommy_list_foreach(&scanlist, (tommy_foreach_func*)free); diff --git a/cmdline/scrub.c b/cmdline/scrub.c index bc977f58..16aebb66 100644 --- a/cmdline/scrub.c +++ b/cmdline/scrub.c @@ -228,40 +228,40 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par /* This one is really an unexpected error, because we are only reading */ /* and closing a descriptor should never fail */ if (errno == EIO) { - msg_tag("error:%u:%s:%s: Close EIO error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); - msg_error("DANGER! Unexpected input/output close error in a data disk, it isn't possible to scrub.\n"); - msg_error("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); - msg_error("Stopping at block %u\n", i); + log_tag("error:%u:%s:%s: Close EIO error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); + log_fatal("DANGER! Unexpected input/output close error in a data disk, it isn't possible to scrub.\n"); + log_fatal("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); + log_fatal("Stopping at block %u\n", i); ++io_error; goto bail; } - msg_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); - msg_error("WARNING! Unexpected close error in a data disk, it isn't possible to scrub.\n"); - msg_error("Ensure that file '%s' can be accessed.\n", handle[j].path); - msg_error("Stopping at block %u\n", i); + log_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); + log_fatal("WARNING! Unexpected close error in a data disk, it isn't possible to scrub.\n"); + log_fatal("Ensure that file '%s' can be accessed.\n", handle[j].path); + log_fatal("Stopping at block %u\n", i); ++error; goto bail; /* LCOV_EXCL_STOP */ } } - ret = handle_open(&handle[j], block_file_get(block), state->file_mode, msg_warning, 0); + ret = handle_open(&handle[j], block_file_get(block), state->file_mode, log_error, 0); if (ret == -1) { /* file we have tried to open for error reporting */ struct snapraid_file* file = block_file_get(block); if (errno == EIO) { /* LCOV_EXCL_START */ - msg_tag("error:%u:%s:%s: Open EIO error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); - msg_error("DANGER! Unexpected input/output open error in a data disk, it isn't possible to scrub.\n"); - msg_error("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); - msg_error("Stopping at block %u\n", i); + log_tag("error:%u:%s:%s: Open EIO error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); + log_fatal("DANGER! Unexpected input/output open error in a data disk, it isn't possible to scrub.\n"); + log_fatal("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); + log_fatal("Stopping at block %u\n", i); ++io_error; goto bail; /* LCOV_EXCL_STOP */ } - msg_tag("error:%u:%s:%s: Open error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); + log_tag("error:%u:%s:%s: Open error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); ++error; error_on_this_block = 1; continue; @@ -283,29 +283,29 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par /* from the last sync, as we are expected to return errors if running */ /* in an unsynced array. This is just like the check command. */ - read_size = handle_read(&handle[j], block, buffer[j], state->block_size, msg_warning, 0); + read_size = handle_read(&handle[j], block, buffer[j], state->block_size, log_error, 0); if (read_size == -1) { /* file we are processing for error reporting */ struct snapraid_file* file = block_file_get(block); if (errno == EIO) { - msg_tag("error:%u:%s:%s: Read EIO error at position %u. %s\n", i, disk->name, esc(file->sub), block_file_pos(block), strerror(errno)); + log_tag("error:%u:%s:%s: Read EIO error at position %u. %s\n", i, disk->name, esc(file->sub), block_file_pos(block), strerror(errno)); if (io_error >= state->opt.io_error_limit) { /* LCOV_EXCL_START */ - msg_error("DANGER! Too many input/output read error in a data disk, it isn't possible to scrub.\n"); - msg_error("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); - msg_error("Stopping at block %u\n", i); + log_fatal("DANGER! Too many input/output read error in a data disk, it isn't possible to scrub.\n"); + log_fatal("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); + log_fatal("Stopping at block %u\n", i); ++io_error; goto bail; /* LCOV_EXCL_STOP */ } - msg_warning("Input/Output error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block)); + log_error("Input/Output error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block)); ++io_error; io_error_on_this_block = 1; continue; } - msg_tag("error:%u:%s:%s: Read error at position %u. %s\n", i, disk->name, esc(file->sub), block_file_pos(block), strerror(errno)); + log_tag("error:%u:%s:%s: Read error at position %u. %s\n", i, disk->name, esc(file->sub), block_file_pos(block), strerror(errno)); ++error; error_on_this_block = 1; continue; @@ -330,14 +330,14 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par if (block_has_updated_hash(block)) { /* compare the hash */ if (memcmp(hash, block->hash, HASH_SIZE) != 0) { - msg_tag("error:%u:%s:%s: Data error at position %u\n", i, disk->name, esc(handle[j].file->sub), block_file_pos(block)); + log_tag("error:%u:%s:%s: Data error at position %u\n", i, disk->name, esc(handle[j].file->sub), block_file_pos(block)); /* it's a silent error only if we are dealing with synced files */ if (file_is_unsynced) { ++error; error_on_this_block = 1; } else { - msg_warning("Data error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block)); + log_error("Data error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block)); ++silent_error; silent_error_on_this_block = 1; } @@ -361,29 +361,29 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par /* read the parity */ for (l = 0; l < state->level; ++l) { - ret = parity_read(parity[l], i, buffer_recov[l], state->block_size, msg_warning); + ret = parity_read(parity[l], i, buffer_recov[l], state->block_size, log_error); if (ret == -1) { buffer_recov[l] = 0; if (errno == EIO) { - msg_tag("parity_error:%u:%s: Read EIO error. %s\n", i, lev_config_name(l), strerror(errno)); + log_tag("parity_error:%u:%s: Read EIO error. %s\n", i, lev_config_name(l), strerror(errno)); if (io_error >= state->opt.io_error_limit) { /* LCOV_EXCL_START */ - msg_error("DANGER! Too many input/output read error in the %s disk, it isn't possible to scrub.\n", lev_name(l)); - msg_error("Ensure that disk '%s' is sane and can be read.\n", lev_config_name(l)); - msg_error("Stopping at block %u\n", i); + log_fatal("DANGER! Too many input/output read error in the %s disk, it isn't possible to scrub.\n", lev_name(l)); + log_fatal("Ensure that disk '%s' is sane and can be read.\n", lev_config_name(l)); + log_fatal("Stopping at block %u\n", i); ++io_error; goto bail; /* LCOV_EXCL_STOP */ } - msg_warning("Input/Output error in parity '%s' at position '%u'\n", lev_config_name(l), i); + log_error("Input/Output error in parity '%s' at position '%u'\n", lev_config_name(l), i); ++io_error; io_error_on_this_block = 1; continue; } - msg_tag("parity_error:%u:%s: Read error. %s\n", i, lev_config_name(l), strerror(errno)); + log_tag("parity_error:%u:%s: Read error. %s\n", i, lev_config_name(l), strerror(errno)); ++error; error_on_this_block = 1; continue; @@ -399,14 +399,14 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par /* compare the parity */ for (l = 0; l < state->level; ++l) { if (buffer_recov[l] && memcmp(buffer[diskmax + l], buffer_recov[l], state->block_size) != 0) { - msg_tag("parity_error:%u:%s: Data error\n", i, lev_config_name(l)); + log_tag("parity_error:%u:%s: Data error\n", i, lev_config_name(l)); /* it's a silent error only if we are dealing with synced blocks */ if (block_is_unsynced) { ++error; error_on_this_block = 1; } else { - msg_error("Data error in parity '%s' at position '%u'\n", lev_config_name(l), i); + log_fatal("Data error in parity '%s' at position '%u'\n", lev_config_name(l), i); ++silent_error; silent_error_on_this_block = 1; } @@ -486,24 +486,24 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par } if (error) - msg_error("WARNING! Unexpected file errors!\n"); + log_fatal("WARNING! Unexpected file errors!\n"); if (io_error) - msg_error("DANGER! Unexpected input/output errors! The failing blocks are now marked as bad!\n"); + log_fatal("DANGER! Unexpected input/output errors! The failing blocks are now marked as bad!\n"); if (silent_error) - msg_error("DANGER! Unexpected data errors! The failing blocks are now marked as bad!\n"); + log_fatal("DANGER! Unexpected data errors! The failing blocks are now marked as bad!\n"); if (io_error || silent_error) { - msg_error("Use 'snapraid status' to list the bad blocks.\n"); - msg_error("Use 'snapraid -e fix' to recover.\n"); + log_fatal("Use 'snapraid status' to list the bad blocks.\n"); + log_fatal("Use 'snapraid -e fix' to recover.\n"); } - msg_tag("summary:error_file:%u\n", error); - msg_tag("summary:error_io:%u\n", io_error); - msg_tag("summary:error_data:%u\n", silent_error); + log_tag("summary:error_file:%u\n", error); + log_tag("summary:error_io:%u\n", io_error); + log_tag("summary:error_data:%u\n", silent_error); if (error + silent_error + io_error == 0) - msg_tag("summary:exit:ok\n"); + log_tag("summary:exit:ok\n"); else - msg_tag("summary:exit:error\n"); - msg_flush(); + log_tag("summary:exit:error\n"); + log_flush(); bail: for (j = 0; j < diskmax; ++j) { @@ -512,8 +512,8 @@ bail: ret = handle_close(&handle[j]); if (ret == -1) { /* LCOV_EXCL_START */ - msg_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); - msg_error("DANGER! Unexpected close error in a data disk.\n"); + log_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); + log_fatal("DANGER! Unexpected close error in a data disk.\n"); ++error; /* continue, as we are already exiting */ /* LCOV_EXCL_STOP */ @@ -602,7 +602,7 @@ int state_scrub(struct snapraid_state* state, int percentage, int olderthan) /* copy the info in the temp vector */ count = 0; - msg_tag("block_count:%u\n", blockmax); + log_tag("block_count:%u\n", blockmax); for (i = 0; i < blockmax; ++i) { snapraid_info info = info_get(&state->infoarr, i); @@ -615,7 +615,7 @@ int state_scrub(struct snapraid_state* state, int percentage, int olderthan) if (!count) { /* LCOV_EXCL_START */ - msg_error("The array appears to be empty.\n"); + log_fatal("The array appears to be empty.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -625,12 +625,12 @@ int state_scrub(struct snapraid_state* state, int percentage, int olderthan) /* output the info map */ i = 0; - msg_tag("info_count:%u\n", count); + log_tag("info_count:%u\n", count); while (i < count) { unsigned j = i + 1; while (j < count && info_get_time(infomap[i]) == info_get_time(infomap[j])) ++j; - msg_tag("info_time:%" PRIu64 ":%u\n", (uint64_t)info_get_time(infomap[i]), j - i); + log_tag("info_time:%" PRIu64 ":%u\n", (uint64_t)info_get_time(infomap[i]), j - i); i = j; } @@ -658,9 +658,9 @@ int state_scrub(struct snapraid_state* state, int percentage, int olderthan) lastlimit = 0; } - msg_tag("count_limit:%u\n", countlimit); - msg_tag("time_limit:%" PRIu64 "\n", (uint64_t)timelimit); - msg_tag("last_limit:%u\n", lastlimit); + log_tag("count_limit:%u\n", countlimit); + log_tag("time_limit:%" PRIu64 "\n", (uint64_t)timelimit); + log_tag("last_limit:%u\n", lastlimit); /* free the temp vector */ free(infomap); @@ -671,7 +671,7 @@ int state_scrub(struct snapraid_state* state, int percentage, int olderthan) ret = parity_open(parity_ptr[l], state->parity[l].path, state->file_mode); if (ret == -1) { /* LCOV_EXCL_START */ - msg_error("WARNING! Without an accessible %s file, it isn't possible to scrub.\n", lev_name(l)); + log_fatal("WARNING! Without an accessible %s file, it isn't possible to scrub.\n", lev_name(l)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -691,7 +691,7 @@ int state_scrub(struct snapraid_state* state, int percentage, int olderthan) ret = parity_close(parity_ptr[l]); if (ret == -1) { /* LCOV_EXCL_START */ - msg_error("DANGER! Unexpected close error in %s disk.\n", lev_name(l)); + log_fatal("DANGER! Unexpected close error in %s disk.\n", lev_name(l)); ++error; /* continue, as we are already exiting */ /* LCOV_EXCL_STOP */ diff --git a/cmdline/search.c b/cmdline/search.c index 7f0f2142..210cfdd9 100644 --- a/cmdline/search.c +++ b/cmdline/search.c @@ -79,14 +79,14 @@ int search_file_compare(const void* void_arg, const void* void_data) f = open(path, O_RDONLY | O_BINARY); if (f == -1) { /* LCOV_EXCL_START */ - msg_error("Error opening file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error opening file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (lseek(f, arg->offset, SEEK_SET) != arg->offset) { /* LCOV_EXCL_START */ - msg_error("Error seeking file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error seeking file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -94,7 +94,7 @@ int search_file_compare(const void* void_arg, const void* void_data) ret = read(f, arg->buffer, arg->read_size); if (ret < 0 || (unsigned)ret != arg->read_size) { /* LCOV_EXCL_START */ - msg_error("Error reading file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error reading file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -102,7 +102,7 @@ int search_file_compare(const void* void_arg, const void* void_data) ret = close(f); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error closing file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error closing file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -157,7 +157,7 @@ static void search_dir(struct snapraid_state* state, struct snapraid_disk* disk, d = opendir(dir); if (!d) { /* LCOV_EXCL_START */ - msg_error("Error opening directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal("Error opening directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -176,7 +176,7 @@ static void search_dir(struct snapraid_state* state, struct snapraid_disk* disk, dd = readdir(d); if (dd == 0 && errno != 0) { /* LCOV_EXCL_START */ - msg_error("Error reading directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal("Error reading directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -216,7 +216,7 @@ static void search_dir(struct snapraid_state* state, struct snapraid_disk* disk, if (st.st_mode == 0) { if (lstat(path_next, &st) != 0) { /* LCOV_EXCL_START */ - msg_error("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -225,7 +225,7 @@ static void search_dir(struct snapraid_state* state, struct snapraid_disk* disk, /* get lstat info about the file */ if (lstat(path_next, &st) != 0) { /* LCOV_EXCL_START */ - msg_error("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); + log_fatal("Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -250,7 +250,7 @@ static void search_dir(struct snapraid_state* state, struct snapraid_disk* disk, if (closedir(d) != 0) { /* LCOV_EXCL_START */ - msg_error("Error closing directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal("Error closing directory '%s'. %s.\n", dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/selftest.c b/cmdline/selftest.c index 78ca5f2c..1668f482 100644 --- a/cmdline/selftest.c +++ b/cmdline/selftest.c @@ -160,7 +160,7 @@ static void test_hash(void) digest = tommy_hash_u32(seed32, buffer_aligned, TEST_MURMUR3[i].len); if (digest != TEST_HASH32[i].digest) { /* LCOV_EXCL_START */ - msg_error("Failed hash32 test\n"); + log_fatal("Failed hash32 test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -172,7 +172,7 @@ static void test_hash(void) digest = tommy_hash_u64(seed64, buffer_aligned, TEST_MURMUR3[i].len); if (digest != TEST_HASH64[i].digest) { /* LCOV_EXCL_START */ - msg_error("Failed hash64 test\n"); + log_fatal("Failed hash64 test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -185,7 +185,7 @@ static void test_hash(void) memhash(HASH_MURMUR3, seed_aligned, digest, buffer_aligned, TEST_MURMUR3[i].len); if (memcmp(digest, TEST_MURMUR3[i].digest, HASH_SIZE) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed Murmur3 test\n"); + log_fatal("Failed Murmur3 test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -197,7 +197,7 @@ static void test_hash(void) memhash(HASH_SPOOKY2, seed_aligned, digest, buffer_aligned, TEST_SPOOKY2[i].len); if (memcmp(digest, TEST_SPOOKY2[i].digest, HASH_SIZE) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed Spooky2 test\n"); + log_fatal("Failed Spooky2 test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -246,7 +246,7 @@ static void test_crc32c(void) digest = crc32c(0, (const unsigned char*)TEST_CRC32C[i].data, TEST_CRC32C[i].len); if (digest != TEST_CRC32C[i].digest) { /* LCOV_EXCL_START */ - msg_error("Failed CRC32C test\n"); + log_fatal("Failed CRC32C test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -373,22 +373,22 @@ static void test_tommy(void) return; bail: /* LCOV_EXCL_START */ - msg_error("Failed tommy test\n"); + log_fatal("Failed tommy test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } void selftest(void) { - msg_tag("selftest:\n"); - msg_flush(); + log_tag("selftest:\n"); + log_flush(); msg_progress("Self test...\n"); /* large file check */ if (sizeof(off_t) < sizeof(uint64_t)) { /* LCOV_EXCL_START */ - msg_error("Missing support for large files\n"); + log_fatal("Missing support for large files\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -398,55 +398,55 @@ void selftest(void) test_tommy(); if (raid_selftest() != 0) { /* LCOV_EXCL_START */ - msg_error("Failed SELF test\n"); + log_fatal("Failed SELF test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_sort() != 0) { /* LCOV_EXCL_START */ - msg_error("Failed SORT test\n"); + log_fatal("Failed SORT test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_insert() != 0) { /* LCOV_EXCL_START */ - msg_error("Failed INSERT test\n"); + log_fatal("Failed INSERT test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_combo() != 0) { /* LCOV_EXCL_START */ - msg_error("Failed COMBO test\n"); + log_fatal("Failed COMBO test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_par(RAID_MODE_VANDERMONDE, 32, 256) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed GEN Vandermonde test\n"); + log_fatal("Failed GEN Vandermonde test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_rec(RAID_MODE_VANDERMONDE, 12, 256) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed REC Vandermonde test\n"); + log_fatal("Failed REC Vandermonde test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_par(RAID_MODE_CAUCHY, 32, 256) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed GEN Cauchy test\n"); + log_fatal("Failed GEN Cauchy test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_rec(RAID_MODE_CAUCHY, 12, 256) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed REC Cauchy test\n"); + log_fatal("Failed REC Cauchy test\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (raid_test_par(RAID_MODE_CAUCHY, 1, 256) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed GEN Cauchy test sigle data disk\n"); + log_fatal("Failed GEN Cauchy test sigle data disk\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index a9093d5c..b3d86ef1 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -76,13 +76,13 @@ void usage(void) void memory(void) { - msg_tag("memory:used:%" PRIu64 "\n", (uint64_t)malloc_counter()); + log_tag("memory:used:%" PRIu64 "\n", (uint64_t)malloc_counter()); /* size of the block + the size of the blockarr pointer to it */ - msg_tag("memory:block:%" PRIu64 "\n", (uint64_t)(sizeof(struct snapraid_block) + sizeof(void*))); + log_tag("memory:block:%" PRIu64 "\n", (uint64_t)(sizeof(struct snapraid_block) + sizeof(void*))); /* size of the file + the size of the 3 hashtables pointers to it, * 2 for the hashtable grow factor */ - msg_tag("memory:file:%" PRIu64 "\n", (uint64_t)(sizeof(struct snapraid_file) + 3*2*sizeof(void*))); + log_tag("memory:file:%" PRIu64 "\n", (uint64_t)(sizeof(struct snapraid_file) + 3*2*sizeof(void*))); msg_progress("Using %u MiB of memory.\n", (unsigned)(malloc_counter() / (1024 * 1024))); @@ -154,7 +154,7 @@ void log_open(const char* log) break; default : /* LCOV_EXCL_START */ - msg_error("Invalid type specifier '%c' in the log file.\n", *log); + log_fatal("Invalid type specifier '%c' in the log file.\n", *log); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -169,7 +169,7 @@ void log_open(const char* log) stdlog = fopen(path, mode); if (!stdlog) { /* LCOV_EXCL_START */ - msg_error("Error opening the log file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error opening the log file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -180,7 +180,7 @@ void log_close(const char* log) if (stdlog != stdout && stdlog != stderr && stdlog != 0) { if (fclose(stdlog) != 0) { /* LCOV_EXCL_START */ - msg_error("Error closing the log file '%s'. %s.\n", log, strerror(errno)); + log_fatal("Error closing the log file '%s'. %s.\n", log, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -463,7 +463,7 @@ int main(int argc, char* argv[]) struct snapraid_filter* filter = filter_alloc_file(1, optarg); if (!filter) { /* LCOV_EXCL_START */ - msg_error("Invalid filter specification '%s'\n", optarg); + log_fatal("Invalid filter specification '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -473,7 +473,7 @@ int main(int argc, char* argv[]) struct snapraid_filter* filter = filter_alloc_disk(1, optarg); if (!filter) { /* LCOV_EXCL_START */ - msg_error("Invalid filter specification '%s'\n", optarg); + log_fatal("Invalid filter specification '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -494,7 +494,7 @@ int main(int argc, char* argv[]) percentage = strtoul(optarg, &e, 10); if (!e || *e || percentage > 100) { /* LCOV_EXCL_START */ - msg_error("Invalid percentage '%s'\n", optarg); + log_fatal("Invalid percentage '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -503,7 +503,7 @@ int main(int argc, char* argv[]) olderthan = strtoul(optarg, &e, 10); if (!e || *e || olderthan > 1000) { /* LCOV_EXCL_START */ - msg_error("Invalid number of days '%s'\n", optarg); + log_fatal("Invalid number of days '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -512,7 +512,7 @@ int main(int argc, char* argv[]) blockstart = strtoul(optarg, &e, 0); if (!e || *e) { /* LCOV_EXCL_START */ - msg_error("Invalid start position '%s'\n", optarg); + log_fatal("Invalid start position '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -521,7 +521,7 @@ int main(int argc, char* argv[]) blockcount = strtoul(optarg, &e, 0); if (!e || *e) { /* LCOV_EXCL_START */ - msg_error("Invalid count number '%s'\n", optarg); + log_fatal("Invalid count number '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -530,7 +530,7 @@ int main(int argc, char* argv[]) opt.io_error_limit = strtoul(optarg, &e, 0); if (!e || *e) { /* LCOV_EXCL_START */ - msg_error("Invalid error limit number '%s'\n", optarg); + log_fatal("Invalid error limit number '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -538,7 +538,7 @@ int main(int argc, char* argv[]) case 'i' : if (import_timestamp) { /* LCOV_EXCL_START */ - msg_error("Import directory '%s' already specified as '%s'\n", optarg, import_timestamp); + log_fatal("Import directory '%s' already specified as '%s'\n", optarg, import_timestamp); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -547,7 +547,7 @@ int main(int argc, char* argv[]) case OPT_TEST_IMPORT_CONTENT : if (import_content) { /* LCOV_EXCL_START */ - msg_error("Import directory '%s' already specified as '%s'\n", optarg, import_content); + log_fatal("Import directory '%s' already specified as '%s'\n", optarg, import_content); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -556,7 +556,7 @@ int main(int argc, char* argv[]) case 'l' : if (log) { /* LCOV_EXCL_START */ - msg_error("Log file '%s' already specified as '%s'\n", optarg, log); + log_fatal("Log file '%s' already specified as '%s'\n", optarg, log); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -696,7 +696,7 @@ int main(int argc, char* argv[]) break; default : /* LCOV_EXCL_START */ - msg_error("Unknown option '%c'\n", (char)c); + log_fatal("Unknown option '%c'\n", (char)c); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -762,7 +762,7 @@ int main(int argc, char* argv[]) operation = OPERATION_SMART; } else { /* LCOV_EXCL_START */ - msg_error("Unknown command '%s'\n", argv[optind]); + log_fatal("Unknown command '%s'\n", argv[optind]); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -774,7 +774,7 @@ int main(int argc, char* argv[]) default : if (opt.auditonly) { /* LCOV_EXCL_START */ - msg_error("You cannot use -a, --audit-only with the '%s' command\n", command); + log_fatal("You cannot use -a, --audit-only with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -788,7 +788,7 @@ int main(int argc, char* argv[]) default : if (opt.force_nocopy) { /* LCOV_EXCL_START */ - msg_error("You cannot use -N, --force-nocopy with the '%s' command\n", command); + log_fatal("You cannot use -N, --force-nocopy with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -800,14 +800,14 @@ int main(int argc, char* argv[]) default : if (opt.prehash) { /* LCOV_EXCL_START */ - msg_error("You cannot use -h, --pre-hash with the '%s' command\n", command); + log_fatal("You cannot use -h, --pre-hash with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (opt.force_full) { /* LCOV_EXCL_START */ - msg_error("You cannot use -F, --force-full with the '%s' command\n", command); + log_fatal("You cannot use -F, --force-full with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -815,14 +815,14 @@ int main(int argc, char* argv[]) if (opt.force_full && opt.force_nocopy) { /* LCOV_EXCL_START */ - msg_error("You cannot use the -F, --force-full and -N, --force-nocopy options at the same time\n"); + log_fatal("You cannot use the -F, --force-full and -N, --force-nocopy options at the same time\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (opt.prehash && opt.force_nocopy) { /* LCOV_EXCL_START */ - msg_error("You cannot use the -h, --pre-hash and -N, --force-nocopy options at the same time\n"); + log_fatal("You cannot use the -h, --pre-hash and -N, --force-nocopy options at the same time\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -835,25 +835,25 @@ int main(int argc, char* argv[]) default : if (!tommy_list_empty(&filterlist_file)) { /* LCOV_EXCL_START */ - msg_error("You cannot use -f, --filter with the '%s' command\n", command); + log_fatal("You cannot use -f, --filter with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!tommy_list_empty(&filterlist_disk)) { /* LCOV_EXCL_START */ - msg_error("You cannot use -d, --filter-disk with the '%s' command\n", command); + log_fatal("You cannot use -d, --filter-disk with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (filter_missing != 0) { /* LCOV_EXCL_START */ - msg_error("You cannot use -m, --filter-missing with the '%s' command\n", command); + log_fatal("You cannot use -m, --filter-missing with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (filter_error != 0) { /* LCOV_EXCL_START */ - msg_error("You cannot use -e, --filter-error with the '%s' command\n", command); + log_fatal("You cannot use -e, --filter-error with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -866,7 +866,7 @@ int main(int argc, char* argv[]) default : if (import_timestamp != 0 || import_content != 0) { /* LCOV_EXCL_START */ - msg_error("You cannot import with the '%s' command\n", command); + log_fatal("You cannot import with the '%s' command\n", command); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -927,17 +927,17 @@ int main(int argc, char* argv[]) /* print generic info into the log */ t = time(0); tm = localtime(&t); - msg_tag("version:%s\n", PACKAGE_VERSION); - msg_tag("unixtime:%" PRIi64 "\n", (int64_t)t); + log_tag("version:%s\n", PACKAGE_VERSION); + log_tag("unixtime:%" PRIi64 "\n", (int64_t)t); if (tm) { char datetime[64]; strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", tm); - msg_tag("time:%s\n", datetime); + log_tag("time:%s\n", datetime); } - msg_tag("command:%s\n", command); + log_tag("command:%s\n", command); for (i = 0; i < argc; ++i) - msg_tag("argv:%u:%s\n", i, argv[i]); - msg_flush(); + log_tag("argv:%u:%s\n", i, argv[i]); + log_flush(); if (!opt.skip_self) selftest(); @@ -957,10 +957,10 @@ int main(int argc, char* argv[]) if (lock == -1) { /* LCOV_EXCL_START */ if (errno != EWOULDBLOCK) { - msg_error("Error creating the lock file '%s'. %s.\n", state.lockfile, strerror(errno)); + log_fatal("Error creating the lock file '%s'. %s.\n", state.lockfile, strerror(errno)); } else { - msg_error("The lock file '%s' is already locked!\n", state.lockfile); - msg_error("SnapRAID is already in use!\n"); + log_fatal("The lock file '%s' is already locked!\n", state.lockfile); + log_fatal("SnapRAID is already in use!\n"); } exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -1025,7 +1025,7 @@ int main(int argc, char* argv[]) ret = system(run); /* ignore error */ if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error in running command '%s'.\n", run); + log_fatal("Error in running command '%s'.\n", run); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1181,7 +1181,7 @@ int main(int argc, char* argv[]) if (!opt.skip_lock) { if (lock_unlock(lock) == -1) { /* LCOV_EXCL_START */ - msg_error("Error closing the lock file '%s'. %s.\n", state.lockfile, strerror(errno)); + log_fatal("Error closing the lock file '%s'. %s.\n", state.lockfile, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } diff --git a/cmdline/state.c b/cmdline/state.c index a134af97..58c39741 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -183,7 +183,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t if (state->raid_mode == RAID_MODE_VANDERMONDE) { if (state->level > 3) { /* LCOV_EXCL_START */ - msg_error("If you use the z-parity you cannot have more than 3 parities.\n"); + log_fatal("If you use the z-parity you cannot have more than 3 parities.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STIO */ } @@ -192,7 +192,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t for (l = 0; l < state->level; ++l) { if (state->parity[l].path[0] == 0) { /* LCOV_EXCL_START */ - msg_error("No '%s' specification in '%s'\n", lev_config_name(l), path); + log_fatal("No '%s' specification in '%s'\n", lev_config_name(l), path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -200,7 +200,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t if (tommy_list_empty(&state->contentlist)) { /* LCOV_EXCL_START */ - msg_error("No 'content' specification in '%s'\n", path); + log_fatal("No 'content' specification in '%s'\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -212,7 +212,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t for (l = 0; l < state->level; ++l) { if (pathcmp(state->parity[l].path, content->content) == 0) { /* LCOV_EXCL_START */ - msg_error("Same path used for '%s' and 'content' as '%s'\n", lev_config_name(l), content->content); + log_fatal("Same path used for '%s' and 'content' as '%s'\n", lev_config_name(l), content->content); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -228,10 +228,10 @@ static void state_config_check(struct snapraid_state* state, const char* path, t #ifdef _WIN32 if (disk->device == 0) { /* LCOV_EXCL_START */ - msg_error("Disk '%s' has a zero serial number.\n", disk->dir); - msg_error("This is not necessarely wrong, but for using SnapRAID\n"); - msg_error("it's better to change the serial number of the disk.\n"); - msg_error("Try using the 'VolumeID' tool by 'Mark Russinovich'.\n"); + log_fatal("Disk '%s' has a zero serial number.\n", disk->dir); + log_fatal("This is not necessarely wrong, but for using SnapRAID\n"); + log_fatal("it's better to change the serial number of the disk.\n"); + log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -242,15 +242,15 @@ static void state_config_check(struct snapraid_state* state, const char* path, t struct snapraid_disk* other = j->data; if (disk->device == other->device) { /* LCOV_EXCL_START */ - msg_error("Disks '%s' and '%s' are on the same device.\n", disk->dir, other->dir); + log_fatal("Disks '%s' and '%s' are on the same device.\n", disk->dir, other->dir); #ifdef _WIN32 - msg_error("Both have the serial number '%" PRIx64 "'.\n", disk->device); - msg_error("Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); - msg_error("to change one of the disk serial.\n"); + log_fatal("Both have the serial number '%" PRIx64 "'.\n", disk->device); + log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); + log_fatal("to change one of the disk serial.\n"); #endif /* in "fix" we allow to continue anyway */ if (strcmp(state->command, "fix") == 0) { - msg_error("You can '%s' anyway, using 'snapraid --force-device %s'.\n", state->command, state->command); + log_fatal("You can '%s' anyway, using 'snapraid --force-device %s'.\n", state->command, state->command); } exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -262,11 +262,11 @@ static void state_config_check(struct snapraid_state* state, const char* path, t for (l = 0; l < state->level; ++l) { if (disk->device == state->parity[l].device) { /* LCOV_EXCL_START */ - msg_error("Disk '%s' and %s '%s' are on the same device.\n", disk->dir, lev_name(l), state->parity[l].path); + log_fatal("Disk '%s' and %s '%s' are on the same device.\n", disk->dir, lev_name(l), state->parity[l].path); #ifdef _WIN32 - msg_error("Both have the serial number '%" PRIx64 "'.\n", disk->device); - msg_error("Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); - msg_error("to change one of the disk serial.\n"); + log_fatal("Both have the serial number '%" PRIx64 "'.\n", disk->device); + log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); + log_fatal("to change one of the disk serial.\n"); #endif exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -276,11 +276,11 @@ static void state_config_check(struct snapraid_state* state, const char* path, t if (state->pool[0] != 0 && disk->device == state->pool_device) { /* LCOV_EXCL_START */ - msg_error("Disk '%s' and pool '%s' are on the same device.\n", disk->dir, state->pool); + log_fatal("Disk '%s' and pool '%s' are on the same device.\n", disk->dir, state->pool); #ifdef _WIN32 - msg_error("Both have the serial number '%" PRIx64 "'.\n", disk->device); - msg_error("Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); - msg_error("to change one of the disk serial.\n"); + log_fatal("Both have the serial number '%" PRIx64 "'.\n", disk->device); + log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); + log_fatal("to change one of the disk serial.\n"); #endif exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -294,10 +294,10 @@ static void state_config_check(struct snapraid_state* state, const char* path, t for (l = 0; l < state->level; ++l) { if (state->parity[l].device == 0) { /* LCOV_EXCL_START */ - msg_error("Disk '%s' has a zero serial number.\n", state->parity[l].path); - msg_error("This is not necessarely wrong, but for using SnapRAID\n"); - msg_error("it's better to change the serial number of the disk.\n"); - msg_error("Try using the 'VolumeID' tool by 'Mark Russinovich'.\n"); + log_fatal("Disk '%s' has a zero serial number.\n", state->parity[l].path); + log_fatal("This is not necessarely wrong, but for using SnapRAID\n"); + log_fatal("it's better to change the serial number of the disk.\n"); + log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -309,11 +309,11 @@ static void state_config_check(struct snapraid_state* state, const char* path, t for (j = l + 1; j < state->level; ++j) { if (state->parity[l].device == state->parity[j].device) { /* LCOV_EXCL_START */ - msg_error("Parity '%s' and '%s' are on the same device.\n", state->parity[l].path, state->parity[j].path); + log_fatal("Parity '%s' and '%s' are on the same device.\n", state->parity[l].path, state->parity[j].path); #ifdef _WIN32 - msg_error("Both have the serial number '%" PRIx64 "'.\n", state->parity[l].device); - msg_error("Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); - msg_error("to change one of the disk serial.\n"); + log_fatal("Both have the serial number '%" PRIx64 "'.\n", state->parity[l].device); + log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); + log_fatal("to change one of the disk serial.\n"); #endif exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -324,11 +324,11 @@ static void state_config_check(struct snapraid_state* state, const char* path, t for (l = 0; l < state->level; ++l) { if (state->pool[0] != 0 && state->pool_device == state->parity[l].device) { /* LCOV_EXCL_START */ - msg_error("Pool '%s' and parity '%s' are on the same device.\n", state->pool, state->parity[l].path); + log_fatal("Pool '%s' and parity '%s' are on the same device.\n", state->pool, state->parity[l].path); #ifdef _WIN32 - msg_error("Both have the serial number '%" PRIx64 "'.\n", state->pool_device); - msg_error("Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); - msg_error("to change one of the disk serial.\n"); + log_fatal("Both have the serial number '%" PRIx64 "'.\n", state->pool_device); + log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'\n"); + log_fatal("to change one of the disk serial.\n"); #endif exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -341,10 +341,10 @@ static void state_config_check(struct snapraid_state* state, const char* path, t if (!state->opt.skip_device) { if (state->pool[0] != 0 && state->pool_device == 0) { /* LCOV_EXCL_START */ - msg_error("Disk '%s' has a zero serial number.\n", state->pool); - msg_error("This is not necessarely wrong, but for using SnapRAID\n"); - msg_error("it's better to change the serial number of the disk.\n"); - msg_error("Try using the 'VolumeID' tool by 'Mark Russinovich'.\n"); + log_fatal("Disk '%s' has a zero serial number.\n", state->pool); + log_fatal("This is not necessarely wrong, but for using SnapRAID\n"); + log_fatal("it's better to change the serial number of the disk.\n"); + log_fatal("Try using the 'VolumeID' tool by 'Mark Russinovich'.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -377,7 +377,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t if (content_count < state->level + 1) { /* LCOV_EXCL_START */ - msg_error("You must have at least %d 'content' files in different disks.\n", state->level + 1); + log_fatal("You must have at least %d 'content' files in different disks.\n", state->level + 1); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -389,11 +389,11 @@ static void state_config_check(struct snapraid_state* state, const char* path, t #endif if (state->raid_mode == RAID_MODE_CAUCHY) { if (state->level == 3) { - msg_error("WARNING! Your CPU doesn't have a fast implementation for triple parity.\n"); - msg_error("WARNING! It's recommended to switch to 'z-parity' instead than '3-parity'.\n"); + log_fatal("WARNING! Your CPU doesn't have a fast implementation for triple parity.\n"); + log_fatal("WARNING! It's recommended to switch to 'z-parity' instead than '3-parity'.\n"); } else if (state->level > 3) { - msg_error("WARNING! Your CPU doesn't have a fast implementation beyond triple parity.\n"); - msg_error("WARNING! It's recommended to reduce the parity levels to triple parity.\n"); + log_fatal("WARNING! Your CPU doesn't have a fast implementation beyond triple parity.\n"); + log_fatal("WARNING! It's recommended to reduce the parity levels to triple parity.\n"); } } @@ -408,7 +408,7 @@ static void state_config_check(struct snapraid_state* state, const char* path, t } if (j == 0) { /* LCOV_EXCL_START */ - msg_error("Option -d, --filter-disk %s doesn't match any disk.\n", filter->pattern); + log_fatal("Option -d, --filter-disk %s doesn't match any disk.\n", filter->pattern); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -466,17 +466,17 @@ void state_config(struct snapraid_state* state, const char* path, const char* co /* store current command */ state->command = command; - msg_tag("conf:%s\n", path); + log_tag("conf:%s\n", path); f = sopen_read(path); if (!f) { /* LCOV_EXCL_START */ if (errno == ENOENT) { - msg_error("No configuration file found at '%s'\n", path); + log_fatal("No configuration file found at '%s'\n", path); } else if (errno == EACCES) { - msg_error("You do not have rights to access the configuration file '%s'\n", path); + log_fatal("You do not have rights to access the configuration file '%s'\n", path); } else { - msg_error("Error opening the configuration file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error opening the configuration file '%s'. %s.\n", path, strerror(errno)); } exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -497,7 +497,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgettok(f, tag, sizeof(tag)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Error reading the configuration file '%s' at line %u\n", path, line); + log_fatal("Error reading the configuration file '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -512,26 +512,26 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetu32(f, &state->block_size); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'blocksize' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'blocksize' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (state->block_size < 1) { /* LCOV_EXCL_START */ - msg_error("Too small 'blocksize' specification in '%s' at line %u\n", path, line); + log_fatal("Too small 'blocksize' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (state->block_size > 16 * 1024) { /* LCOV_EXCL_START */ - msg_error("Too big 'blocksize' specification in '%s' at line %u\n", path, line); + log_fatal("Too big 'blocksize' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } /* check if it's a power of 2 */ if ((state->block_size & (state->block_size - 1)) != 0) { /* LCOV_EXCL_START */ - msg_error("Not power of 2 'blocksize' specification in '%s' at line %u\n", path, line); + log_fatal("Not power of 2 'blocksize' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -542,7 +542,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (*state->parity[level].path) { /* LCOV_EXCL_START */ - msg_error("Multiple '%s' specification in '%s' at line %u\n", tag, path, line); + log_fatal("Multiple '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -550,14 +550,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetlasttok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid '%s' specification in '%s' at line %u\n", tag, path, line); + log_fatal("Invalid '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - msg_error("Empty '%s' specification in '%s' at line %u\n", tag, path, line); + log_fatal("Empty '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -576,7 +576,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co pathcpy(device, sizeof(device), "."); if (stat(device, &st) != 0) { /* LCOV_EXCL_START */ - msg_error("Error accessing 'parity' dir '%s' specification in '%s' at line %u\n", device, path, line); + log_fatal("Error accessing 'parity' dir '%s' specification in '%s' at line %u\n", device, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -593,7 +593,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co } else if (strcmp(tag, "share") == 0) { if (*state->share) { /* LCOV_EXCL_START */ - msg_error("Multiple 'share' specification in '%s' at line %u\n", path, line); + log_fatal("Multiple 'share' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -601,14 +601,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetlasttok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'share' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'share' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - msg_error("Empty 'share' specification in '%s' at line %u\n", path, line); + log_fatal("Empty 'share' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -619,7 +619,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (*state->pool) { /* LCOV_EXCL_START */ - msg_error("Multiple 'pool' specification in '%s' at line %u\n", path, line); + log_fatal("Multiple 'pool' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -627,14 +627,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetlasttok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'pool' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'pool' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - msg_error("Empty 'pool' specification in '%s' at line %u\n", path, line); + log_fatal("Empty 'pool' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -644,7 +644,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co /* get the device of the directory containing the pool tree */ if (stat(buffer, &st) != 0) { /* LCOV_EXCL_START */ - msg_error("Error accessing 'pool' dir '%s' specification in '%s' at line %u\n", buffer, path, line); + log_fatal("Error accessing 'pool' dir '%s' specification in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -659,21 +659,21 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetlasttok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'content' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'content' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (pathcmp(buffer, "/dev/null") == 0 || pathcmp(buffer, "NUL") == 0) { /* LCOV_EXCL_START */ - msg_error("You cannot use the null device as 'content' specification in '%s' at line %u\n", path, line); + log_fatal("You cannot use the null device as 'content' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - msg_error("Empty 'content' specification in '%s' at line %u\n", path, line); + log_fatal("Empty 'content' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -686,7 +686,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co } if (i) { /* LCOV_EXCL_START */ - msg_error("Duplicate 'content' specification in '%s' at line %u\n", path, line); + log_fatal("Duplicate 'content' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -700,7 +700,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co pathcpy(device, sizeof(device), "."); if (stat(device, &st) != 0) { /* LCOV_EXCL_START */ - msg_error("Error accessing 'content' dir '%s' specification in '%s' at line %u\n", device, path, line); + log_fatal("Error accessing 'content' dir '%s' specification in '%s' at line %u\n", device, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -723,14 +723,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'disk' name specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'disk' name specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - msg_error("Empty 'disk' name specification in '%s' at line %u\n", path, line); + log_fatal("Empty 'disk' name specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -740,14 +740,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetlasttok(f, dir, sizeof(dir)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'disk' dir specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'disk' dir specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*dir) { /* LCOV_EXCL_START */ - msg_error("Empty 'disk' dir specification in '%s' at line %u\n", path, line); + log_fatal("Empty 'disk' dir specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -763,7 +763,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co } if (i) { /* LCOV_EXCL_START */ - msg_error("Duplicate disk name '%s' at line %u\n", buffer, line); + log_fatal("Duplicate disk name '%s' at line %u\n", buffer, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -773,7 +773,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (stat(device, &st) != 0) { /* LCOV_EXCL_START */ - msg_error("Error accessing 'disk' '%s' specification in '%s' at line %u\n", dir, device, line); + log_fatal("Error accessing 'disk' '%s' specification in '%s' at line %u\n", dir, device, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -793,14 +793,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'smartctl' name specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'smartctl' name specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - msg_error("Empty 'smartctl' name specification in '%s' at line %u\n", path, line); + log_fatal("Empty 'smartctl' name specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -810,21 +810,21 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetlasttok(f, custom, sizeof(custom)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'smartctl' option specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'smartctl' option specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*custom) { /* LCOV_EXCL_START */ - msg_error("Empty 'smartctl' option specification in '%s' at line %u\n", path, line); + log_fatal("Empty 'smartctl' option specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (validate_smartctl(custom) != 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'smartctl' option specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'smartctl' option specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -833,7 +833,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (lev_config_scan(buffer, &level, 0) == 0) { if (state->parity[level].smartctl[0] != 0) { /* LCOV_EXCL_START */ - msg_error("Duplicate parity smartctl '%s' at line %u\n", buffer, line); + log_fatal("Duplicate parity smartctl '%s' at line %u\n", buffer, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -849,13 +849,13 @@ void state_config(struct snapraid_state* state, const char* path, const char* co } if (!i) { /* LCOV_EXCL_START */ - msg_error("Missing disk smartctl '%s' at line %u\n", buffer, line); + log_fatal("Missing disk smartctl '%s' at line %u\n", buffer, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (disk->smartctl[0] != 0) { /* LCOV_EXCL_START */ - msg_error("Duplicate disk name '%s' at line %u\n", buffer, line); + log_fatal("Duplicate disk name '%s' at line %u\n", buffer, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -870,14 +870,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetlasttok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'exclude' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'exclude' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - msg_error("Empty 'exclude' specification in '%s' at line %u\n", path, line); + log_fatal("Empty 'exclude' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -885,7 +885,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co filter = filter_alloc_file(-1, buffer); if (!filter) { /* LCOV_EXCL_START */ - msg_error("Invalid 'exclude' specification '%s' in '%s' at line %u\n", buffer, path, line); + log_fatal("Invalid 'exclude' specification '%s' in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -896,14 +896,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetlasttok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'include' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'include' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - msg_error("Empty 'include' specification in '%s' at line %u\n", path, line); + log_fatal("Empty 'include' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -911,7 +911,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co filter = filter_alloc_file(1, buffer); if (!filter) { /* LCOV_EXCL_START */ - msg_error("Invalid 'include' specification '%s' in '%s' at line %u\n", buffer, path, line); + log_fatal("Invalid 'include' specification '%s' in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -922,14 +922,14 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetlasttok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'autosave' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'autosave' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*buffer) { /* LCOV_EXCL_START */ - msg_error("Empty 'autosave' specification in '%s' at line %u\n", path, line); + log_fatal("Empty 'autosave' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -938,7 +938,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (!e || *e) { /* LCOV_EXCL_START */ - msg_error("Invalid 'autosave' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'autosave' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -951,13 +951,13 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ret = sgetline(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid comment in '%s' at line %u\n", path, line); + log_fatal("Invalid comment in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } } else { /* LCOV_EXCL_START */ - msg_error("Invalid command '%s' in '%s' at line %u\n", tag, path, line); + log_fatal("Invalid command '%s' in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -972,7 +972,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co } if (c != '\n') { /* LCOV_EXCL_START */ - msg_error("Extra data in '%s' at line %u\n", path, line); + log_fatal("Extra data in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -981,7 +981,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error reading the configuration file '%s' at line %u\n", path, line); + log_fatal("Error reading the configuration file '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1015,7 +1015,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co /* by default use a random hash seed */ if (randomize(state->hashseed, HASH_SIZE) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed to get random values.\n"); + log_fatal("Failed to get random values.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1025,29 +1025,29 @@ void state_config(struct snapraid_state* state, const char* path, const char* co /* intentionally not set the prevhashseed, if used valgrind will warn about it */ - msg_tag("blocksize:%u\n", state->block_size); + log_tag("blocksize:%u\n", state->block_size); for (i = state->disklist; i != 0; i = i->next) { struct snapraid_disk* disk = i->data; - msg_tag("disk:%s:%s\n", disk->name, disk->dir); + log_tag("disk:%s:%s\n", disk->name, disk->dir); } - msg_tag("mode:%s\n", lev_raid_name(state->raid_mode, state->level)); + log_tag("mode:%s\n", lev_raid_name(state->raid_mode, state->level)); for (l = 0; l < state->level; ++l) - msg_tag("%s:%s\n", lev_config_name(l), state->parity[l].path); + log_tag("%s:%s\n", lev_config_name(l), state->parity[l].path); if (state->pool[0] != 0) - msg_tag("pool:%s\n", state->pool); + log_tag("pool:%s\n", state->pool); if (state->share[0] != 0) - msg_tag("share:%s\n", state->share); + log_tag("share:%s\n", state->share); if (state->autosave != 0) - msg_tag("autosave:%" PRIu64 "\n", state->autosave); + log_tag("autosave:%" PRIu64 "\n", state->autosave); for (i = tommy_list_head(&state->filterlist); i != 0; i = i->next) { char out[PATH_MAX]; struct snapraid_filter* filter = i->data; - msg_tag("filter:%s\n", filter_type(filter, out, sizeof(out))); + log_tag("filter:%s\n", filter_type(filter, out, sizeof(out))); } if (state->filter_hidden) - msg_tag("filter:nohidden:\n"); - msg_flush(); + log_tag("filter:nohidden:\n"); + log_flush(); } /** @@ -1173,7 +1173,7 @@ static void state_map(struct snapraid_state* state) disk = find_disk(state, map->name); if (disk == 0) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency for mapping '%s'\n", map->name); + log_fatal("Internal inconsistency for mapping '%s'\n", map->name); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1194,7 +1194,7 @@ static void state_map(struct snapraid_state* state) if (map->uuid[0] != 0) { /* count the number of uuid change */ ++uuid_mismatch; - msg_error("UUID change for disk '%s' from '%s' to '%s'\n", disk->name, map->uuid, uuid); + log_fatal("UUID change for disk '%s' from '%s' to '%s'\n", disk->name, map->uuid, uuid); } else { /* no message here, because having a disk without */ /* UUID is the normal state of an empty disk */ @@ -1228,7 +1228,7 @@ static void state_map(struct snapraid_state* state) if (state->parity[l].uuid[0] != 0) { /* count the number of uuid change */ ++uuid_mismatch; - msg_error("UUID change for parity '%s' from '%s' to '%s'\n", lev_config_name(l), state->parity[l].uuid, uuid); + log_fatal("UUID change for parity '%s' from '%s' to '%s'\n", lev_config_name(l), state->parity[l].uuid, uuid); } /* update the uuid */ @@ -1242,11 +1242,11 @@ static void state_map(struct snapraid_state* state) if (!state->opt.force_uuid && uuid_mismatch > state->level) { /* LCOV_EXCL_START */ - msg_error("Too many disks have UUID changed from the latest 'sync'.\n"); - msg_error("If this happens because you really replaced them,\n"); - msg_error("you can '%s' anyway, using 'snapraid --force-uuid %s'.\n", state->command, state->command); - msg_error("Instead, it's possible that you messed up the disk mount points,\n"); - msg_error("and you have to restore the mount points at the state of the latest sync.\n"); + log_fatal("Too many disks have UUID changed from the latest 'sync'.\n"); + log_fatal("If this happens because you really replaced them,\n"); + log_fatal("you can '%s' anyway, using 'snapraid --force-uuid %s'.\n", state->command, state->command); + log_fatal("Instead, it's possible that you messed up the disk mount points,\n"); + log_fatal("and you have to restore the mount points at the state of the latest sync.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1263,7 +1263,7 @@ static void state_map(struct snapraid_state* state) /* ensure to don't go over the limit of the RAID engine */ if (diskcount > RAID_DATA_MAX) { /* LCOV_EXCL_START */ - msg_error("Too many data disks. No more than %u.\n", RAID_DATA_MAX); + log_fatal("Too many data disks. No more than %u.\n", RAID_DATA_MAX); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1273,15 +1273,15 @@ static void state_map(struct snapraid_state* state) /* recommend number of parities */ if (diskcount >= 36 && state->level < 6) { - msg_error("WARNING! With %u disks it's recommended to use six parity levels.\n", diskcount); + log_fatal("WARNING! With %u disks it's recommended to use six parity levels.\n", diskcount); } else if (diskcount >= 29 && state->level < 5) { - msg_error("WARNING! With %u disks it's recommended to use five parity levels.\n", diskcount); + log_fatal("WARNING! With %u disks it's recommended to use five parity levels.\n", diskcount); } else if (diskcount >= 22 && state->level < 4) { - msg_error("WARNING! With %u disks it's recommended to use four parity levels.\n", diskcount); + log_fatal("WARNING! With %u disks it's recommended to use four parity levels.\n", diskcount); } else if (diskcount >= 15 && state->level < 3) { - msg_error("WARNING! With %u disks it's recommended to use three parity levels.\n", diskcount); + log_fatal("WARNING! With %u disks it's recommended to use three parity levels.\n", diskcount); } else if (diskcount >= 5 && state->level < 2) { - msg_error("WARNING! With %u disks it's recommended to use two parity levels.\n", diskcount); + log_fatal("WARNING! With %u disks it's recommended to use two parity levels.\n", diskcount); } } @@ -1301,7 +1301,7 @@ void state_refresh(struct snapraid_state* state) disk = find_disk(state, map->name); if (disk == 0) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency for mapping '%s'\n", map->name); + log_fatal("Internal inconsistency for mapping '%s'\n", map->name); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1309,7 +1309,7 @@ void state_refresh(struct snapraid_state* state) ret = fsinfo(disk->dir, 0, &total_space, &free_space); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error accessing disk '%s' to get filesystem info. %s.\n", disk->dir, strerror(errno)); + log_fatal("Error accessing disk '%s' to get filesystem info. %s.\n", disk->dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1332,7 +1332,7 @@ void state_refresh(struct snapraid_state* state) ret = fsinfo(state->parity[l].path, 0, &total_space, &free_space); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error accessing file '%s' to get filesystem info. %s.\n", state->parity[l].path, strerror(errno)); + log_fatal("Error accessing file '%s' to get filesystem info. %s.\n", state->parity[l].path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1361,13 +1361,13 @@ static void state_content_check(struct snapraid_state* state, const char* path) struct snapraid_map* other = j->data; if (strcmp(map->name, other->name) == 0) { /* LCOV_EXCL_START */ - msg_error("Colliding 'map' disk specification in '%s'\n", path); + log_fatal("Colliding 'map' disk specification in '%s'\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (map->position == other->position) { /* LCOV_EXCL_START */ - msg_error("Colliding 'map' index specification in '%s'\n", path); + log_fatal("Colliding 'map' index specification in '%s'\n", path); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1486,7 +1486,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, tag, sizeof(tag)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Error reading the configuration file '%s' at line %u\n", path, line); + log_fatal("Error reading the configuration file '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1506,7 +1506,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE if (!file) { /* LCOV_EXCL_START */ - msg_error("Unexpected '%s' specification in '%s' at line %u\n", tag, path, line); + log_fatal("Unexpected '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1514,14 +1514,14 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &v_pos); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid '%s' specification in '%s' at line %u\n", tag, path, line); + log_fatal("Invalid '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (blockidx >= file->blockmax) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in '%s' specification in '%s' at line %u\n", tag, path, line); + log_fatal("Internal inconsistency in '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1530,7 +1530,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE if (block->parity_pos != POS_INVALID) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in '%s' specification in '%s' at line %u\n", tag, path, line); + log_fatal("Internal inconsistency in '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1563,7 +1563,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - msg_error("Invalid '%s' specification in '%s' at line %u\n", tag, path, line); + log_fatal("Invalid '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1571,7 +1571,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgethex(f, block->hash, HASH_SIZE); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid '%s' specification in '%s' at line %u\n", tag, path, line); + log_fatal("Invalid '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1616,7 +1616,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE /* we must not overwrite existing blocks */ if (disk_block_get(disk, v_pos) != BLOCK_EMPTY) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency for '%s' specification in '%s' at line %u\n", tag, path, line); + log_fatal("Internal inconsistency for '%s' specification in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1642,14 +1642,14 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &v_pos); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'inf' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'inf' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (v_pos >= blockmax) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in position for 'inf' specification in '%s' at line %u\n", path, line); + log_fatal("Internal inconsistency in position for 'inf' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1657,7 +1657,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - msg_error("Invalid 'inf' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'inf' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1665,7 +1665,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &t); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'inf' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'inf' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1678,7 +1678,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'inf' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'inf' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1690,13 +1690,13 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE if (state->prevhash == HASH_UNDEFINED) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency for missing previous checksum in '%s' at line %u\n", path, line); + log_fatal("Internal inconsistency for missing previous checksum in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } } else { /* LCOV_EXCL_START */ - msg_error("Invalid 'inf' specification '%s' in '%s' at line %u\n", buffer, path, line); + log_fatal("Invalid 'inf' specification '%s' in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1716,7 +1716,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE if (!disk) { /* LCOV_EXCL_START */ - msg_error("Unexpected 'off' specification in '%s' at line %u\n", path, line); + log_fatal("Unexpected 'off' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1727,7 +1727,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &v_pos); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'off' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'off' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1738,7 +1738,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - msg_error("Invalid 'off' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'off' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1747,7 +1747,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgethex(f, deleted->block.hash, HASH_SIZE); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'off' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'off' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1761,7 +1761,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE /* we must not overwrite existing blocks */ if (disk_block_get(disk, v_pos) != BLOCK_EMPTY) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency for 'off' specification in '%s' at line %u\n", path, line); + log_fatal("Internal inconsistency for 'off' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1782,7 +1782,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE if (file) { /* LCOV_EXCL_START */ - msg_error("Missing 'blk' specification in '%s' at line %u\n", path, line); + log_fatal("Missing 'blk' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1790,7 +1790,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'file' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1798,7 +1798,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - msg_error("Invalid 'file' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1806,7 +1806,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu64(f, &v_size); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'file' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1814,7 +1814,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - msg_error("Invalid 'file' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1822,7 +1822,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu64(f, &v_mtime_sec); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'file' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1832,7 +1832,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &v_mtime_nsec); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'file' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1845,7 +1845,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE if (c != ' ') { /* LCOV_EXCL_START */ - msg_error("Invalid 'file' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1853,7 +1853,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu64(f, &v_inode); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'file' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1861,7 +1861,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - msg_error("Invalid 'file' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1869,14 +1869,14 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetline(f, sub, sizeof(sub)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'file' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*sub) { /* LCOV_EXCL_START */ - msg_error("Invalid 'file' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'file' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1885,7 +1885,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE disk = find_disk(state, buffer); if (!disk) { /* LCOV_EXCL_START */ - msg_error("Disk named '%s' not found in '%s' at line %u\n", buffer, path, line); + log_fatal("Disk named '%s' not found in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1915,7 +1915,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE if (file) { /* LCOV_EXCL_START */ - msg_error("Missing 'blk' specification in '%s' at line %u\n", path, line); + log_fatal("Missing 'blk' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1923,7 +1923,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'hole' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'hole' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1932,7 +1932,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE disk = find_disk(state, buffer); if (!disk) { /* LCOV_EXCL_START */ - msg_error("Disk named '%s' not found in '%s' at line %u\n", buffer, path, line); + log_fatal("Disk named '%s' not found in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1946,7 +1946,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'symlink' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'symlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1954,7 +1954,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - msg_error("Invalid 'symlink' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'symlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1962,7 +1962,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetline(f, sub, sizeof(sub)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'symlink' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'symlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1970,7 +1970,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgeteol(f); if (c != '\n') { /* LCOV_EXCL_START */ - msg_error("Invalid 'symlink' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'symlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1979,13 +1979,13 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, tokento, sizeof(tokento)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'symlink' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'symlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (strcmp(tokento, "to") != 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'symlink' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'symlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1993,7 +1993,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - msg_error("Invalid 'symlink' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'symlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2001,14 +2001,14 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetline(f, linkto, sizeof(linkto)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'symlink' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'symlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*sub || !*linkto) { /* LCOV_EXCL_START */ - msg_error("Invalid 'symlink' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'symlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2017,7 +2017,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE disk = find_disk(state, buffer); if (!disk) { /* LCOV_EXCL_START */ - msg_error("Disk named '%s' not found in '%s' at line %u\n", buffer, path, line); + log_fatal("Disk named '%s' not found in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2041,7 +2041,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2049,7 +2049,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - msg_error("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2057,7 +2057,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetline(f, sub, sizeof(sub)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2065,7 +2065,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgeteol(f); if (c != '\n') { /* LCOV_EXCL_START */ - msg_error("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2074,13 +2074,13 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, tokento, sizeof(tokento)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (strcmp(tokento, "to") != 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2088,7 +2088,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - msg_error("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2096,14 +2096,14 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetline(f, linkto, sizeof(linkto)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*sub || !*linkto) { /* LCOV_EXCL_START */ - msg_error("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'hardlink' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2112,7 +2112,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE disk = find_disk(state, buffer); if (!disk) { /* LCOV_EXCL_START */ - msg_error("Disk named '%s' not found in '%s' at line %u\n", buffer, path, line); + log_fatal("Disk named '%s' not found in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2134,7 +2134,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'dir' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'dir' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2142,7 +2142,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - msg_error("Invalid 'dir' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'dir' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2150,14 +2150,14 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetline(f, sub, sizeof(sub)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'dir' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'dir' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!*sub) { /* LCOV_EXCL_START */ - msg_error("Invalid 'dir' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'dir' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2166,7 +2166,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE disk = find_disk(state, buffer); if (!disk) { /* LCOV_EXCL_START */ - msg_error("Disk named '%s' not found in '%s' at line %u\n", buffer, path, line); + log_fatal("Disk named '%s' not found in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2185,7 +2185,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'checksum' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'checksum' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2196,7 +2196,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE state->hash = HASH_SPOOKY2; } else { /* LCOV_EXCL_START */ - msg_error("Invalid 'checksum' specification '%s' in '%s' at line %u\n", buffer, path, line); + log_fatal("Invalid 'checksum' specification '%s' in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2207,7 +2207,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgethex(f, state->hashseed, HASH_SIZE); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'seed' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'seed' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2220,7 +2220,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'prevchecksum' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'prevchecksum' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2231,7 +2231,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE state->prevhash = HASH_SPOOKY2; } else { /* LCOV_EXCL_START */ - msg_error("Invalid 'prevchecksum' specification '%s' in '%s' at line %u\n", buffer, path, line); + log_fatal("Invalid 'prevchecksum' specification '%s' in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2239,7 +2239,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - msg_error("Invalid 'prevchecksum' specification '%s' in '%s' at line %u\n", buffer, path, line); + log_fatal("Invalid 'prevchecksum' specification '%s' in '%s' at line %u\n", buffer, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2248,7 +2248,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgethex(f, state->prevhashseed, HASH_SIZE); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'seed' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'seed' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2258,7 +2258,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &blksize); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'blksize' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'blksize' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2270,8 +2270,8 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE if (blksize != state->block_size) { /* LCOV_EXCL_START */ - msg_error("Mismatching 'blksize' and 'blocksize' specification in '%s' at line %u\n", path, line); - msg_error("Please restore the 'blocksize' value in the configuration file to '%u'\n", blksize / 1024); + log_fatal("Mismatching 'blksize' and 'blocksize' specification in '%s' at line %u\n", path, line); + log_fatal("Please restore the 'blocksize' value in the configuration file to '%u'\n", blksize / 1024); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2285,7 +2285,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'map' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'map' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2293,7 +2293,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - msg_error("Invalid 'map' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'map' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2301,7 +2301,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &v_pos); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'map' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'map' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2311,7 +2311,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - msg_error("Invalid 'map' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'map' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2319,7 +2319,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &v_total_blocks); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'map' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'map' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2327,7 +2327,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - msg_error("Invalid 'map' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'map' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2335,7 +2335,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &v_free_blocks); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'map' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'map' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2355,7 +2355,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, uuid, sizeof(uuid)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'map' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'map' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2374,7 +2374,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &v_level); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'parity' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'parity' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2382,7 +2382,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - msg_error("Invalid 'parity' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'parity' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2390,7 +2390,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &v_total_blocks); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'parity' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'parity' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2398,7 +2398,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE c = sgetc(f); if (c != ' ') { /* LCOV_EXCL_START */ - msg_error("Invalid 'parity' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'parity' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2406,7 +2406,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &v_free_blocks); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'parity' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'parity' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2422,7 +2422,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgettok(f, uuid, sizeof(uuid)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'map' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'map' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2445,7 +2445,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetu32(f, &sign); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid 'sign' specification in '%s' at line %u\n", path, line); + log_fatal("Invalid 'sign' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2458,13 +2458,13 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE ret = sgetline(f, buffer, sizeof(buffer)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Invalid comment in '%s' at line %u\n", path, line); + log_fatal("Invalid comment in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } } else { /* LCOV_EXCL_START */ - msg_error("Invalid command '%s' in '%s' at line %u\n", tag, path, line); + log_fatal("Invalid command '%s' in '%s' at line %u\n", tag, path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2476,7 +2476,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE } if (c != '\n') { /* LCOV_EXCL_START */ - msg_error("Extra data in '%s' at line %u\n", path, line); + log_fatal("Extra data in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2485,14 +2485,14 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error reading the content file '%s' at line %u\n", path, line); + log_fatal("Error reading the content file '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (file) { /* LCOV_EXCL_START */ - msg_error("Missing 'blk' specification in '%s' at line %u\n", path, line); + log_fatal("Missing 'blk' specification in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2500,7 +2500,7 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE /* check that the stored parity size matches the loaded state */ if (blockmax != parity_allocated_size(state)) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in parity size in '%s' at line %u\n", path, line); + log_fatal("Internal inconsistency in parity size in '%s' at line %u\n", path, line); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2578,7 +2578,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2589,7 +2589,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputsl("checksum spooky2", f); } else { /* LCOV_EXCL_START */ - msg_error("Unexpected hash when writing the content file '%s'.\n", serrorfile(f)); + log_fatal("Unexpected hash when writing the content file '%s'.\n", serrorfile(f)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2598,7 +2598,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2613,7 +2613,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputsl("prevchecksum spooky2", f); } else { /* LCOV_EXCL_START */ - msg_error("Unexpected prevhash when writing the content file '%s'.\n", serrorfile(f)); + log_fatal("Unexpected prevhash when writing the content file '%s'.\n", serrorfile(f)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2622,7 +2622,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2638,7 +2638,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) disk = find_disk(state, map->name); if (!disk) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency for unmapped disk '%s'\n", map->name); + log_fatal("Internal inconsistency for unmapped disk '%s'\n", map->name); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2663,7 +2663,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2694,7 +2694,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2739,7 +2739,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2752,7 +2752,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) /* consistency check */ if (block != disk_block_get(disk, block->parity_pos)) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency mismatch for block %u state %u in file '%s'\n", block->parity_pos, block_state, file->sub); + log_fatal("Internal inconsistency mismatch for block %u state %u in file '%s'\n", block->parity_pos, block_state, file->sub); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2769,7 +2769,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) break; default : /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in state for block %u state %u\n", block->parity_pos, block_state); + log_fatal("Internal inconsistency in state for block %u state %u\n", block->parity_pos, block_state); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2782,7 +2782,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2815,7 +2815,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2832,7 +2832,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2846,7 +2846,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2857,7 +2857,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) /* consistency check */ if (block->parity_pos != b) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in delete position %u/%u!\n", block->parity_pos, b); + log_fatal("Internal inconsistency in delete position %u/%u!\n", block->parity_pos, b); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2869,7 +2869,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2897,7 +2897,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) sputeol(f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2906,7 +2906,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f) if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2929,20 +2929,20 @@ static void decoding_error(const char* path, STREAM* f) if (seof(f)) { /* LCOV_EXCL_START */ - msg_error("Unexpected end of content file '%s' at offset %" PRIi64 "\n", path, stell(f)); - msg_error("This content file is truncated. Use an alternate copy.\n"); + log_fatal("Unexpected end of content file '%s' at offset %" PRIi64 "\n", path, stell(f)); + log_fatal("This content file is truncated. Use an alternate copy.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error reading the content file '%s' at offset %" PRIi64 "\n", path, stell(f)); + log_fatal("Error reading the content file '%s' at offset %" PRIi64 "\n", path, stell(f)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } - msg_error("Decoding error in '%s' at offset %" PRIi64 "\n", path, stell(f)); + log_fatal("Decoding error in '%s' at offset %" PRIi64 "\n", path, stell(f)); buf[0] = 0; buf[1] = 0; @@ -2965,7 +2965,7 @@ static void decoding_error(const char* path, STREAM* f) if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error flushing the content file '%s' at offset %" PRIi64 "\n", path, stell(f)); + log_fatal("Error flushing the content file '%s' at offset %" PRIi64 "\n", path, stell(f)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -2980,11 +2980,11 @@ static void decoding_error(const char* path, STREAM* f) crc_stored = crc32c(crc_stored, buf, 4); if (crc_computed != crc_stored) { - msg_error("Mismatching CRC in '%s'\n", path); - msg_error("This content file is damaged! Use an alternate copy.\n"); + log_fatal("Mismatching CRC in '%s'\n", path); + log_fatal("This content file is damaged! Use an alternate copy.\n"); exit(EXIT_FAILURE); } else { - msg_error("The file CRC is correct!\n"); + log_fatal("The file CRC is correct!\n"); } } @@ -3014,7 +3014,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (ret < 0) { /* LCOV_EXCL_START */ decoding_error(path, f); - msg_error("Invalid header!\n"); + log_fatal("Invalid header!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3031,9 +3031,9 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST /* LCOV_EXCL_START */ if (memcmp(buffer, "SNAPCNT", 7) != 0) { decoding_error(path, f); - msg_error("Invalid header!\n"); + log_fatal("Invalid header!\n"); } else { - msg_error("The content file '%s' was generated with a newer version of SnapRAID!\n", path); + log_fatal("The content file '%s' was generated with a newer version of SnapRAID!\n", path); } exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -3064,7 +3064,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (ret < 0 || mapping >= mapping_max) { /* LCOV_EXCL_START */ decoding_error(path, f); - msg_error("Internal inconsistency in mapping index!\n"); + log_fatal("Internal inconsistency in mapping index!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3082,7 +3082,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (v_size / state->block_size > blockmax) { /* LCOV_EXCL_START */ decoding_error(path, f); - msg_error("Internal inconsistency in file size too big!\n"); + log_fatal("Internal inconsistency in file size too big!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3168,14 +3168,14 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (v_idx + v_count > file->blockmax) { /* LCOV_EXCL_START */ decoding_error(path, f); - msg_error("Internal inconsistency in block number!\n"); + log_fatal("Internal inconsistency in block number!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (v_pos + v_count > blockmax) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in block size %u/%u!\n", blockmax, v_pos + v_count); + log_fatal("Internal inconsistency in block size %u/%u!\n", blockmax, v_pos + v_count); decoding_error(path, f); exit(EXIT_FAILURE); /* LCOV_EXCL_START */ @@ -3191,7 +3191,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (block->parity_pos != POS_INVALID) { /* LCOV_EXCL_START */ decoding_error(path, f); - msg_error("Internal inconsistency in block position!\n"); + log_fatal("Internal inconsistency in block position!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3213,7 +3213,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST default : /* LCOV_EXCL_START */ decoding_error(path, f); - msg_error("Invalid block type!\n"); + log_fatal("Invalid block type!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3271,7 +3271,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (disk_block_get(disk, v_pos) != BLOCK_EMPTY) { /* LCOV_EXCL_START */ decoding_error(path, f); - msg_error("Internal inconsistency in block existence!\n"); + log_fatal("Internal inconsistency in block existence!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3320,7 +3320,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (v_pos + v_count > blockmax) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in info size %u/%u!\n", blockmax, v_pos + v_count); + log_fatal("Internal inconsistency in info size %u/%u!\n", blockmax, v_pos + v_count); decoding_error(path, f); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -3352,7 +3352,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (rehash && state->prevhash == HASH_UNDEFINED) { /* LCOV_EXCL_START */ decoding_error(path, f); - msg_error("Internal inconsistency for missing previous checksum!\n"); + log_fatal("Internal inconsistency for missing previous checksum!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3371,7 +3371,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (!info) { /* LCOV_EXCL_START */ decoding_error(path, f); - msg_error("Internal inconsistency for missing info!\n"); + log_fatal("Internal inconsistency for missing info!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3395,7 +3395,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (ret < 0 || mapping >= mapping_max) { /* LCOV_EXCL_START */ decoding_error(path, f); - msg_error("Internal inconsistency in mapping index!\n"); + log_fatal("Internal inconsistency in mapping index!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3415,7 +3415,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (v_pos + v_count > blockmax) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in hole size %u/%u!\n", blockmax, v_pos + v_count); + log_fatal("Internal inconsistency in hole size %u/%u!\n", blockmax, v_pos + v_count); decoding_error(path, f); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -3457,9 +3457,9 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST /* we must not overwrite existing blocks */ if (disk_block_get(disk, v_pos) != BLOCK_EMPTY) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency for used hole at pos %u!\n", v_pos); + log_fatal("Internal inconsistency for used hole at pos %u!\n", v_pos); if (state->opt.skip_content_check) { - msg_error("Overriding as used.\n"); + log_fatal("Overriding as used.\n"); deleted_free(deleted); } else { decoding_error(path, f); @@ -3486,7 +3486,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST default : /* LCOV_EXCL_START */ decoding_error(path, f); - msg_error("Invalid hole type!\n"); + log_fatal("Invalid hole type!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3503,7 +3503,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (ret < 0 || mapping >= mapping_max) { /* LCOV_EXCL_START */ decoding_error(path, f); - msg_error("Internal inconsistency in mapping index!\n"); + log_fatal("Internal inconsistency in mapping index!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3553,7 +3553,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (ret < 0 || mapping >= mapping_max) { /* LCOV_EXCL_START */ decoding_error(path, f); - msg_error("Internal inconsistency in mapping index!\n"); + log_fatal("Internal inconsistency in mapping index!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3602,7 +3602,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (ret < 0 || mapping >= mapping_max) { /* LCOV_EXCL_START */ decoding_error(path, f); - msg_error("Internal inconsistency in mapping index!\n"); + log_fatal("Internal inconsistency in mapping index!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3646,7 +3646,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST default : /* LCOV_EXCL_START */ decoding_error(path, f); - msg_error("Invalid checksum!\n"); + log_fatal("Invalid checksum!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3673,7 +3673,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST default : /* LCOV_EXCL_START */ decoding_error(path, f); - msg_error("Invalid checksum!\n"); + log_fatal("Invalid checksum!\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3705,8 +3705,8 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (blksize != state->block_size) { /* LCOV_EXCL_START */ decoding_error(path, f); - msg_error("Mismatching 'blksize' and 'blocksize' specification!\n"); - msg_error("Please restore the 'blocksize' value in the configuration file to '%u'\n", blksize / 1024); + log_fatal("Mismatching 'blksize' and 'blocksize' specification!\n"); + log_fatal("Please restore the 'blocksize' value in the configuration file to '%u'\n", blksize / 1024); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3782,8 +3782,8 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (!disk) { /* LCOV_EXCL_START */ decoding_error(path, f); - msg_error("Disk named '%s' not present in the configuration file!\n", buffer); - msg_error("If you have removed it from the configuration file, please restore it\n"); + log_fatal("Disk named '%s' not present in the configuration file!\n", buffer); + log_fatal("If you have removed it from the configuration file, please restore it\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3853,8 +3853,8 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (ret < 0) { /* LCOV_EXCL_START */ /* here don't call decoding_error() because it's too late to get the crc */ - msg_error("Error reading the CRC in '%s' at offset %" PRIi64 "\n", path, stell(f)); - msg_error("This content file is damaged! Use an alternate copy.\n"); + log_fatal("Error reading the CRC in '%s' at offset %" PRIi64 "\n", path, stell(f)); + log_fatal("This content file is damaged! Use an alternate copy.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3862,8 +3862,8 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (crc_stored != crc_computed) { /* LCOV_EXCL_START */ /* here don't call decoding_error() because it's too late to get the crc */ - msg_error("Mismatching CRC in '%s'\n", path); - msg_error("This content file is damaged! Use an alternate copy.\n"); + log_fatal("Mismatching CRC in '%s'\n", path); + log_fatal("This content file is damaged! Use an alternate copy.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3872,7 +3872,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST } else { /* LCOV_EXCL_START */ decoding_error(path, f); - msg_error("Invalid command '%c'!\n", (char)c); + log_fatal("Invalid command '%c'!\n", (char)c); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3882,15 +3882,15 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error reading the content file '%s' at offset %" PRIi64 "\n", path, stell(f)); + log_fatal("Error reading the content file '%s' at offset %" PRIi64 "\n", path, stell(f)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (!crc_checked) { /* LCOV_EXCL_START */ - msg_error("Finished reading '%s' without finding the CRC\n", path); - msg_error("This content file is truncated or damaged! Use an alternate copy.\n"); + log_fatal("Finished reading '%s' without finding the CRC\n", path); + log_fatal("This content file is truncated or damaged! Use an alternate copy.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3898,9 +3898,9 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST /* check that the stored parity size matches the loaded state */ if (blockmax != parity_allocated_size(state)) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in parity size %u/%u in '%s' at offset %" PRIi64 "\n", blockmax, parity_allocated_size(state), path, stell(f)); + log_fatal("Internal inconsistency in parity size %u/%u in '%s' at offset %" PRIi64 "\n", blockmax, parity_allocated_size(state), path, stell(f)); if (state->opt.skip_content_check) { - msg_error("Overriding.\n"); + log_fatal("Overriding.\n"); blockmax = parity_allocated_size(state); } else { exit(EXIT_FAILURE); @@ -3976,7 +3976,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputb32(blockmax, f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -3988,14 +3988,14 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputc('k', f); } else { /* LCOV_EXCL_START */ - msg_error("Unexpected hash when writing the content file '%s'.\n", serrorfile(f)); + log_fatal("Unexpected hash when writing the content file '%s'.\n", serrorfile(f)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } swrite(state->hashseed, HASH_SIZE, f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4011,14 +4011,14 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputc('k', f); } else { /* LCOV_EXCL_START */ - msg_error("Unexpected prevhash when writing the content file '%s'.\n", serrorfile(f)); + log_fatal("Unexpected prevhash when writing the content file '%s'.\n", serrorfile(f)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } swrite(state->prevhashseed, HASH_SIZE, f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4035,7 +4035,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) disk = find_disk(state, map->name); if (!disk) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency for unmapped disk '%s'\n", map->name); + log_fatal("Internal inconsistency for unmapped disk '%s'\n", map->name); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4050,7 +4050,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputbs(map->uuid, f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4073,7 +4073,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputbs(state->parity[l].uuid, f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4115,7 +4115,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputbs(file->sub, f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4150,7 +4150,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) break; default : /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in state for block %u state %u\n", v_pos, block_state); + log_fatal("Internal inconsistency in state for block %u state %u\n", v_pos, block_state); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4167,7 +4167,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) /* consistency check */ if (block != disk_block_get(disk, block->parity_pos)) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in mismatch for block %u state %u in file '%s'\n", block->parity_pos, block_state, file->sub); + log_fatal("Internal inconsistency in mismatch for block %u state %u in file '%s'\n", block->parity_pos, block_state, file->sub); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4177,7 +4177,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4209,7 +4209,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputbs(link->linkto, f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4224,7 +4224,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputbs(dir->sub, f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4237,7 +4237,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputb32(disk->mapping_idx, f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4269,7 +4269,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) /* consistency check */ if (block->parity_pos != begin) { /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in delete position %u/%u!\n", block->parity_pos, begin); + log_fatal("Internal inconsistency in delete position %u/%u!\n", block->parity_pos, begin); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4289,7 +4289,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4337,7 +4337,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4351,7 +4351,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) /* flush data written to the disk */ if (sflush(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s' (in flush before crc). %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s' (in flush before crc). %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4363,9 +4363,9 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) /* with the one of the data written to the stream */ if (crc != scrc_stream(f)) { /* LCOV_EXCL_START */ - msg_error("CRC mismatch writing the content stream.\n"); - msg_error("DANGER! Your RAM memory is broken! DO NOT PROCEED UNTIL FIXED!\n"); - msg_error("Try running a memory test like http://www.memtest86.com/\n"); + log_fatal("CRC mismatch writing the content stream.\n"); + log_fatal("DANGER! Your RAM memory is broken! DO NOT PROCEED UNTIL FIXED!\n"); + log_fatal("Try running a memory test like http://www.memtest86.com/\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4373,7 +4373,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f) sputble32(crc, f); if (serror(f)) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s'. %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4401,8 +4401,8 @@ void state_read(struct snapraid_state* state) pathcpy(path, sizeof(path), content->content); if (!state->no_conf) { - msg_tag("content:%s\n", path); - msg_flush(); + log_tag("content:%s\n", path); + log_flush(); } msg_progress("Loading state from %s...\n", path); @@ -4414,14 +4414,14 @@ void state_read(struct snapraid_state* state) /* if it's real error of an existing file, abort */ if (errno != ENOENT) { /* LCOV_EXCL_START */ - msg_error("Error opening the content file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error opening the content file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } /* otherwise continue */ if (node->next) { - msg_error("WARNING! Content file '%s' not found, trying with another copy...\n", path); + log_fatal("WARNING! Content file '%s' not found, trying with another copy...\n", path); /* ensure to rewrite all the content files */ state->need_write = 1; @@ -4434,7 +4434,7 @@ void state_read(struct snapraid_state* state) /* if not found, assume empty */ if (!f) { - msg_error("No content file found. Assuming empty.\n"); + log_fatal("No content file found. Assuming empty.\n"); /* create the initial mapping */ state_map(state); @@ -4445,7 +4445,7 @@ void state_read(struct snapraid_state* state) ret = fstat(shandle(f), &st); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Error stating the content file '%s'. %s.\n", path, strerror(errno)); + log_fatal("Error stating the content file '%s'. %s.\n", path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4462,7 +4462,7 @@ void state_read(struct snapraid_state* state) /* allow missing content files, but not any other kind of error */ if (errno != ENOENT) { /* LCOV_EXCL_START */ - msg_error("Error stating the content file '%s'. %s.\n", other_path, strerror(errno)); + log_fatal("Error stating the content file '%s'. %s.\n", other_path, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4472,8 +4472,8 @@ void state_read(struct snapraid_state* state) } else { /* if the size is different */ if (other_st.st_size != st.st_size) { - msg_error("WARNING! Content files '%s' and '%s' have a different size!\n", path, other_path); - msg_error("Likely one of the two is broken!\n"); + log_fatal("WARNING! Content files '%s' and '%s' have a different size!\n", path, other_path); + log_fatal("Likely one of the two is broken!\n"); /* ensure to rewrite all the content files */ state->need_write = 1; @@ -4514,10 +4514,10 @@ void state_read(struct snapraid_state* state) if (state->hash == HASH_UNDEFINED) { /* LCOV_EXCL_START */ - msg_error("The checksum to use is not specified.\n"); - msg_error("This happens because you are likely upgrading from SnapRAID 1.0.\n"); - msg_error("To use a new SnapRAID you must restart from scratch,\n"); - msg_error("deleting all the content and parity files.\n"); + log_fatal("The checksum to use is not specified.\n"); + log_fatal("This happens because you are likely upgrading from SnapRAID 1.0.\n"); + log_fatal("To use a new SnapRAID you must restart from scratch,\n"); + log_fatal("deleting all the content and parity files.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4552,7 +4552,7 @@ void state_write(struct snapraid_state* state) f = sopen_multi_write(count_content); if (!f) { /* LCOV_EXCL_START */ - msg_error("Error opening the content files.\n"); + log_fatal("Error opening the content files.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4565,7 +4565,7 @@ void state_write(struct snapraid_state* state) pathprint(tmp, sizeof(tmp), "%s.tmp", content->content); if (sopen_multi_file(f, k, tmp) != 0) { /* LCOV_EXCL_START */ - msg_error("Error opening the content file '%s'. %s.\n", tmp, strerror(errno)); + log_fatal("Error opening the content file '%s'. %s.\n", tmp, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4583,7 +4583,7 @@ void state_write(struct snapraid_state* state) if (sflush(f) != 0) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s', in flush(). %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s', in flush(). %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4591,7 +4591,7 @@ void state_write(struct snapraid_state* state) #if HAVE_FSYNC if (ssync(f) != 0) { /* LCOV_EXCL_START */ - msg_error("Error writing the content file '%s' in sync(). %s.\n", serrorfile(f), strerror(errno)); + log_fatal("Error writing the content file '%s' in sync(). %s.\n", serrorfile(f), strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4599,7 +4599,7 @@ void state_write(struct snapraid_state* state) if (sclose(f) != 0) { /* LCOV_EXCL_START */ - msg_error("Error closing the content files in close(). %s.\n", strerror(errno)); + log_fatal("Error closing the content files in close(). %s.\n", strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4613,7 +4613,7 @@ void state_write(struct snapraid_state* state) pathprint(tmp, sizeof(tmp), "%s.tmp", content->content); if (rename(tmp, content->content) != 0) { /* LCOV_EXCL_START */ - msg_error("Error renaming the content file '%s' to '%s' in rename(). %s.\n", tmp, content->content, strerror(errno)); + log_fatal("Error renaming the content file '%s' to '%s' in rename(). %s.\n", tmp, content->content, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -4701,8 +4701,8 @@ int state_progress_begin(struct snapraid_state* state, block_off_t blockstart, b time_t now; if (state->opt.gui) { - msg_tag("run:begin:%u:%u:%u\n", blockstart, blockmax, countmax); - msg_flush(); + log_tag("run:begin:%u:%u:%u\n", blockstart, blockmax, countmax); + log_flush(); } now = time(0); @@ -4719,8 +4719,8 @@ int state_progress_begin(struct snapraid_state* state, block_off_t blockstart, b if (!state->opt.gui) { msg_status("Not starting for interruption\n"); } - msg_tag("sigint:0: SIGINT received\n"); - msg_flush(); + log_tag("sigint:0: SIGINT received\n"); + log_flush(); return 0; /* LCOV_EXCL_STOP */ } @@ -4731,8 +4731,8 @@ int state_progress_begin(struct snapraid_state* state, block_off_t blockstart, b void state_progress_end(struct snapraid_state* state, block_off_t countpos, block_off_t countmax, data_off_t countsize) { if (state->opt.gui) { - msg_tag("run:end\n"); - msg_flush(); + log_tag("run:end\n"); + log_flush(); } else if (countmax == 0) { msg_status("Nothing to do\n"); } else { @@ -4867,8 +4867,8 @@ int state_progress(struct snapraid_state* state, block_off_t blockpos, block_off } if (state->opt.gui) { - msg_tag("run:pos:%u:%u:%" PRIu64 ":%u:%u:%u:%u:%" PRIu64 "\n", blockpos, countpos, countsize, out_perc, out_eta, out_speed, out_cpu, (uint64_t)elapsed); - msg_flush(); + log_tag("run:pos:%u:%u:%" PRIu64 ":%u:%u:%u:%u:%" PRIu64 "\n", blockpos, countpos, countsize, out_perc, out_eta, out_speed, out_cpu, (uint64_t)elapsed); + log_flush(); } else { msg_bar("%u%%, %u MiB", out_perc, (unsigned)(countsize / MEGA)); if (out_speed) @@ -4901,11 +4901,11 @@ int state_progress(struct snapraid_state* state, block_off_t blockpos, block_off if (global_interrupt) { /* LCOV_EXCL_START */ if (!state->opt.gui) { - msg_error("\n"); - msg_error("Stopping for interruption at block %u\n", blockpos); + log_fatal("\n"); + log_fatal("Stopping for interruption at block %u\n", blockpos); } - msg_tag("sigint:%u: SIGINT received\n", blockpos); - msg_flush(); + log_tag("sigint:%u: SIGINT received\n", blockpos); + log_flush(); return 1; /* LCOV_EXCL_STOP */ } diff --git a/cmdline/status.c b/cmdline/status.c index 88250f96..3637bc39 100644 --- a/cmdline/status.c +++ b/cmdline/status.c @@ -81,20 +81,20 @@ int state_status(struct snapraid_state* state) blockmax = parity_allocated_size(state); - msg_tag("summary:block_size:%u\n", state->block_size); - msg_tag("summary:parity_block_count:%u\n", blockmax); + log_tag("summary:block_size:%u\n", state->block_size); + log_tag("summary:parity_block_count:%u\n", blockmax); /* get the minimum parity free space */ parity_block_free = state->parity[0].free_blocks; for (l = 0; l < state->level; ++l) { - msg_tag("summary:parity_block_total:%s:%u\n", lev_config_name(l), state->parity[l].total_blocks); - msg_tag("summary:parity_block_free:%s:%u\n", lev_config_name(l), state->parity[l].free_blocks); + log_tag("summary:parity_block_total:%s:%u\n", lev_config_name(l), state->parity[l].total_blocks); + log_tag("summary:parity_block_free:%s:%u\n", lev_config_name(l), state->parity[l].free_blocks); if (state->parity[l].free_blocks < parity_block_free) parity_block_free = state->parity[l].free_blocks; if (state->parity[l].free_blocks != 0) free_not_zero = 1; } - msg_tag("summary:parity_block_free_min:%u\n", parity_block_free); + log_tag("summary:parity_block_free_min:%u\n", parity_block_free); printf("SnapRAID status report:\n"); printf("\n"); @@ -216,18 +216,18 @@ int state_status(struct snapraid_state* state) } printf(" %s\n", disk->name); - msg_tag("summary:disk_file_count:%s:%u\n", disk->name, disk_file_count); - msg_tag("summary:disk_block_count:%s:%u\n", disk->name, disk_block_count); - msg_tag("summary:disk_fragmented_file_count:%s:%u\n", disk->name, disk_file_fragmented); - msg_tag("summary:disk_excess_fragment_count:%s:%u\n", disk->name, disk_extra_fragment); - msg_tag("summary:disk_file_size:%s:%" PRIu64 "\n", disk->name, disk_file_size); - msg_tag("summary:disk_block_allocated:%s:%u\n", disk->name, disk_block_latest_used + 1); - msg_tag("summary:disk_block_total:%s:%u\n", disk->name, disk->total_blocks); - msg_tag("summary:disk_block_free:%s:%u\n", disk->name, disk->free_blocks); - msg_tag("summary:disk_block_max_by_space:%s:%u\n", disk->name, disk_block_max_by_space); - msg_tag("summary:disk_block_max_by_parity:%s:%u\n", disk->name, disk_block_max_by_parity); - msg_tag("summary:disk_block_max:%s:%u\n", disk->name, disk_block_max); - msg_tag("summary:disk_space_wasted:%s:%" PRId64 "\n", disk->name, wasted); + log_tag("summary:disk_file_count:%s:%u\n", disk->name, disk_file_count); + log_tag("summary:disk_block_count:%s:%u\n", disk->name, disk_block_count); + log_tag("summary:disk_fragmented_file_count:%s:%u\n", disk->name, disk_file_fragmented); + log_tag("summary:disk_excess_fragment_count:%s:%u\n", disk->name, disk_extra_fragment); + log_tag("summary:disk_file_size:%s:%" PRIu64 "\n", disk->name, disk_file_size); + log_tag("summary:disk_block_allocated:%s:%u\n", disk->name, disk_block_latest_used + 1); + log_tag("summary:disk_block_total:%s:%u\n", disk->name, disk->total_blocks); + log_tag("summary:disk_block_free:%s:%u\n", disk->name, disk->free_blocks); + log_tag("summary:disk_block_max_by_space:%s:%u\n", disk->name, disk_block_max_by_space); + log_tag("summary:disk_block_max_by_parity:%s:%u\n", disk->name, disk_block_max_by_parity); + log_tag("summary:disk_block_max:%s:%u\n", disk->name, disk_block_max); + log_tag("summary:disk_space_wasted:%s:%" PRId64 "\n", disk->name, wasted); } /* totals */ @@ -245,17 +245,17 @@ int state_status(struct snapraid_state* state) if (!free_not_zero) printf("\nWARNING! Free space info will be valid after the first sync.\n"); - msg_tag("summary:file_count:%u\n", file_count); - msg_tag("summary:file_block_count:%" PRIu64 "\n", file_block_count); - msg_tag("summary:fragmented_file_count:%u\n", file_fragmented); - msg_tag("summary:excess_fragment_count:%u\n", extra_fragment); - msg_tag("summary:file_size:%" PRIu64 "\n", file_size); - msg_tag("summary:parity_size:%" PRIu64 "\n", blockmax * (uint64_t)state->block_size); - msg_tag("summary:parity_size_max:%" PRIu64 "\n", (blockmax + parity_block_free) * (uint64_t)state->block_size); - msg_tag("summary:hash:%s\n", hash_config_name(state->hash)); - msg_tag("summary:prev_hash:%s\n", hash_config_name(state->prevhash)); - msg_tag("summary:best_hash:%s\n", hash_config_name(state->besthash)); - msg_flush(); + log_tag("summary:file_count:%u\n", file_count); + log_tag("summary:file_block_count:%" PRIu64 "\n", file_block_count); + log_tag("summary:fragmented_file_count:%u\n", file_fragmented); + log_tag("summary:excess_fragment_count:%u\n", extra_fragment); + log_tag("summary:file_size:%" PRIu64 "\n", file_size); + log_tag("summary:parity_size:%" PRIu64 "\n", blockmax * (uint64_t)state->block_size); + log_tag("summary:parity_size_max:%" PRIu64 "\n", (blockmax + parity_block_free) * (uint64_t)state->block_size); + log_tag("summary:hash:%s\n", hash_config_name(state->hash)); + log_tag("summary:prev_hash:%s\n", hash_config_name(state->prevhash)); + log_tag("summary:best_hash:%s\n", hash_config_name(state->besthash)); + log_flush(); /* copy the info a temp vector, and count bad/rehash/unsynced blocks */ infomap = malloc_nofail(blockmax * sizeof(snapraid_info)); @@ -265,7 +265,7 @@ int state_status(struct snapraid_state* state) count = 0; rehash = 0; unsynced_blocks = 0; - msg_tag("block_count:%u\n", blockmax); + log_tag("block_count:%u\n", blockmax); for (i = 0; i < blockmax; ++i) { int one_invalid; int one_valid; @@ -307,19 +307,19 @@ int state_status(struct snapraid_state* state) if (state->opt.gui) { if (info != 0) - msg_tag("block:%u:%" PRIu64 ":%s:%s:%s:%s\n", i, (uint64_t)info_get_time(info), one_valid ? "used" : "", one_invalid ? "unsynced" : "", info_get_bad(info) ? "bad" : "", info_get_rehash(info) ? "rehash" : ""); + log_tag("block:%u:%" PRIu64 ":%s:%s:%s:%s\n", i, (uint64_t)info_get_time(info), one_valid ? "used" : "", one_invalid ? "unsynced" : "", info_get_bad(info) ? "bad" : "", info_get_rehash(info) ? "rehash" : ""); else - msg_tag("block_noinfo:%u:%s:%s\n", i, one_valid ? "used" : "", one_invalid ? "unsynced" : ""); + log_tag("block_noinfo:%u:%s:%s\n", i, one_valid ? "used" : "", one_invalid ? "unsynced" : ""); } } - msg_tag("summary:has_unsynced:%u\n", unsynced_blocks); - msg_tag("summary:has_rehash:%u\n", rehash); - msg_tag("summary:has_bad:%u:%u:%u\n", bad, bad_first, bad_last); - msg_flush(); + log_tag("summary:has_unsynced:%u\n", unsynced_blocks); + log_tag("summary:has_rehash:%u\n", rehash); + log_tag("summary:has_bad:%u:%u:%u\n", bad, bad_first, bad_last); + log_flush(); if (!count) { - msg_error("The array is empty.\n"); + log_fatal("The array is empty.\n"); free(infomap); return 0; } @@ -329,12 +329,12 @@ int state_status(struct snapraid_state* state) /* output the info map */ i = 0; - msg_tag("info_count:%u\n", count); + log_tag("info_count:%u\n", count); while (i < count) { unsigned j = i + 1; while (j < count && info_get_time(infomap[i]) == info_get_time(infomap[j])) ++j; - msg_tag("info_time:%" PRIu64 ":%u\n", (uint64_t)info_get_time(infomap[i]), j - i); + log_tag("info_time:%" PRIu64 ":%u\n", (uint64_t)info_get_time(infomap[i]), j - i); i = j; } diff --git a/cmdline/support.c b/cmdline/support.c index ba1aef91..95e1933e 100644 --- a/cmdline/support.c +++ b/cmdline/support.c @@ -50,11 +50,11 @@ static pthread_mutex_t msg_lock = PTHREAD_MUTEX_INITIALIZER; * The buffering is similar at the "line buffered" one, that * is not available on Windows, so we emulate it in this way. * - * For stdlog the flush is only limited. - * To ensure flushing the caller should use msg_flush(). + * For stdlog flushing is limited. To ensure flushing the + * caller should use log_flush(). */ -void msg_error(const char* format, ...) +void log_fatal(const char* format, ...) { va_list ap; @@ -62,7 +62,7 @@ void msg_error(const char* format, ...) if (stdlog) { va_start(ap, format); - fprintf(stdlog, "msg:error: "); + fprintf(stdlog, "msg:fatal: "); vfprintf(stdlog, format, ap); fflush(stdlog); va_end(ap); @@ -76,7 +76,7 @@ void msg_error(const char* format, ...) pthread_mutex_unlock(&msg_lock); } -void msg_warning(const char* format, ...) +void log_error(const char* format, ...) { va_list ap; @@ -84,7 +84,7 @@ void msg_warning(const char* format, ...) if (stdlog) { va_start(ap, format); - fprintf(stdlog, "msg:warning: "); + fprintf(stdlog, "msg:error: "); vfprintf(stdlog, format, ap); fflush(stdlog); va_end(ap); @@ -98,7 +98,7 @@ void msg_warning(const char* format, ...) pthread_mutex_unlock(&msg_lock); } -void msg_expected(const char* format, ...) +void log_expected(const char* format, ...) { va_list ap; @@ -106,7 +106,7 @@ void msg_expected(const char* format, ...) if (stdlog) { va_start(ap, format); - fprintf(stdlog, "msg:warning: "); + fprintf(stdlog, "msg:expected: "); vfprintf(stdlog, format, ap); fflush(stdlog); va_end(ap); @@ -115,7 +115,7 @@ void msg_expected(const char* format, ...) pthread_mutex_unlock(&msg_lock); } -void msg_tag(const char* format, ...) +void log_tag(const char* format, ...) { va_list ap; @@ -124,12 +124,26 @@ void msg_tag(const char* format, ...) if (stdlog) { va_start(ap, format); vfprintf(stdlog, format, ap); + /* here we intentionally don't flush */ + /* to make the output faster */ va_end(ap); } pthread_mutex_unlock(&msg_lock); } +void log_flush(void) +{ + pthread_mutex_lock(&msg_lock); + + if (stdlog) + fflush(stdlog); + fflush(stdout); + fflush(stderr); + + pthread_mutex_unlock(&msg_lock); +} + void msg_status(const char* format, ...) { va_list ap; @@ -244,8 +258,6 @@ void msg_flush(void) { pthread_mutex_lock(&msg_lock); - if (stdlog) - fflush(stdlog); fflush(stdout); fflush(stderr); @@ -316,7 +328,7 @@ const char* esc(const char* str) bail: /* LCOV_EXCL_START */ - msg_error("Escape too long\n"); + log_fatal("Escape too long\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -343,7 +355,7 @@ void pathcpy(char* dst, size_t size, const char* src) if (len + 1 > size) { /* LCOV_EXCL_START */ - msg_error("Path too long\n"); + log_fatal("Path too long\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -358,7 +370,7 @@ void pathcat(char* dst, size_t size, const char* src) if (dst_len + src_len + 1 > size) { /* LCOV_EXCL_START */ - msg_error("Path too long\n"); + log_fatal("Path too long\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -372,7 +384,7 @@ void pathcatc(char* dst, size_t size, char c) if (dst_len + 2 > size) { /* LCOV_EXCL_START */ - msg_error("Path too long\n"); + log_fatal("Path too long\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -420,7 +432,7 @@ void pathprint(char* dst, size_t size, const char* format, ...) if (len >= size) { /* LCOV_EXCL_START */ - msg_error("Path too long\n"); + log_fatal("Path too long\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -433,7 +445,7 @@ void pathslash(char* dst, size_t size) if (len > 0 && dst[len - 1] != '/') { if (len + 2 >= size) { /* LCOV_EXCL_START */ - msg_error("Path too long\n"); + log_fatal("Path too long\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -528,7 +540,7 @@ int mkancestor(const char* file) /* create it */ if (mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) != 0) { /* LCOV_EXCL_START */ - msg_error("Error creating directory '%s'. %s.\n", dir, strerror(errno)); + log_fatal("Error creating directory '%s'. %s.\n", dir, strerror(errno)); return -1; /* LCOV_EXCL_STOP */ } @@ -760,7 +772,7 @@ int smartctl_attribute(FILE* f, const char* file, const char* name, uint64_t* sm /* remove extraneous chars */ s = polish(buf); - msg_tag("smartctl:%s:%s:out: %s\n", file, name, s); + log_tag("smartctl:%s:%s:out: %s\n", file, name, s); /* skip initial spaces */ while (isspace(*s)) @@ -789,14 +801,14 @@ int smartctl_attribute(FILE* f, const char* file, const char* name, uint64_t* sm } else if (inside) { if (sscanf(s, "%u %*s %*s %*s %*s %*s %*s %*s %*s %" SCNu64, &id, &raw) != 2) { /* LCOV_EXCL_START */ - msg_error("Invalid smartctl line '%s'.\n", s); + log_fatal("Invalid smartctl line '%s'.\n", s); return -1; /* LCOV_EXCL_STOP */ } if (id >= 256) { /* LCOV_EXCL_START */ - msg_error("Invalid SMART id '%u'.\n", id); + log_fatal("Invalid SMART id '%u'.\n", id); return -1; /* LCOV_EXCL_STOP */ } @@ -822,7 +834,7 @@ int smartctl_flush(FILE* f, const char* file, const char* name) /* remove extraneous chars */ s = polish(buf); - msg_tag("smartctl:%s:%s:out: %s\n", file, name, s); + log_tag("smartctl:%s:%s:out: %s\n", file, name, s); } return 0; diff --git a/cmdline/support.h b/cmdline/support.h index 58a14a78..ac6013f7 100644 --- a/cmdline/support.h +++ b/cmdline/support.h @@ -22,32 +22,37 @@ /* log */ /** - * Fatal messages. + * Fatal error messages. * * Messages printed before an early termination. * * These messages go in the log file and in stderr inconditionally. */ -void msg_error(const char* format, ...) __attribute__((format(attribute_printf, 1, 2))); +void log_fatal(const char* format, ...) __attribute__((format(attribute_printf, 1, 2))); /** - * Warning messages. + * Unexpected error messages. * - * Messages reporting warnings or error conditions that don't prevent the program to run. + * Messages reporting error conditions that don't prevent the program to run. * * Some of them could be also serious errors, like "silent errors". - * The summary results is anyway always printed with as errors. + * In such case, the summary result is always printed as error, + * and we are sure to notify the user in some way. * * These messages go in the log file if specified, otherwise they go in stderr. */ -void msg_warning(const char* format, ...) __attribute__((format(attribute_printf, 1, 2))); +void log_error(const char* format, ...) __attribute__((format(attribute_printf, 1, 2))); /** - * Warning messages, without fallback to stderr. + * Expected error messages, without fallback to stderr. + * + * These errors are "someway" expected, and then they never go to screen. + * For example, when undeleting missing files, the messages for missing files + * are not shown. * * These messages go in the log file if specified, otherwise they are lost. */ -void msg_expected(const char* format, ...) __attribute__((format(attribute_printf, 1, 2))); +void log_expected(const char* format, ...) __attribute__((format(attribute_printf, 1, 2))); /** * Tag messages. @@ -60,13 +65,26 @@ void msg_expected(const char* format, ...) __attribute__((format(attribute_print * * These messages are buffered. Use msg_flush() to flush them. */ -void msg_tag(const char* format, ...) __attribute__((format(attribute_printf, 1, 2))); +void log_tag(const char* format, ...) __attribute__((format(attribute_printf, 1, 2))); + +/** + * Flush the log. + */ +void log_flush(void); + +/** + * Pointer to log function. + */ +typedef void fptr(const char* format, ...); + +/****************************************************************************/ +/* message */ /** * Message levels. * * The levels control the amount of information printed on the screen. - * Note that msg_error(), msg_warning() and msg_tag() are not influenced by this option. + * Note that log_fatal(), log_error(), log_expected() and log_tag() are not affected by this option. * * From the most quiet to the most verbose. */ @@ -96,7 +114,7 @@ void msg_status(const char* format, ...) __attribute__((format(attribute_printf, * Potentially a lot of messages are possible. They can still be on the screen, * as losing them we don't lose information. * - * These messages never go in the log file, becauae there is always a corresponding msg_tag(). + * These messages never go in the log file, becauae there is always a corresponding log_tag(). */ void msg_info(const char* format, ...) __attribute__((format(attribute_printf, 1, 2))); @@ -134,10 +152,8 @@ void msg_verbose(const char* format, ...) __attribute__((format(attribute_printf */ void msg_flush(void); -/** - * Pointer to log function. - */ -typedef void fptr(const char* format, ...); +/****************************************************************************/ +/* escape */ /** * Escape a string. diff --git a/cmdline/sync.c b/cmdline/sync.c index 2476b5bb..0a48b2d0 100644 --- a/cmdline/sync.c +++ b/cmdline/sync.c @@ -132,44 +132,44 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta /* This one is really an unexpected error, because we are only reading */ /* and closing a descriptor should never fail */ if (errno == EIO) { - msg_tag("error:%u:%s:%s: Close EIO error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); - msg_error("DANGER! Unexpected input/output close error in a data disk, it isn't possible to sync.\n"); - msg_error("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); - msg_error("Stopping at block %u\n", i); + log_tag("error:%u:%s:%s: Close EIO error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); + log_fatal("DANGER! Unexpected input/output close error in a data disk, it isn't possible to sync.\n"); + log_fatal("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); + log_fatal("Stopping at block %u\n", i); ++io_error; goto bail; } - msg_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); - msg_error("WARNING! Unexpected close error in a data disk, it isn't possible to sync.\n"); - msg_error("Ensure that file '%s' can be accessed.\n", handle[j].path); - msg_error("Stopping at block %u\n", i); + log_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); + log_fatal("WARNING! Unexpected close error in a data disk, it isn't possible to sync.\n"); + log_fatal("Ensure that file '%s' can be accessed.\n", handle[j].path); + log_fatal("Stopping at block %u\n", i); ++error; goto bail; /* LCOV_EXCL_STOP */ } } - ret = handle_open(&handle[j], block_file_get(block), state->file_mode, msg_warning, 0); + ret = handle_open(&handle[j], block_file_get(block), state->file_mode, log_error, 0); if (ret == -1) { /* file we have tried to open for error reporting */ struct snapraid_file* file = block_file_get(block); if (errno == EIO) { /* LCOV_EXCL_START */ - msg_tag("error:%u:%s:%s: Open EIO error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); - msg_error("DANGER! Unexpected input/output open error in a data disk, it isn't possible to sync.\n"); - msg_error("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); - msg_error("Stopping at block %u\n", i); + log_tag("error:%u:%s:%s: Open EIO error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); + log_fatal("DANGER! Unexpected input/output open error in a data disk, it isn't possible to sync.\n"); + log_fatal("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); + log_fatal("Stopping at block %u\n", i); ++io_error; goto bail; /* LCOV_EXCL_STOP */ } if (errno == ENOENT) { - msg_tag("error:%u:%s:%s: Open ENOENT error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); - msg_warning("Missing file '%s'.\n", handle[j].path); - msg_warning("WARNING! You cannot modify data disk during a sync.\n"); - msg_warning("Rerun the sync command when finished.\n"); + log_tag("error:%u:%s:%s: Open ENOENT error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); + log_error("Missing file '%s'.\n", handle[j].path); + log_error("WARNING! You cannot modify data disk during a sync.\n"); + log_error("Rerun the sync command when finished.\n"); ++error; /* if the file is missing, it means that it was removed during sync */ /* this isn't a serious error, so we skip this block, and continue with others */ @@ -177,20 +177,20 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta } if (errno == EACCES) { - msg_tag("error:%u:%s:%s: Open EACCES error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); - msg_warning("No access at file '%s'.\n", handle[j].path); - msg_warning("WARNING! Please fix the access permission in the data disk.\n"); - msg_warning("Rerun the sync command when finished.\n"); + log_tag("error:%u:%s:%s: Open EACCES error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); + log_error("No access at file '%s'.\n", handle[j].path); + log_error("WARNING! Please fix the access permission in the data disk.\n"); + log_error("Rerun the sync command when finished.\n"); ++error; /* this isn't a serious error, so we skip this block, and continue with others */ continue; } /* LCOV_EXCL_START */ - msg_tag("error:%u:%s:%s: Open error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); - msg_error("WARNING! Unexpected open error in a data disk, it isn't possible to sync.\n"); - msg_error("Ensure that file '%s' can be accessed.\n", handle[j].path); - msg_error("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub); + log_tag("error:%u:%s:%s: Open error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); + log_fatal("WARNING! Unexpected open error in a data disk, it isn't possible to sync.\n"); + log_fatal("Ensure that file '%s' can be accessed.\n", handle[j].path); + log_fatal("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub); ++error; goto bail; /* LCOV_EXCL_STOP */ @@ -204,41 +204,41 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta ) { /* file we are processing for error reporting */ struct snapraid_file* file = block_file_get(block); - msg_tag("error:%u:%s:%s: Unexpected attribute change\n", i, disk->name, esc(file->sub)); + log_tag("error:%u:%s:%s: Unexpected attribute change\n", i, disk->name, esc(file->sub)); if (handle[j].st.st_size != file->size) { - msg_warning("Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle[j].path, file->size, handle[j].st.st_size); + log_error("Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle[j].path, file->size, handle[j].st.st_size); } else if (handle[j].st.st_mtime != file->mtime_sec || STAT_NSEC(&handle[j].st) != file->mtime_nsec) { - msg_warning("Unexpected time change at file '%s' from %" PRIu64 ".%d to %" PRIu64 ".%d.\n", handle[j].path, file->mtime_sec, file->mtime_nsec, (uint64_t)handle[j].st.st_mtime, (uint32_t)STAT_NSEC(&handle[j].st)); + log_error("Unexpected time change at file '%s' from %" PRIu64 ".%d to %" PRIu64 ".%d.\n", handle[j].path, file->mtime_sec, file->mtime_nsec, (uint64_t)handle[j].st.st_mtime, (uint32_t)STAT_NSEC(&handle[j].st)); } else { - msg_warning("Unexpected inode change from %" PRIu64 " to %" PRIu64 " at file '%s'.\n", file->inode, (uint64_t)handle[j].st.st_ino, handle[j].path); + log_error("Unexpected inode change from %" PRIu64 " to %" PRIu64 " at file '%s'.\n", file->inode, (uint64_t)handle[j].st.st_ino, handle[j].path); } - msg_warning("WARNING! You cannot modify files during a sync.\n"); - msg_warning("Rerun the sync command when finished.\n"); + log_error("WARNING! You cannot modify files during a sync.\n"); + log_error("Rerun the sync command when finished.\n"); ++error; /* if the file is changed, it means that it was modified during sync */ /* this isn't a serious error, so we skip this block, and continue with others */ continue; } - read_size = handle_read(&handle[j], block, buffer, state->block_size, msg_error, 0); + read_size = handle_read(&handle[j], block, buffer, state->block_size, log_fatal, 0); if (read_size == -1) { /* LCOV_EXCL_START */ /* file we are processing for error reporting */ struct snapraid_file* file = block_file_get(block); if (errno == EIO) { - msg_tag("error:%u:%s:%s: Read EIO error at position %u. %s\n", i, disk->name, esc(file->sub), block_file_pos(block), strerror(errno)); - msg_error("DANGER! Unexpected input/output read error in a data disk, it isn't possible to sync.\n"); - msg_error("Ensure that disk '%s' is sane and that file '%s' can be read.\n", disk->dir, handle[j].path); - msg_error("Stopping at block %u\n", i); + log_tag("error:%u:%s:%s: Read EIO error at position %u. %s\n", i, disk->name, esc(file->sub), block_file_pos(block), strerror(errno)); + log_fatal("DANGER! Unexpected input/output read error in a data disk, it isn't possible to sync.\n"); + log_fatal("Ensure that disk '%s' is sane and that file '%s' can be read.\n", disk->dir, handle[j].path); + log_fatal("Stopping at block %u\n", i); ++io_error; goto bail; } - msg_tag("error:%u:%s:%s: Read error at position %u. %s\n", i, disk->name, esc(file->sub), block_file_pos(block), strerror(errno)); - msg_error("WARNING! Unexpected read error in a data disk, it isn't possible to sync.\n"); - msg_error("Ensure that file '%s' can be read.\n", handle[j].path); - msg_error("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub); + log_tag("error:%u:%s:%s: Read error at position %u. %s\n", i, disk->name, esc(file->sub), block_file_pos(block), strerror(errno)); + log_fatal("WARNING! Unexpected read error in a data disk, it isn't possible to sync.\n"); + log_fatal("Ensure that file '%s' can be read.\n", handle[j].path); + log_fatal("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub); ++error; goto bail; /* LCOV_EXCL_STOP */ @@ -287,18 +287,18 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta /* This one is really an unexpected error, because we are only reading */ /* and closing a descriptor should never fail */ if (errno == EIO) { - msg_tag("error:%u:%s:%s: Close EIO error. %s\n", blockmax, disk->name, esc(file->sub), strerror(errno)); - msg_error("DANGER! Unexpected input/output close error in a data disk, it isn't possible to sync.\n"); - msg_error("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); - msg_error("Stopping at block %u\n", blockmax); + log_tag("error:%u:%s:%s: Close EIO error. %s\n", blockmax, disk->name, esc(file->sub), strerror(errno)); + log_fatal("DANGER! Unexpected input/output close error in a data disk, it isn't possible to sync.\n"); + log_fatal("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); + log_fatal("Stopping at block %u\n", blockmax); ++io_error; goto bail; } - msg_tag("error:%u:%s:%s: Close error. %s\n", blockmax, disk->name, esc(file->sub), strerror(errno)); - msg_error("WARNING! Unexpected close error in a data disk, it isn't possible to sync.\n"); - msg_error("Ensure that file '%s' can be accessed.\n", handle[j].path); - msg_error("Stopping at block %u\n", blockmax); + log_tag("error:%u:%s:%s: Close error. %s\n", blockmax, disk->name, esc(file->sub), strerror(errno)); + log_fatal("WARNING! Unexpected close error in a data disk, it isn't possible to sync.\n"); + log_fatal("Ensure that file '%s' can be accessed.\n", handle[j].path); + log_fatal("Stopping at block %u\n", blockmax); ++error; goto bail; /* LCOV_EXCL_STOP */ @@ -323,9 +323,9 @@ end: } if (error) - msg_error("WARNING! Unexpected file errors!\n"); + log_fatal("WARNING! Unexpected file errors!\n"); - msg_tag("hash_summary:error_file:%u\n", error); + log_tag("hash_summary:error_file:%u\n", error); /* proceed without bailing out */ goto finish; @@ -340,8 +340,8 @@ bail: struct snapraid_disk* disk = handle[j].disk; ret = handle_close(&handle[j]); if (ret == -1) { - msg_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); - msg_error("DANGER! Unexpected close error in a data disk.\n"); + log_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); + log_fatal("DANGER! Unexpected close error in a data disk.\n"); ++error; /* continue, as we are already exiting */ } @@ -606,44 +606,44 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari /* This one is really an unexpected error, because we are only reading */ /* and closing a descriptor should never fail */ if (errno == EIO) { - msg_tag("error:%u:%s:%s: Close EIO error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); - msg_error("DANGER! Unexpected input/output close error in a data disk, it isn't possible to sync.\n"); - msg_error("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); - msg_error("Stopping at block %u\n", i); + log_tag("error:%u:%s:%s: Close EIO error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); + log_fatal("DANGER! Unexpected input/output close error in a data disk, it isn't possible to sync.\n"); + log_fatal("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); + log_fatal("Stopping at block %u\n", i); ++io_error; goto bail; } - msg_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); - msg_error("WARNING! Unexpected close error in a data disk, it isn't possible to sync.\n"); - msg_error("Ensure that file '%s' can be accessed.\n", handle[j].path); - msg_error("Stopping at block %u\n", i); + log_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); + log_fatal("WARNING! Unexpected close error in a data disk, it isn't possible to sync.\n"); + log_fatal("Ensure that file '%s' can be accessed.\n", handle[j].path); + log_fatal("Stopping at block %u\n", i); ++error; goto bail; /* LCOV_EXCL_STOP */ } } - ret = handle_open(&handle[j], block_file_get(block), state->file_mode, msg_warning, 0); + ret = handle_open(&handle[j], block_file_get(block), state->file_mode, log_error, 0); if (ret == -1) { /* file we have tried to open for error reporting */ struct snapraid_file* file = block_file_get(block); if (errno == EIO) { /* LCOV_EXCL_START */ - msg_tag("error:%u:%s:%s: Open EIO error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); - msg_error("DANGER! Unexpected input/output open error in a data disk, it isn't possible to sync.\n"); - msg_error("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); - msg_error("Stopping at block %u\n", i); + log_tag("error:%u:%s:%s: Open EIO error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); + log_fatal("DANGER! Unexpected input/output open error in a data disk, it isn't possible to sync.\n"); + log_fatal("Ensure that disk '%s' is sane and that file '%s' can be accessed.\n", disk->dir, handle[j].path); + log_fatal("Stopping at block %u\n", i); ++io_error; goto bail; /* LCOV_EXCL_STOP */ } if (errno == ENOENT) { - msg_tag("error:%u:%s:%s: Open ENOENT error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); - msg_warning("Missing file '%s'.\n", handle[j].path); - msg_warning("WARNING! You cannot modify data disk during a sync.\n"); - msg_warning("Rerun the sync command when finished.\n"); + log_tag("error:%u:%s:%s: Open ENOENT error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); + log_error("Missing file '%s'.\n", handle[j].path); + log_error("WARNING! You cannot modify data disk during a sync.\n"); + log_error("Rerun the sync command when finished.\n"); ++error; /* if the file is missing, it means that it was removed during sync */ /* this isn't a serious error, so we skip this block, and continue with others */ @@ -652,10 +652,10 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari } if (errno == EACCES) { - msg_tag("error:%u:%s:%s: Open EACCES error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); - msg_warning("No access at file '%s'.\n", handle[j].path); - msg_warning("WARNING! Please fix the access permission in the data disk.\n"); - msg_warning("Rerun the sync command when finished.\n"); + log_tag("error:%u:%s:%s: Open EACCES error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); + log_error("No access at file '%s'.\n", handle[j].path); + log_error("WARNING! Please fix the access permission in the data disk.\n"); + log_error("Rerun the sync command when finished.\n"); ++error; /* this isn't a serious error, so we skip this block, and continue with others */ error_on_this_block = 1; @@ -663,10 +663,10 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari } /* LCOV_EXCL_START */ - msg_tag("error:%u:%s:%s: Open error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); - msg_error("WARNING! Unexpected open error in a data disk, it isn't possible to sync.\n"); - msg_error("Ensure that file '%s' can be accessed.\n", handle[j].path); - msg_error("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub); + log_tag("error:%u:%s:%s: Open error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); + log_fatal("WARNING! Unexpected open error in a data disk, it isn't possible to sync.\n"); + log_fatal("Ensure that file '%s' can be accessed.\n", handle[j].path); + log_fatal("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub); ++error; goto bail; /* LCOV_EXCL_STOP */ @@ -680,17 +680,17 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari ) { /* file we are processing for error reporting */ struct snapraid_file* file = block_file_get(block); - msg_tag("error:%u:%s:%s: Unexpected attribute change\n", i, disk->name, esc(file->sub)); + log_tag("error:%u:%s:%s: Unexpected attribute change\n", i, disk->name, esc(file->sub)); if (handle[j].st.st_size != file->size) { - msg_warning("Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle[j].path, file->size, handle[j].st.st_size); + log_error("Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle[j].path, file->size, handle[j].st.st_size); } else if (handle[j].st.st_mtime != file->mtime_sec || STAT_NSEC(&handle[j].st) != file->mtime_nsec) { - msg_warning("Unexpected time change at file '%s' from %" PRIu64 ".%d to %" PRIu64 ".%d.\n", handle[j].path, file->mtime_sec, file->mtime_nsec, (uint64_t)handle[j].st.st_mtime, (uint32_t)STAT_NSEC(&handle[j].st)); + log_error("Unexpected time change at file '%s' from %" PRIu64 ".%d to %" PRIu64 ".%d.\n", handle[j].path, file->mtime_sec, file->mtime_nsec, (uint64_t)handle[j].st.st_mtime, (uint32_t)STAT_NSEC(&handle[j].st)); } else { - msg_warning("Unexpected inode change from %" PRIu64 " to %" PRIu64 " at file '%s'.\n", file->inode, (uint64_t)handle[j].st.st_ino, handle[j].path); + log_error("Unexpected inode change from %" PRIu64 " to %" PRIu64 " at file '%s'.\n", file->inode, (uint64_t)handle[j].st.st_ino, handle[j].path); } - msg_warning("WARNING! You cannot modify files during a sync.\n"); - msg_warning("Rerun the sync command when finished.\n"); + log_error("WARNING! You cannot modify files during a sync.\n"); + log_error("Rerun the sync command when finished.\n"); ++error; /* if the file is changed, it means that it was modified during sync */ /* this isn't a serious error, so we skip this block, and continue with others */ @@ -698,31 +698,31 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari continue; } - read_size = handle_read(&handle[j], block, buffer[j], state->block_size, msg_warning, 0); + read_size = handle_read(&handle[j], block, buffer[j], state->block_size, log_error, 0); if (read_size == -1) { /* LCOV_EXCL_START */ /* file we are processing for error reporting */ struct snapraid_file* file = block_file_get(block); if (errno == EIO) { - msg_tag("error:%u:%s:%s: Read EIO error at position %u. %s\n", i, disk->name, esc(file->sub), block_file_pos(block), strerror(errno)); + log_tag("error:%u:%s:%s: Read EIO error at position %u. %s\n", i, disk->name, esc(file->sub), block_file_pos(block), strerror(errno)); if (io_error >= state->opt.io_error_limit) { - msg_error("DANGER! Unexpected input/output read error in a data disk, it isn't possible to sync.\n"); - msg_error("Ensure that disk '%s' is sane and that file '%s' can be read.\n", disk->dir, handle[j].path); - msg_error("Stopping at block %u\n", i); + log_fatal("DANGER! Unexpected input/output read error in a data disk, it isn't possible to sync.\n"); + log_fatal("Ensure that disk '%s' is sane and that file '%s' can be read.\n", disk->dir, handle[j].path); + log_fatal("Stopping at block %u\n", i); ++io_error; goto bail; } - msg_warning("Input/Output error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block)); + log_error("Input/Output error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block)); ++io_error; io_error_on_this_block = 1; continue; } - msg_tag("error:%u:%s:%s: Read error at position %u. %s\n", i, disk->name, esc(file->sub), block_file_pos(block), strerror(errno)); - msg_error("WARNING! Unexpected read error in a data disk, it isn't possible to sync.\n"); - msg_error("Ensure that file '%s' can be read.\n", handle[j].path); - msg_error("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub); + log_tag("error:%u:%s:%s: Read error at position %u. %s\n", i, disk->name, esc(file->sub), block_file_pos(block), strerror(errno)); + log_fatal("WARNING! Unexpected read error in a data disk, it isn't possible to sync.\n"); + log_fatal("Ensure that file '%s' can be read.\n", handle[j].path); + log_fatal("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", file->sub); ++error; goto bail; /* LCOV_EXCL_STOP */ @@ -752,17 +752,17 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari /* if the file has invalid parity, it's a REP changed during the sync */ if (block_has_invalid_parity(block)) { - msg_tag("error:%u:%s:%s: Unexpected data change\n", i, disk->name, esc(file->sub)); - msg_warning("Data change at file '%s' at position '%u'\n", handle[j].path, block_file_pos(block)); - msg_warning("WARNING! Unexpected data modification of a file without parity!\n"); + log_tag("error:%u:%s:%s: Unexpected data change\n", i, disk->name, esc(file->sub)); + log_error("Data change at file '%s' at position '%u'\n", handle[j].path, block_file_pos(block)); + log_error("WARNING! Unexpected data modification of a file without parity!\n"); if (file_flag_has(file, FILE_IS_COPY)) { - msg_warning("This file was detected as a copy of another file with the same name, size,\n"); - msg_warning("and timestamp, but the file data isn't matching the assumed copy.\n"); - msg_warning("If this is a false positive, and the files are expected to be different,\n"); - msg_warning("you can 'sync' anyway using 'snapraid --force-nocopy sync'\n"); + log_error("This file was detected as a copy of another file with the same name, size,\n"); + log_error("and timestamp, but the file data isn't matching the assumed copy.\n"); + log_error("If this is a false positive, and the files are expected to be different,\n"); + log_error("you can 'sync' anyway using 'snapraid --force-nocopy sync'\n"); } else { - msg_warning("Try removing the file from the array and rerun the 'sync' command!\n"); + log_error("Try removing the file from the array and rerun the 'sync' command!\n"); } ++error; @@ -772,8 +772,8 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari error_on_this_block = 1; continue; } else { /* otherwise it's a BLK with silent error */ - msg_tag("error:%u:%s:%s: Data error at position %u\n", i, disk->name, esc(file->sub), block_file_pos(block)); - msg_warning("Data error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block)); + log_tag("error:%u:%s:%s: Data error at position %u\n", i, disk->name, esc(file->sub), block_file_pos(block)); + log_error("Data error in file '%s' at position '%u'\n", handle[j].path, block_file_pos(block)); /* save the failed block for the fix */ failed[failed_count].index = j; @@ -866,29 +866,29 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari /* we are sure that parity exists because */ /* we have at least one BLK block */ for (l = 0; l < state->level; ++l) { - ret = parity_read(parity[l], i, buffer[diskmax + l], state->block_size, msg_warning); + ret = parity_read(parity[l], i, buffer[diskmax + l], state->block_size, log_error); if (ret == -1) { /* LCOV_EXCL_START */ if (errno == EIO) { - msg_tag("parity_error:%u:%s: Read EIO error. %s\n", i, lev_config_name(l), strerror(errno)); + log_tag("parity_error:%u:%s: Read EIO error. %s\n", i, lev_config_name(l), strerror(errno)); if (io_error >= state->opt.io_error_limit) { - msg_error("DANGER! Unexpected input/output read error in the %s disk, it isn't possible to sync.\n", lev_name(l)); - msg_error("Ensure that disk '%s' is sane and can be read.\n", lev_config_name(l)); - msg_error("Stopping at block %u\n", i); + log_fatal("DANGER! Unexpected input/output read error in the %s disk, it isn't possible to sync.\n", lev_name(l)); + log_fatal("Ensure that disk '%s' is sane and can be read.\n", lev_config_name(l)); + log_fatal("Stopping at block %u\n", i); ++io_error; goto bail; } - msg_warning("Input/Output error in parity '%s' at position '%u'\n", lev_config_name(l), i); + log_error("Input/Output error in parity '%s' at position '%u'\n", lev_config_name(l), i); ++io_error; io_error_on_this_block = 1; continue; } - msg_tag("parity_error:%u:%s: Read error. %s\n", i, lev_config_name(l), strerror(errno)); - msg_error("WARNING! Unexpected read error in the %s disk, it isn't possible to sync.\n", lev_name(l)); - msg_error("Ensure that disk '%s' can be read.\n", lev_config_name(l)); - msg_error("Stopping at block %u\n", i); + log_tag("parity_error:%u:%s: Read error. %s\n", i, lev_config_name(l), strerror(errno)); + log_fatal("WARNING! Unexpected read error in the %s disk, it isn't possible to sync.\n", lev_name(l)); + log_fatal("Ensure that disk '%s' can be read.\n", lev_config_name(l)); + log_fatal("Stopping at block %u\n", i); ++error; goto bail; /* LCOV_EXCL_STOP */ @@ -965,25 +965,25 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari if (ret == -1) { /* LCOV_EXCL_START */ if (errno == EIO) { - msg_tag("parity_error:%u:%s: Write EIO error. %s\n", i, lev_config_name(l), strerror(errno)); + log_tag("parity_error:%u:%s: Write EIO error. %s\n", i, lev_config_name(l), strerror(errno)); if (io_error >= state->opt.io_error_limit) { - msg_error("DANGER! Unexpected input/output write error in the %s disk, it isn't possible to sync.\n", lev_name(l)); - msg_error("Ensure that disk '%s' is sane and can be written.\n", lev_config_name(l)); - msg_error("Stopping at block %u\n", i); + log_fatal("DANGER! Unexpected input/output write error in the %s disk, it isn't possible to sync.\n", lev_name(l)); + log_fatal("Ensure that disk '%s' is sane and can be written.\n", lev_config_name(l)); + log_fatal("Stopping at block %u\n", i); ++io_error; goto bail; } - msg_warning("Input/Output error in parity '%s' at position '%u'\n", lev_config_name(l), i); + log_error("Input/Output error in parity '%s' at position '%u'\n", lev_config_name(l), i); ++io_error; io_error_on_this_block = 1; continue; } - msg_tag("parity_error:%u:%s: Write error. %s\n", i, lev_config_name(l), strerror(errno)); - msg_error("WARNING! Unexpected write error in the %s disk, it isn't possible to sync.\n", lev_name(l)); - msg_error("Ensure that disk '%s' has some free space available.\n", lev_config_name(l)); - msg_error("Stopping at block %u\n", i); + log_tag("parity_error:%u:%s: Write error. %s\n", i, lev_config_name(l), strerror(errno)); + log_fatal("WARNING! Unexpected write error in the %s disk, it isn't possible to sync.\n", lev_name(l)); + log_fatal("Ensure that disk '%s' has some free space available.\n", lev_config_name(l)); + log_fatal("Stopping at block %u\n", i); ++error; goto bail; /* LCOV_EXCL_STOP */ @@ -1086,10 +1086,10 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari ret = parity_sync(parity[l]); if (ret == -1) { /* LCOV_EXCL_START */ - msg_tag("parity_error:%u:%s: Sync error\n", i, lev_config_name(l)); - msg_error("DANGER! Unexpected sync error in %s disk.\n", lev_name(l)); - msg_error("Ensure that disk '%s' is sane.\n", lev_config_name(l)); - msg_error("Stopping at block %u\n", i); + log_tag("parity_error:%u:%s: Sync error\n", i, lev_config_name(l)); + log_fatal("DANGER! Unexpected sync error in %s disk.\n", lev_name(l)); + log_fatal("Ensure that disk '%s' is sane.\n", lev_config_name(l)); + log_fatal("Stopping at block %u\n", i); ++error; goto bail; /* LCOV_EXCL_STOP */ @@ -1117,10 +1117,10 @@ end: ret = parity_sync(parity[l]); if (ret == -1) { /* LCOV_EXCL_START */ - msg_tag("parity_error:%u:%s: Sync error\n", i, lev_config_name(l)); - msg_error("DANGER! Unexpected sync error in %s disk.\n", lev_name(l)); - msg_error("Ensure that disk '%s' is sane.\n", lev_config_name(l)); - msg_error("Stopping at block %u\n", i); + log_tag("parity_error:%u:%s: Sync error\n", i, lev_config_name(l)); + log_fatal("DANGER! Unexpected sync error in %s disk.\n", lev_name(l)); + log_fatal("Ensure that disk '%s' is sane.\n", lev_config_name(l)); + log_fatal("Stopping at block %u\n", i); ++error; goto bail; /* LCOV_EXCL_STOP */ @@ -1139,24 +1139,24 @@ end: } if (error) - msg_error("WARNING! Unexpected file errors!\n"); + log_fatal("WARNING! Unexpected file errors!\n"); if (io_error) - msg_error("DANGER! Unexpected input/output errors! The failing blocks are now marked as bad!\n"); + log_fatal("DANGER! Unexpected input/output errors! The failing blocks are now marked as bad!\n"); if (silent_error) - msg_error("DANGER! Unexpected data errors! The failing blocks are now marked as bad!\n"); + log_fatal("DANGER! Unexpected data errors! The failing blocks are now marked as bad!\n"); if (io_error || silent_error) { - msg_error("Use 'snapraid status' to list the bad blocks.\n"); - msg_error("Use 'snapraid -e fix' to recover.\n"); + log_fatal("Use 'snapraid status' to list the bad blocks.\n"); + log_fatal("Use 'snapraid -e fix' to recover.\n"); } - msg_tag("summary:error_file:%u\n", error); - msg_tag("summary:error_io:%u\n", io_error); - msg_tag("summary:error_data:%u\n", silent_error); + log_tag("summary:error_file:%u\n", error); + log_tag("summary:error_io:%u\n", io_error); + log_tag("summary:error_data:%u\n", silent_error); if (error + silent_error + io_error == 0) - msg_tag("summary:exit:ok\n"); + log_tag("summary:exit:ok\n"); else - msg_tag("summary:exit:error\n"); - msg_flush(); + log_tag("summary:exit:error\n"); + log_flush(); bail: for (j = 0; j < diskmax; ++j) { @@ -1165,8 +1165,8 @@ bail: ret = handle_close(&handle[j]); if (ret == -1) { /* LCOV_EXCL_START */ - msg_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); - msg_error("DANGER! Unexpected close error in a data disk.\n"); + log_tag("error:%u:%s:%s: Close error. %s\n", i, disk->name, esc(file->sub), strerror(errno)); + log_fatal("DANGER! Unexpected close error in a data disk.\n"); ++error; /* continue, as we are already exiting */ /* LCOV_EXCL_STOP */ @@ -1219,7 +1219,7 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t if (blockstart > blockmax) { /* LCOV_EXCL_START */ - msg_error("Error in the starting block %u. It's bigger than the parity size %u.\n", blockstart, blockmax); + log_fatal("Error in the starting block %u. It's bigger than the parity size %u.\n", blockstart, blockmax); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1237,7 +1237,7 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t ret = parity_create(parity_ptr[l], state->parity[l].path, &out_size, state->file_mode); if (ret == -1) { /* LCOV_EXCL_START */ - msg_error("WARNING! Without an accessible %s file, it isn't possible to sync.\n", lev_name(l)); + log_fatal("WARNING! Without an accessible %s file, it isn't possible to sync.\n", lev_name(l)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1247,7 +1247,7 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t /* if the file is too small */ if (parityblocks < used_paritymax) { - msg_error("WARNING! The %s file %s has data only %u blocks instead of %u.\n", lev_name(l), state->parity[l].path, parityblocks, used_paritymax); + log_fatal("WARNING! The %s file %s has data only %u blocks instead of %u.\n", lev_name(l), state->parity[l].path, parityblocks, used_paritymax); } /* keep the smallest parity number of blocks */ @@ -1260,15 +1260,15 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t /* if the parities are too small */ if (file_paritymax < used_paritymax) { /* LCOV_EXCL_START */ - msg_error("DANGER! One or more the parity files are smaller than expected!\n"); + log_fatal("DANGER! One or more the parity files are smaller than expected!\n"); if (file_paritymax != 0) { - msg_error("If this happens because you are using an old content file,\n"); - msg_error("you can 'sync' anyway using 'snapraid --force-full sync'\n"); - msg_error("to force a full rebuild of the parity.\n"); + log_fatal("If this happens because you are using an old content file,\n"); + log_fatal("you can 'sync' anyway using 'snapraid --force-full sync'\n"); + log_fatal("to force a full rebuild of the parity.\n"); } else { - msg_error("It's possible that the parity disks are not mounted.\n"); - msg_error("If instead you are adding a new parity level, you can 'sync' using\n"); - msg_error("'snapraid --force-full sync' to force a full rebuild of the parity.\n"); + log_fatal("It's possible that the parity disks are not mounted.\n"); + log_fatal("If instead you are adding a new parity level, you can 'sync' using\n"); + log_fatal("'snapraid --force-full sync' to force a full rebuild of the parity.\n"); } exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -1284,7 +1284,7 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t if (ret == -1) { /* LCOV_EXCL_START */ parity_overflow(state, out_size); - msg_error("WARNING! Without an accessible %s file, it isn't possible to sync.\n", lev_name(l)); + log_fatal("WARNING! Without an accessible %s file, it isn't possible to sync.\n", lev_name(l)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -1331,7 +1331,7 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t ret = parity_close(parity_ptr[l]); if (ret == -1) { /* LCOV_EXCL_START */ - msg_error("DANGER! Unexpected close error in %s disk.\n", lev_name(l)); + log_fatal("DANGER! Unexpected close error in %s disk.\n", lev_name(l)); ++unrecoverable_error; /* continue, as we are already exiting */ /* LCOV_EXCL_STOP */ diff --git a/cmdline/unix.c b/cmdline/unix.c index 71144387..060e4f48 100644 --- a/cmdline/unix.c +++ b/cmdline/unix.c @@ -341,7 +341,7 @@ static dev_t devread(const char* path) f = open(path, O_RDONLY); if (f == -1) { /* LCOV_EXCL_START */ - msg_error("Failed to open '%s'.\n", path); + log_fatal("Failed to open '%s'.\n", path); return 0; /* LCOV_EXCL_STOP */ } @@ -350,14 +350,14 @@ static dev_t devread(const char* path) if (ret < 0) { /* LCOV_EXCL_START */ close(f); - msg_error("Failed to read '%s'.\n", path); + log_fatal("Failed to read '%s'.\n", path); return 0; /* LCOV_EXCL_STOP */ } if (ret == sizeof(buf)) { /* LCOV_EXCL_START */ close(f); - msg_error("Too long read '%s'.\n", path); + log_fatal("Too long read '%s'.\n", path); return 0; /* LCOV_EXCL_STOP */ } @@ -368,7 +368,7 @@ static dev_t devread(const char* path) if (*e != ':') { /* LCOV_EXCL_START */ close(f); - msg_error("Invalid format in '%s' for '%s'.\n", path, buf); + log_fatal("Invalid format in '%s' for '%s'.\n", path, buf); return 0; /* LCOV_EXCL_STOP */ } @@ -377,7 +377,7 @@ static dev_t devread(const char* path) if (*e != 0 && !isspace(*e)) { /* LCOV_EXCL_START */ close(f); - msg_error("Invalid format in '%s' for '%s'.\n", path, buf); + log_fatal("Invalid format in '%s' for '%s'.\n", path, buf); return 0; /* LCOV_EXCL_STOP */ } @@ -385,7 +385,7 @@ static dev_t devread(const char* path) ret = close(f); if (ret != 0) { /* LCOV_EXCL_START */ - msg_error("Failed to close '%s'.\n", path); + log_fatal("Failed to close '%s'.\n", path); return 0; /* LCOV_EXCL_STOP */ } @@ -411,13 +411,13 @@ static int devresolve(dev_t device, char* path, size_t path_size) ret = readlink(path, buf, sizeof(buf)); if (ret < 0) { /* LCOV_EXCL_START */ - msg_error("Failed to readlink '%s'.\n", path); + log_fatal("Failed to readlink '%s'.\n", path); return -1; /* LCOV_EXCL_STOP */ } if (ret == sizeof(buf)) { /* LCOV_EXCL_START */ - msg_error("Too long readlink '%s'.\n", path); + log_fatal("Too long readlink '%s'.\n", path); return -1; /* LCOV_EXCL_STOP */ } @@ -426,7 +426,7 @@ static int devresolve(dev_t device, char* path, size_t path_size) if (buf[0] != '.' || buf[1] != '.' || buf[2] != '/') { /* LCOV_EXCL_START */ - msg_error("Unexpected link '%s' at '%s'.\n", buf, path); + log_fatal("Unexpected link '%s' at '%s'.\n", buf, path); return -1; /* LCOV_EXCL_STOP */ } @@ -437,13 +437,13 @@ static int devresolve(dev_t device, char* path, size_t path_size) /* check the device */ if (stat(path, &st) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed to stat '%s'.\n", path); + log_fatal("Failed to stat '%s'.\n", path); return -1; /* LCOV_EXCL_STOP */ } if (st.st_rdev != device) { /* LCOV_EXCL_START */ - msg_error("Unexpected device '%u:%u' instead of '%u:%u' for '%s'.\n", major(st.st_rdev), minor(st.st_rdev), major(device), minor(device), path); + log_fatal("Unexpected device '%u:%u' instead of '%u:%u' for '%s'.\n", major(st.st_rdev), minor(st.st_rdev), major(device), minor(device), path); return -1; /* LCOV_EXCL_STOP */ } @@ -556,7 +556,7 @@ static int devscan(tommy_list* list) d = opendir(dir); if (d == 0) { /* LCOV_EXCL_START */ - msg_error("Failed to open dir '%s'.\n", dir); + log_fatal("Failed to open dir '%s'.\n", dir); return -1; /* LCOV_EXCL_STOP */ } @@ -639,12 +639,12 @@ static int devsmart(dev_t device, const char* name, const char* custom, uint64_t snprintf(cmd, sizeof(cmd), "smartctl -a %s", file); } - msg_tag("smartctl:%s:%s:run: %s\n", file, name, cmd); + log_tag("smartctl:%s:%s:run: %s\n", file, name, cmd); f = popen(cmd, "r"); if (!f) { /* LCOV_EXCL_START */ - msg_error("Failed to run '%s' (from popen).\n", cmd); + log_fatal("Failed to run '%s' (from popen).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } @@ -658,17 +658,17 @@ static int devsmart(dev_t device, const char* name, const char* custom, uint64_t ret = pclose(f); - msg_tag("smartctl:%s:%s:ret: %x\n", file, name, ret); + log_tag("smartctl:%s:%s:ret: %x\n", file, name, ret); if (!WIFEXITED(ret)) { /* LCOV_EXCL_START */ - msg_error("Failed to run '%s' (not exited).\n", cmd); + log_fatal("Failed to run '%s' (not exited).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } if (WEXITSTATUS(ret) == 127) { /* LCOV_EXCL_START */ - msg_error("Failed to run '%s' (from sh).\n", cmd); + log_fatal("Failed to run '%s' (from sh).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } @@ -701,12 +701,12 @@ static int devdown(dev_t device, const char* name, const char* custom) snprintf(cmd, sizeof(cmd), "smartctl -s standby,now %s", file); } - msg_tag("smartctl:%s:%s:run: %s\n", file, name, cmd); + log_tag("smartctl:%s:%s:run: %s\n", file, name, cmd); f = popen(cmd, "r"); if (!f) { /* LCOV_EXCL_START */ - msg_error("Failed to run '%s' (from popen).\n", cmd); + log_fatal("Failed to run '%s' (from popen).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } @@ -720,23 +720,23 @@ static int devdown(dev_t device, const char* name, const char* custom) ret = pclose(f); - msg_tag("smartctl:%s:%s:ret: %x\n", file, name, ret); + log_tag("smartctl:%s:%s:ret: %x\n", file, name, ret); if (!WIFEXITED(ret)) { /* LCOV_EXCL_START */ - msg_error("Failed to run '%s' (not exited).\n", cmd); + log_fatal("Failed to run '%s' (not exited).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } if (WEXITSTATUS(ret) == 127) { /* LCOV_EXCL_START */ - msg_error("Failed to run '%s' (from sh).\n", cmd); + log_fatal("Failed to run '%s' (from sh).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } if (WEXITSTATUS(ret) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed to run '%s' with return code %xh.\n", cmd, WEXITSTATUS(ret)); + log_fatal("Failed to run '%s' with return code %xh.\n", cmd, WEXITSTATUS(ret)); return -1; /* LCOV_EXCL_STOP */ } @@ -763,7 +763,7 @@ static int devup(const char* mount) ret = mkdir(path, 0); if (ret != 0 && errno != EEXIST) { /* LCOV_EXCL_START */ - msg_error("Failed to create dir '%s'.\n", path); + log_fatal("Failed to create dir '%s'.\n", path); return -1; /* LCOV_EXCL_STOP */ } @@ -792,7 +792,7 @@ static void* thread_spinup(void* arg) /* first get the device number, this usually doesn't trigger a thread_spinup */ if (stat(devinfo->mount, &st) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed to stat device '%s'.\n", devinfo->mount); + log_fatal("Failed to stat device '%s'.\n", devinfo->mount); return (void*)-1; /* LCOV_EXCL_STOP */ } @@ -872,7 +872,7 @@ static int device_thread(tommy_list* list, void* (*func)(void* arg)) if (pthread_create(&devinfo->thread, 0, func, devinfo) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed to create thread.\n"); + log_fatal("Failed to create thread.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -885,7 +885,7 @@ static int device_thread(tommy_list* list, void* (*func)(void* arg)) if (pthread_join(devinfo->thread, &retval) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed to join thread.\n"); + log_fatal("Failed to join thread.\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -921,13 +921,13 @@ int devquery(tommy_list* high, tommy_list* low, int operation) /* sysfs and devfs interfaces are required */ if (stat("/sys/dev/block", &st) != 0) { /* LCOV_EXCL_START */ - msg_error("Missing interface /sys/dev/block.\n"); + log_fatal("Missing interface /sys/dev/block.\n"); return -1; /* LCOV_EXCL_STOP */ } if (stat("/dev/block", &st) != 0) { /* LCOV_EXCL_START */ - msg_error("Missing interface /dev/block.\n"); + log_fatal("Missing interface /dev/block.\n"); return -1; /* LCOV_EXCL_STOP */ } @@ -939,7 +939,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation) /* get the device file */ if (devresolve(devinfo->device, devinfo->file, sizeof(devinfo->file)) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed to resolve device '%u:%u'.\n", major(devinfo->device), minor(devinfo->device)); + log_fatal("Failed to resolve device '%u:%u'.\n", major(devinfo->device), minor(devinfo->device)); return -1; /* LCOV_EXCL_STOP */ } @@ -947,7 +947,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation) /* expand the tree of devices */ if (devtree(devinfo->name, devinfo->smartctl, devinfo->device, devinfo, low) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed to expand device '%u:%u'.\n", major(devinfo->device), minor(devinfo->device)); + log_fatal("Failed to expand device '%u:%u'.\n", major(devinfo->device), minor(devinfo->device)); return -1; /* LCOV_EXCL_STOP */ } @@ -977,7 +977,7 @@ int devquery(tommy_list* high, tommy_list* low, int operation) if (operation == DEVICE_SMART) { if (devscan(low) != 0) { /* LCOV_EXCL_START */ - msg_error("Failed to list other devices.\n"); + log_fatal("Failed to list other devices.\n"); return -1; /* LCOV_EXCL_STOP */ } diff --git a/cmdline/util.c b/cmdline/util.c index 67fe8f86..2a3baf4f 100644 --- a/cmdline/util.c +++ b/cmdline/util.c @@ -72,8 +72,8 @@ void mtest_vector(int n, size_t size, void** vv) { if (raid_mtest_vector(n, size, vv) != 0) { /* LCOV_EXCL_START */ - msg_error("DANGER! Your RAM memory is broken! DO NOT PROCEED UNTIL FIXED!\n"); - msg_error("Try running a memory test like http://www.memtest86.com/\n"); + log_fatal("DANGER! Your RAM memory is broken! DO NOT PROCEED UNTIL FIXED!\n"); + log_fatal("Try running a memory test like http://www.memtest86.com/\n"); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } @@ -492,7 +492,7 @@ void memhash(unsigned kind, const unsigned char* seed, void* digest, const void* break; default : /* LCOV_EXCL_START */ - msg_error("Internal inconsistency in hash function %u\n", kind); + log_fatal("Internal inconsistency in hash function %u\n", kind); exit(EXIT_FAILURE); break; /* LCOV_EXCL_STOP */