mirror of
https://github.com/amadvance/snapraid.git
synced 2026-11-25 17:36:26 -05:00
Change the log and output handling
Now the log file contains all the errors messages, and all the tag lines.
This commit is contained in:
parent
ce20be0ded
commit
b5ce575981
32 changed files with 1127 additions and 1036 deletions
|
|
@ -76,7 +76,7 @@ void usage(void)
|
|||
|
||||
void memory(void)
|
||||
{
|
||||
fprintf(stdlog, "memory:used:%" PRIu64 "\n", (uint64_t)malloc_counter());
|
||||
ftag("memory:used:%" PRIu64 "\n", (uint64_t)malloc_counter());
|
||||
printf("Using %u MiB of memory.\n", (unsigned)(malloc_counter() / 1024 / 1024));
|
||||
}
|
||||
|
||||
|
|
@ -151,7 +151,7 @@ void log_open(const char* log)
|
|||
break;
|
||||
default :
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Invalid type specifier '%c' in the log file.\n", *log);
|
||||
ferr("Invalid type specifier '%c' in the log file.\n", *log);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -166,7 +166,7 @@ void log_open(const char* log)
|
|||
stdlog = fopen(path, mode);
|
||||
if (!stdlog) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Error opening the log file '%s'. %s.\n", path, strerror(errno));
|
||||
ferr("Error opening the log file '%s'. %s.\n", path, strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -177,7 +177,7 @@ void log_close(const char* log)
|
|||
if (stdlog != stdout && stdlog != stderr) {
|
||||
if (fclose(stdlog) != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Error closing the log file '%s'. %s.\n", log, strerror(errno));
|
||||
ferr("Error closing the log file '%s'. %s.\n", log, strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -454,7 +454,7 @@ int main(int argc, char* argv[])
|
|||
struct snapraid_filter* filter = filter_alloc_file(1, optarg);
|
||||
if (!filter) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Invalid filter specification '%s'\n", optarg);
|
||||
ferr("Invalid filter specification '%s'\n", optarg);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -464,7 +464,7 @@ int main(int argc, char* argv[])
|
|||
struct snapraid_filter* filter = filter_alloc_disk(1, optarg);
|
||||
if (!filter) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Invalid filter specification '%s'\n", optarg);
|
||||
ferr("Invalid filter specification '%s'\n", optarg);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -484,7 +484,7 @@ int main(int argc, char* argv[])
|
|||
percentage = strtoul(optarg, &e, 10);
|
||||
if (!e || *e || percentage > 100) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Invalid percentage '%s'\n", optarg);
|
||||
ferr("Invalid percentage '%s'\n", optarg);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -493,7 +493,7 @@ int main(int argc, char* argv[])
|
|||
olderthan = strtoul(optarg, &e, 10);
|
||||
if (!e || *e || olderthan > 1000) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Invalid number of days '%s'\n", optarg);
|
||||
ferr("Invalid number of days '%s'\n", optarg);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -502,7 +502,7 @@ int main(int argc, char* argv[])
|
|||
blockstart = strtoul(optarg, &e, 0);
|
||||
if (!e || *e) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Invalid start position '%s'\n", optarg);
|
||||
ferr("Invalid start position '%s'\n", optarg);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -511,7 +511,7 @@ int main(int argc, char* argv[])
|
|||
blockcount = strtoul(optarg, &e, 0);
|
||||
if (!e || *e) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Invalid count number '%s'\n", optarg);
|
||||
ferr("Invalid count number '%s'\n", optarg);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -520,7 +520,7 @@ int main(int argc, char* argv[])
|
|||
opt.io_error_limit = strtoul(optarg, &e, 0);
|
||||
if (!e || *e) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Invalid error limit number '%s'\n", optarg);
|
||||
ferr("Invalid error limit number '%s'\n", optarg);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -528,7 +528,7 @@ int main(int argc, char* argv[])
|
|||
case 'i' :
|
||||
if (import_timestamp) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Import directory '%s' already specified as '%s'\n", optarg, import_timestamp);
|
||||
ferr("Import directory '%s' already specified as '%s'\n", optarg, import_timestamp);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -537,7 +537,7 @@ int main(int argc, char* argv[])
|
|||
case OPT_TEST_IMPORT_CONTENT :
|
||||
if (import_content) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Import directory '%s' already specified as '%s'\n", optarg, import_content);
|
||||
ferr("Import directory '%s' already specified as '%s'\n", optarg, import_content);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -546,7 +546,7 @@ int main(int argc, char* argv[])
|
|||
case 'l' :
|
||||
if (log) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Log file '%s' already specified as '%s'\n", optarg, log);
|
||||
ferr("Log file '%s' already specified as '%s'\n", optarg, log);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -683,7 +683,7 @@ int main(int argc, char* argv[])
|
|||
break;
|
||||
default :
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Unknown option '%c'\n", (char)c);
|
||||
ferr("Unknown option '%c'\n", (char)c);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -749,7 +749,7 @@ int main(int argc, char* argv[])
|
|||
operation = OPERATION_SMART;
|
||||
} else {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Unknown command '%s'\n", argv[optind]);
|
||||
ferr("Unknown command '%s'\n", argv[optind]);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -761,7 +761,7 @@ int main(int argc, char* argv[])
|
|||
default :
|
||||
if (opt.auditonly) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "You cannot use -a, --audit-only with the '%s' command\n", command);
|
||||
ferr("You cannot use -a, --audit-only with the '%s' command\n", command);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -775,7 +775,7 @@ int main(int argc, char* argv[])
|
|||
default :
|
||||
if (opt.force_nocopy) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "You cannot use -N, --force-nocopy with the '%s' command\n", command);
|
||||
ferr("You cannot use -N, --force-nocopy with the '%s' command\n", command);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -787,14 +787,14 @@ int main(int argc, char* argv[])
|
|||
default :
|
||||
if (opt.prehash) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "You cannot use -h, --pre-hash with the '%s' command\n", command);
|
||||
ferr("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 */
|
||||
fprintf(stderr, "You cannot use -F, --force-full with the '%s' command\n", command);
|
||||
ferr("You cannot use -F, --force-full with the '%s' command\n", command);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -802,14 +802,14 @@ int main(int argc, char* argv[])
|
|||
|
||||
if (opt.force_full && opt.force_nocopy) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "You cannot use the -F, --force-full and -N, --force-nocopy options at the same time\n");
|
||||
ferr("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 */
|
||||
fprintf(stderr, "You cannot use the -h, --pre-hash and -N, --force-nocopy options at the same time\n");
|
||||
ferr("You cannot use the -h, --pre-hash and -N, --force-nocopy options at the same time\n");
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -822,25 +822,25 @@ int main(int argc, char* argv[])
|
|||
default :
|
||||
if (!tommy_list_empty(&filterlist_file)) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "You cannot use -f, --filter with the '%s' command\n", command);
|
||||
ferr("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 */
|
||||
fprintf(stderr, "You cannot use -d, --filter-disk with the '%s' command\n", command);
|
||||
ferr("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 */
|
||||
fprintf(stderr, "You cannot use -m, --filter-missing with the '%s' command\n", command);
|
||||
ferr("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 */
|
||||
fprintf(stderr, "You cannot use -e, --filter-error with the '%s' command\n", command);
|
||||
ferr("You cannot use -e, --filter-error with the '%s' command\n", command);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -853,7 +853,7 @@ int main(int argc, char* argv[])
|
|||
default :
|
||||
if (import_timestamp != 0 || import_content != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "You cannot import with the '%s' command\n", command);
|
||||
ferr("You cannot import with the '%s' command\n", command);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -914,16 +914,16 @@ int main(int argc, char* argv[])
|
|||
/* print generic info into the log */
|
||||
t = time(0);
|
||||
tm = localtime(&t);
|
||||
fprintf(stdlog, "version:%s\n", PACKAGE_VERSION);
|
||||
fprintf(stdlog, "unixtime:%" PRIi64 "\n", (int64_t)t);
|
||||
ftag("version:%s\n", PACKAGE_VERSION);
|
||||
ftag("unixtime:%" PRIi64 "\n", (int64_t)t);
|
||||
if (tm) {
|
||||
char datetime[64];
|
||||
strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", tm);
|
||||
fprintf(stdlog, "time:%s\n", datetime);
|
||||
ftag("time:%s\n", datetime);
|
||||
}
|
||||
fprintf(stdlog, "command:%s\n", command);
|
||||
ftag("command:%s\n", command);
|
||||
for (i = 0; i < argc; ++i)
|
||||
fprintf(stdlog, "argv:%u:%s\n", i, argv[i]);
|
||||
ftag("argv:%u:%s\n", i, argv[i]);
|
||||
fflush(stdlog);
|
||||
|
||||
if (!opt.skip_self)
|
||||
|
|
@ -944,10 +944,10 @@ int main(int argc, char* argv[])
|
|||
if (lock == -1) {
|
||||
/* LCOV_EXCL_START */
|
||||
if (errno != EWOULDBLOCK) {
|
||||
fprintf(stderr, "Error creating the lock file '%s'. %s.\n", state.lockfile, strerror(errno));
|
||||
ferr("Error creating the lock file '%s'. %s.\n", state.lockfile, strerror(errno));
|
||||
} else {
|
||||
fprintf(stderr, "The lock file '%s' is already locked!\n", state.lockfile);
|
||||
fprintf(stderr, "SnapRAID is already in use!\n");
|
||||
ferr("The lock file '%s' is already locked!\n", state.lockfile);
|
||||
ferr("SnapRAID is already in use!\n");
|
||||
}
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
|
|
@ -1005,7 +1005,7 @@ int main(int argc, char* argv[])
|
|||
ret = system(run); /* ignore error */
|
||||
if (ret != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Error in running command '%s'.\n", run);
|
||||
ferr("Error in running command '%s'.\n", run);
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -1161,7 +1161,7 @@ int main(int argc, char* argv[])
|
|||
if (!opt.skip_lock) {
|
||||
if (lock_unlock(lock) == -1) {
|
||||
/* LCOV_EXCL_START */
|
||||
fprintf(stderr, "Error closing the lock file '%s'. %s.\n", state.lockfile, strerror(errno));
|
||||
ferr("Error closing the lock file '%s'. %s.\n", state.lockfile, strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue