diff --git a/cmdline/check.c b/cmdline/check.c index 53a8fb89..d7d5984a 100644 --- a/cmdline/check.c +++ b/cmdline/check.c @@ -293,8 +293,6 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign int n; int something_to_recover; int something_unsynced; - char esc_buffer[ESC_MAX]; - error = 0; /* if nothing failed, just recompute the parity */ @@ -339,7 +337,7 @@ static int repair(struct snapraid_state* state, int rehash, unsigned pos, unsign struct snapraid_file* file = failed[j].file; block_off_t file_pos = failed[j].file_pos; - log_tag("repair_entry:%u:%s:%s:%s:%s:%s:%u:\n", j, desc, hash, data, disk->name, esc_tag(file->sub, esc_buffer), file_pos); + log_tag("repair_entry:%u:%s:%s:%s:%s:%s:%u:\n", j, desc, hash, data, disk->name, esc_tag(file->sub), file_pos); } else { log_tag("repair_entry:%u:%s:%s:%s:\n", j, desc, hash, data); } @@ -601,9 +599,6 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s { unsigned j; int ret; - char esc_buffer[ESC_MAX]; - char esc_buffer_alt[ESC_MAX]; - /* for all the files print the final status, and do the final time fix */ /* we also ensure to close files after processing the last block */ for (j = 0; j < diskmax; ++j) { @@ -661,7 +656,7 @@ 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 */ - log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); return -1; /* LCOV_EXCL_STOP */ @@ -672,14 +667,14 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s if (ret != 0) { /* LCOV_EXCL_START */ log_fatal(errno, "Error renaming '%s%s'. %s.\n", disk->dir, file->sub, strerror(errno)); - log_tag("%s:%u:%s:%s: Rename error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Rename error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); return -1; /* LCOV_EXCL_STOP */ } - log_tag("status:unrecoverable:%s:%s\n", disk->name, esc_tag(file->sub, esc_buffer)); - msg_info("unrecoverable %s\n", fmt_term(disk, file->sub, esc_buffer)); + log_tag("status:unrecoverable:%s:%s\n", disk->name, esc_tag(file->sub)); + msg_info("unrecoverable %s\n", fmt_term(disk, file->sub)); /* and do not set the time if damaged */ goto close_and_continue; @@ -699,7 +694,7 @@ 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 */ - log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), i, disk->name, esc_tag(report->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), i, disk->name, esc_tag(report->sub), strerror(errno)); log_fatal_errno(errno, disk->name); return -1; /* LCOV_EXCL_STOP */ @@ -710,15 +705,15 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s ret = handle_open(&handle[j], file, state->file_mode, log_error, log_error); /* output a message for missing files */ if (ret != 0) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Open error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Open error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); return -1; /* LCOV_EXCL_STOP */ } } - log_tag("status:recovered:%s:%s\n", disk->name, esc_tag(file->sub, esc_buffer)); - msg_info("recovered %s\n", fmt_term(disk, file->sub, esc_buffer)); + log_tag("status:recovered:%s:%s\n", disk->name, esc_tag(file->sub)); + msg_info("recovered %s\n", fmt_term(disk, file->sub)); inode = handle[j].st.st_ino; @@ -743,7 +738,7 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s ret = handle_utime(&handle[j]); if (ret == -1) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Time error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Time error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); /* mark the file as damaged */ @@ -752,22 +747,22 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s /* LCOV_EXCL_STOP */ } } else { - log_tag("collision:%s:%s:%s: Not setting modification time to avoid inode collision\n", disk->name, esc_tag(file->sub, esc_buffer), esc_tag(collide_file->sub, esc_buffer_alt)); + log_tag("collision:%s:%s:%s: Not setting modification time to avoid inode collision\n", disk->name, esc_tag(file->sub), esc_tag(collide_file->sub)); } } else { /* we are not fixing, but only checking */ /* print just the final status */ if (file_flag_has(file, FILE_IS_DAMAGED)) { - log_tag("status:unrecoverable:%s:%s\n", disk->name, esc_tag(file->sub, esc_buffer)); - msg_info("unrecoverable %s\n", fmt_term(disk, file->sub, esc_buffer)); + log_tag("status:unrecoverable:%s:%s\n", disk->name, esc_tag(file->sub)); + msg_info("unrecoverable %s\n", fmt_term(disk, file->sub)); } else if (file_flag_has(file, FILE_IS_FIXED)) { - log_tag("status:recoverable:%s:%s\n", disk->name, esc_tag(file->sub, esc_buffer)); - msg_info("recoverable %s\n", fmt_term(disk, file->sub, esc_buffer)); + log_tag("status:recoverable:%s:%s\n", disk->name, esc_tag(file->sub)); + msg_info("recoverable %s\n", fmt_term(disk, file->sub)); } else { /* we don't use msg_verbose() because it also goes into the log */ if (msg_level >= MSG_VERBOSE) { - log_tag("status:correct:%s:%s\n", disk->name, esc_tag(file->sub, esc_buffer)); - msg_info("correct %s\n", fmt_term(disk, file->sub, esc_buffer)); + log_tag("status:correct:%s:%s\n", disk->name, esc_tag(file->sub)); + msg_info("correct %s\n", fmt_term(disk, file->sub)); } } } @@ -782,7 +777,7 @@ close_and_continue: ret = handle_close(&handle[j]); if (ret != 0) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); return -1; /* LCOV_EXCL_STOP */ @@ -887,8 +882,6 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna struct failed_struct* failed; unsigned* failed_map; unsigned l; - char esc_buffer[ESC_MAX]; - char esc_buffer_alt[ESC_MAX]; bit_vect_t* block_enabled; struct snapraid_bw bw; @@ -1062,7 +1055,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = handle_close(&handle[j]); if (ret == -1) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), i, disk->name, esc_tag(report->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), i, disk->name, esc_tag(report->sub), strerror(errno)); log_fatal_errno(errno, disk->name); log_fatal(errno, "Stopping at block %u\n", i); @@ -1077,7 +1070,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = handle_create(&handle[j], file, state->file_mode); if (ret == -1) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Create error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Create error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); log_fatal(errno, "Stopping at block %u\n", i); @@ -1112,7 +1105,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna failed[failed_count].handle = &handle[j]; ++failed_count; - log_tag("%s:%u:%s:%s: Open error at position %u. %s.\n", es(errno), i, disk->name, esc_tag(file->sub, esc_buffer), file_pos, strerror(errno)); + log_tag("%s:%u:%s:%s: Open error at position %u. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), file_pos, strerror(errno)); if (is_hw(errno)) { ++io_error; @@ -1150,14 +1143,14 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna && handle[j].st.st_size > file->size ) { log_error(ESOFT, "File '%s' is larger than expected.\n", handle[j].path); - log_tag("error:%u:%s:%s: Size error\n", i, disk->name, esc_tag(file->sub, esc_buffer)); + log_tag("error:%u:%s:%s: Size error\n", i, disk->name, esc_tag(file->sub)); ++soft_error; if (fix) { ret = handle_truncate(&handle[j], file); if (ret == -1) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Truncate error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Truncate error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); log_fatal(errno, "Stopping at block %u\n", i); @@ -1166,7 +1159,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* LCOV_EXCL_STOP */ } - log_tag("fixed:%u:%s:%s: Fixed size\n", i, disk->name, esc_tag(file->sub, esc_buffer)); + log_tag("fixed:%u:%s:%s: Fixed size\n", i, disk->name, esc_tag(file->sub)); ++recovered_error; } } @@ -1197,7 +1190,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna failed[failed_count].handle = &handle[j]; ++failed_count; - log_tag("%s:%u:%s:%s: Read error at position %u. %s.\n", es(errno), i, disk->name, esc_tag(file->sub, esc_buffer), file_pos, strerror(errno)); + log_tag("%s:%u:%s:%s: Read error at position %u. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), file_pos, strerror(errno)); if (is_hw(errno)) { ++io_error; @@ -1256,7 +1249,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna failed[failed_count].handle = &handle[j]; ++failed_count; - log_tag("error:%u:%s:%s: Data error at position %u, diff hash bits %u/%u\n", i, disk->name, esc_tag(file->sub, esc_buffer), file_pos, diff, BLOCK_HASH_SIZE * 8); + log_tag("error:%u:%s:%s: Data error at position %u, diff hash bits %u/%u\n", i, disk->name, esc_tag(file->sub), file_pos, diff, BLOCK_HASH_SIZE * 8); ++silent_error; continue; } @@ -1323,7 +1316,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) - log_tag("unrecoverable:%u:%s:%s: Unrecoverable error at position %u\n", i, failed[j].disk->name, esc_tag(failed[j].file->sub, esc_buffer), failed[j].file_pos); + log_tag("unrecoverable:%u:%s:%s: Unrecoverable error at position %u\n", i, failed[j].disk->name, esc_tag(failed[j].file->sub), failed[j].file_pos); } /* keep track of damaged files */ @@ -1341,7 +1334,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; - log_tag("unrecoverable:%u:%s:%s: Unrecoverable unsynced error at position %u\n", i, failed[j].disk->name, esc_tag(failed[j].file->sub, esc_buffer), failed[j].file_pos); + log_tag("unrecoverable:%u:%s:%s: Unrecoverable unsynced error at position %u\n", i, failed[j].disk->name, esc_tag(failed[j].file->sub), failed[j].file_pos); } } if (partial_recover_error != 0) { @@ -1389,7 +1382,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna ret = handle_write(failed[j].handle, failed[j].file_pos, buffer[failed[j].index], state->block_size); if (ret == -1) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Write error. %s.\n", es(errno), i, failed[j].disk->name, esc_tag(failed[j].file->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Write error. %s.\n", es(errno), i, failed[j].disk->name, esc_tag(failed[j].file->sub), strerror(errno)); log_fatal_errno(errno, failed[j].disk->name); log_fatal(errno, "Stopping at block %u\n", i); @@ -1412,7 +1405,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(failed[j].file, FILE_IS_FIXED); - log_tag("fixed:%u:%s:%s: Fixed data error at position %u\n", i, failed[j].disk->name, esc_tag(failed[j].file->sub, esc_buffer), failed[j].file_pos); + log_tag("fixed:%u:%s:%s: Fixed data error at position %u\n", i, failed[j].disk->name, esc_tag(failed[j].file->sub), failed[j].file_pos); ++recovered_error; } @@ -1547,7 +1540,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna unsuccessful = 1; log_error(errno, "Error stating empty file '%s'. %s.\n", path, strerror(errno)); - log_tag("empty_%s:%s:%s: Empty file stat error\n", es(errno), disk->name, esc_tag(file->sub, esc_buffer)); + log_tag("empty_%s:%s:%s: Empty file stat error\n", es(errno), disk->name, esc_tag(file->sub)); if (is_hw(errno)) { ++io_error; @@ -1558,13 +1551,13 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna unsuccessful = 1; log_error(ESOFT, "Error stating empty file '%s' for not regular file.\n", path); - log_tag("empty_error:%s:%s: Empty file error for not regular file\n", disk->name, esc_tag(file->sub, esc_buffer)); + log_tag("empty_error:%s:%s: Empty file error for not regular file\n", disk->name, esc_tag(file->sub)); ++soft_error; } else if (st.st_size != 0) { unsuccessful = 1; log_error(ESOFT, "Error stating empty file '%s' for not empty file.\n", path); - log_tag("empty_error:%s:%s: Empty file error for size '%" PRIu64 "'\n", disk->name, esc_tag(file->sub, esc_buffer), (uint64_t)st.st_size); + log_tag("empty_error:%s:%s: Empty file error for size '%" PRIu64 "'\n", disk->name, esc_tag(file->sub), (uint64_t)st.st_size); ++soft_error; } @@ -1576,7 +1569,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret != 0) { /* LCOV_EXCL_START */ log_fatal(errno, "Error creating ancestor '%s%s'. %s.\n", disk->dir, file->sub, strerror(errno)); - log_tag("empty_%s:%u:%s:%s: Create ancestor error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); + log_tag("empty_%s:%u:%s:%s: Create ancestor error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); log_fatal(errno, "Stopping\n"); @@ -1591,7 +1584,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (f == -1) { /* LCOV_EXCL_START */ log_fatal(errno, "Error creating '%s%s'. %s.\n", disk->dir, file->sub, strerror(errno)); - log_tag("empty_%s:%u:%s:%s: Create error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); + log_tag("empty_%s:%u:%s:%s: Create error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); log_fatal(errno, "Stopping\n"); @@ -1605,7 +1598,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret != 0) { /* LCOV_EXCL_START */ log_fatal(errno, "Error timing '%s%s'. %s.\n", disk->dir, file->sub, strerror(errno)); - log_tag("empty_%s:%u:%s:%s: Time error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); + log_tag("empty_%s:%u:%s:%s: Time error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); log_fatal(errno, "Stopping\n"); @@ -1621,7 +1614,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret != 0) { /* LCOV_EXCL_START */ log_fatal(errno, "Error closing '%s%s'. %s.\n", disk->dir, file->sub, strerror(errno)); - log_tag("empty_%s:%u:%s:%s: Close error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); + log_tag("empty_%s:%u:%s:%s: Close error. %s.\n", es(errno), i, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); log_fatal(errno, "Stopping\n"); @@ -1630,11 +1623,11 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* LCOV_EXCL_STOP */ } - log_tag("empty_fixed:%s:%s: Fixed empty file\n", disk->name, esc_tag(file->sub, esc_buffer)); + log_tag("empty_fixed:%s:%s: Fixed empty file\n", disk->name, esc_tag(file->sub)); ++recovered_error; - log_tag("status:recovered:%s:%s\n", disk->name, esc_tag(file->sub, esc_buffer)); - msg_info("recovered %s\n", fmt_term(disk, file->sub, esc_buffer)); + log_tag("status:recovered:%s:%s\n", disk->name, esc_tag(file->sub)); + msg_info("recovered %s\n", fmt_term(disk, file->sub)); } } @@ -1667,7 +1660,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna unsuccessful = 1; log_error(errno, "Error stating hardlink '%s'. %s.\n", path, strerror(errno)); - log_tag("hardlink_%s:%s:%s:%s: Hardlink stat error. %s.\n", es(errno), disk->name, esc_tag(slink->sub, esc_buffer), esc_tag(slink->linkto, esc_buffer_alt), strerror(errno)); + log_tag("hardlink_%s:%s:%s:%s: Hardlink stat error. %s.\n", es(errno), disk->name, esc_tag(slink->sub), esc_tag(slink->linkto), strerror(errno)); if (is_hw(errno)) { ++io_error; @@ -1678,7 +1671,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna unsuccessful = 1; log_error(ESOFT, "Error stating hardlink '%s' for not regular file.\n", path); - log_tag("hardlink_error:%s:%s:%s: Hardlink error for not regular file\n", disk->name, esc_tag(slink->sub, esc_buffer), esc_tag(slink->linkto, esc_buffer_alt)); + log_tag("hardlink_error:%s:%s:%s: Hardlink error for not regular file\n", disk->name, esc_tag(slink->sub), esc_tag(slink->linkto)); ++soft_error; } @@ -1701,7 +1694,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna } log_error(errno, "Error stating hardlink-to '%s'. %s.\n", pathto, strerror(errno)); - log_tag("hardlink_%s:%s:%s:%s: Hardlink to stat error. %s.\n", es(errno), disk->name, esc_tag(slink->sub, esc_buffer), esc_tag(slink->linkto, esc_buffer_alt), strerror(errno)); + log_tag("hardlink_%s:%s:%s:%s: Hardlink to stat error. %s.\n", es(errno), disk->name, esc_tag(slink->sub), esc_tag(slink->linkto), strerror(errno)); if (is_hw(errno)) { ++io_error; @@ -1712,13 +1705,13 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna unsuccessful = 1; log_error(ESOFT, "Error stating hardlink-to '%s' for not regular file.\n", path); - log_tag("hardlink_error:%s:%s:%s: Hardlink-to error for not regular file\n", disk->name, esc_tag(slink->sub, esc_buffer), esc_tag(slink->linkto, esc_buffer_alt)); + log_tag("hardlink_error:%s:%s:%s: Hardlink-to error for not regular file\n", disk->name, esc_tag(slink->sub), esc_tag(slink->linkto)); ++soft_error; } else if (!unsuccessful && st.st_ino != stto.st_ino) { unsuccessful = 1; log_error(ESOFT, "Mismatch hardlink '%s' and '%s'. Different inode.\n", path, pathto); - log_tag("hardlink_error:%s:%s:%s: Hardlink mismatch for different inode\n", disk->name, esc_tag(slink->sub, esc_buffer), esc_tag(slink->linkto, esc_buffer_alt)); + log_tag("hardlink_error:%s:%s:%s: Hardlink mismatch for different inode\n", disk->name, esc_tag(slink->sub), esc_tag(slink->linkto)); ++soft_error; } } else { @@ -1729,7 +1722,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna unsuccessful = 1; log_error(errno, "Error reading symlink '%s'. %s.\n", path, strerror(errno)); - log_tag("symlink_%s:%s:%s: Symlink read error. %s.\n", es(errno), disk->name, esc_tag(slink->sub, esc_buffer), strerror(errno)); + log_tag("symlink_%s:%s:%s: Symlink read error. %s.\n", es(errno), disk->name, esc_tag(slink->sub), strerror(errno)); if (is_hw(errno)) { ++io_error; @@ -1740,7 +1733,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna unsuccessful = 1; log_error(ESOFT, "Error reading symlink '%s'. Symlink too long.\n", path); - log_tag("symlink_error:%s:%s: Symlink too long\n", disk->name, esc_tag(slink->sub, esc_buffer)); + log_tag("symlink_error:%s:%s: Symlink too long\n", disk->name, esc_tag(slink->sub)); ++soft_error; } else { linkto[ret] = 0; @@ -1748,7 +1741,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (strcmp(linkto, slink->linkto) != 0) { unsuccessful = 1; - log_tag("symlink_error:%s:%s: Symlink data error '%s' instead of '%s'\n", disk->name, esc_tag(slink->sub, esc_buffer), linkto, slink->linkto); + log_tag("symlink_error:%s:%s: Symlink data error '%s' instead of '%s'\n", disk->name, esc_tag(slink->sub), linkto, slink->linkto); ++soft_error; } } @@ -1762,7 +1755,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret != 0) { /* LCOV_EXCL_START */ log_fatal(errno, "Error creating ancestor '%s%s'. %s.\n", disk->dir, slink->sub, strerror(errno)); - log_tag("%slink_%s:%u:%s:%s: Create ancestor error. %s.\n", link, es(errno), i, disk->name, esc_tag(slink->sub, esc_buffer), strerror(errno)); + log_tag("%slink_%s:%u:%s:%s: Create ancestor error. %s.\n", link, es(errno), i, disk->name, esc_tag(slink->sub), strerror(errno)); log_fatal_errno(errno, disk->name); log_fatal(errno, "Stopping\n"); @@ -1776,7 +1769,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret != 0 && errno != ENOENT) { /* LCOV_EXCL_START */ log_fatal(errno, "Error removing '%s%s'. %s.\n", disk->dir, slink->sub, strerror(errno)); - log_tag("%slink_%s:%u:%s:%s: Remove error. %s.\n", link, es(errno), i, disk->name, esc_tag(slink->sub, esc_buffer), strerror(errno)); + log_tag("%slink_%s:%u:%s:%s: Remove error. %s.\n", link, es(errno), i, disk->name, esc_tag(slink->sub), strerror(errno)); log_fatal_errno(errno, disk->name); log_fatal(errno, "Stopping\n"); @@ -1791,7 +1784,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret != 0) { /* LCOV_EXCL_START */ log_fatal(errno, "Error writing hardlink '%s' to '%s'. %s.\n", path, pathto, strerror(errno)); - log_tag("hardlink_%s:%u:%s:%s: Hardlink error. %s.\n", es(errno), i, disk->name, esc_tag(slink->sub, esc_buffer), strerror(errno)); + log_tag("hardlink_%s:%u:%s:%s: Hardlink error. %s.\n", es(errno), i, disk->name, esc_tag(slink->sub), strerror(errno)); log_fatal_errno(errno, disk->name); log_fatal(errno, "Stopping\n"); @@ -1800,14 +1793,14 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* LCOV_EXCL_STOP */ } - log_tag("hardlink_fixed:%s:%s: Fixed hardlink error\n", disk->name, esc_tag(slink->sub, esc_buffer)); + log_tag("hardlink_fixed:%s:%s: Fixed hardlink error\n", disk->name, esc_tag(slink->sub)); ++recovered_error; } else { ret = symlink(slink->linkto, path); if (ret != 0) { /* LCOV_EXCL_START */ log_fatal(errno, "Error writing symlink '%s' to '%s'. %s.\n", path, slink->linkto, strerror(errno)); - log_tag("symlink_%s:%u:%s:%s: Hardlink error. %s.\n", es(errno), i, disk->name, esc_tag(slink->sub, esc_buffer), strerror(errno)); + log_tag("symlink_%s:%u:%s:%s: Hardlink error. %s.\n", es(errno), i, disk->name, esc_tag(slink->sub), strerror(errno)); log_fatal_errno(errno, disk->name); log_fatal(errno, "Stopping\n"); @@ -1816,12 +1809,12 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* LCOV_EXCL_STOP */ } - log_tag("symlink_fixed:%s:%s: Fixed symlink error\n", disk->name, esc_tag(slink->sub, esc_buffer)); + log_tag("symlink_fixed:%s:%s: Fixed symlink error\n", disk->name, esc_tag(slink->sub)); ++recovered_error; } - log_tag("status:recovered:%s:%s\n", disk->name, esc_tag(slink->sub, esc_buffer)); - msg_info("recovered %s\n", fmt_term(disk, slink->sub, esc_buffer)); + log_tag("status:recovered:%s:%s\n", disk->name, esc_tag(slink->sub)); + msg_info("recovered %s\n", fmt_term(disk, slink->sub)); } } @@ -1849,7 +1842,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna unsuccessful = 1; log_error(errno, "Error stating dir '%s'. %s.\n", path, strerror(errno)); - log_tag("dir_%s:%s:%s: Dir stat error. %s.\n", es(errno), disk->name, esc_tag(dir->sub, esc_buffer), strerror(errno)); + log_tag("dir_%s:%s:%s: Dir stat error. %s.\n", es(errno), disk->name, esc_tag(dir->sub), strerror(errno)); if (is_hw(errno)) { ++io_error; @@ -1859,7 +1852,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna } else if (!S_ISDIR(st.st_mode)) { unsuccessful = 1; - log_tag("dir_error:%s:%s: Dir error for not directory\n", disk->name, esc_tag(dir->sub, esc_buffer)); + log_tag("dir_error:%s:%s: Dir error for not directory\n", disk->name, esc_tag(dir->sub)); ++soft_error; } @@ -1869,7 +1862,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret != 0) { /* LCOV_EXCL_START */ log_fatal(errno, "Error creating ancestor '%s%s'. %s.\n", disk->dir, dir->sub, strerror(errno)); - log_tag("dir_%s:%u:%s:%s: Create ancestor error. %s.\n", es(errno), i, disk->name, esc_tag(dir->sub, esc_buffer), strerror(errno)); + log_tag("dir_%s:%u:%s:%s: Create ancestor error. %s.\n", es(errno), i, disk->name, esc_tag(dir->sub), strerror(errno)); log_fatal_errno(errno, disk->name); log_fatal(errno, "Stopping\n"); @@ -1883,7 +1876,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna if (ret != 0 && errno != EEXIST) { /* LCOV_EXCL_START */ log_fatal(errno, "Error creating directory '%s%s'. %s.\n", disk->dir, dir->sub, strerror(errno)); - log_tag("dir_%s:%u:%s:%s: Create directory error. %s.\n", es(errno), i, disk->name, esc_tag(dir->sub, esc_buffer), strerror(errno)); + log_tag("dir_%s:%u:%s:%s: Create directory error. %s.\n", es(errno), i, disk->name, esc_tag(dir->sub), strerror(errno)); log_fatal_errno(errno, disk->name); log_fatal(errno, "Stopping\n"); @@ -1892,11 +1885,11 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna /* LCOV_EXCL_STOP */ } - log_tag("dir_fixed:%s:%s: Fixed dir error\n", disk->name, esc_tag(dir->sub, esc_buffer)); + log_tag("dir_fixed:%s:%s: Fixed dir error\n", disk->name, esc_tag(dir->sub)); ++recovered_error; - log_tag("status:recovered:%s:%s\n", disk->name, esc_tag(dir->sub, esc_buffer)); - msg_info("recovered %s\n", fmt_term(disk, dir->sub, esc_buffer)); + log_tag("status:recovered:%s:%s\n", disk->name, esc_tag(dir->sub)); + msg_info("recovered %s\n", fmt_term(disk, dir->sub)); } } } @@ -1912,7 +1905,7 @@ bail: ret = handle_close(&handle[j]); if (ret == -1) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockmax, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockmax, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); ++unrecoverable_error; @@ -1963,7 +1956,7 @@ bail: if (ret != 0) { /* LCOV_EXCL_START */ log_fatal(errno, "Error removing '%s'. %s.\n", path, strerror(errno)); - log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockmax, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockmax, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); ++unrecoverable_error; diff --git a/cmdline/device.c b/cmdline/device.c index ddc4eec1..c6a77acf 100644 --- a/cmdline/device.c +++ b/cmdline/device.c @@ -510,17 +510,15 @@ static double raid_prob_of_one_or_more_failures(double array_failure_rate, doubl static void state_info_log(devinfo_t* devinfo) { - char esc_buffer[ESC_MAX]; - log_tag("info:%s:%s\n", devinfo->file, devinfo->name); if (devinfo->serial[0]) - log_tag("attr:%s:%s:serial:%s\n", devinfo->file, devinfo->name, esc_tag(devinfo->serial, esc_buffer)); + log_tag("attr:%s:%s:serial:%s\n", devinfo->file, devinfo->name, esc_tag(devinfo->serial)); if (devinfo->family[0]) - log_tag("attr:%s:%s:family:%s\n", devinfo->file, devinfo->name, esc_tag(devinfo->family, esc_buffer)); + log_tag("attr:%s:%s:family:%s\n", devinfo->file, devinfo->name, esc_tag(devinfo->family)); if (devinfo->model[0]) - log_tag("attr:%s:%s:model:%s\n", devinfo->file, devinfo->name, esc_tag(devinfo->model, esc_buffer)); + log_tag("attr:%s:%s:model:%s\n", devinfo->file, devinfo->name, esc_tag(devinfo->model)); if (devinfo->interf[0]) - log_tag("attr:%s:%s:interface:%s\n", devinfo->file, devinfo->name, esc_tag(devinfo->interf, esc_buffer)); + log_tag("attr:%s:%s:interface:%s\n", devinfo->file, devinfo->name, esc_tag(devinfo->interf)); if (devinfo->info[INFO_SIZE] != SMART_UNASSIGNED) log_tag("attr:%s:%s:size:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->info[INFO_SIZE]); if (devinfo->info[INFO_ROTATION_RATE] != SMART_UNASSIGNED) diff --git a/cmdline/dry.c b/cmdline/dry.c index 040eb2e8..566db530 100644 --- a/cmdline/dry.c +++ b/cmdline/dry.c @@ -31,8 +31,6 @@ static void dry_data_reader(struct snapraid_worker* worker, struct snapraid_task block_off_t blockcur = task->position; unsigned char* buffer = task->buffer; int ret; - char esc_buffer[ESC_MAX]; - /* if the disk position is not used */ if (!disk) { /* use an empty block */ @@ -64,7 +62,7 @@ static void dry_data_reader(struct snapraid_worker* worker, struct snapraid_task /* LCOV_EXCL_START */ /* This one is really an unexpected error, because we are only reading */ /* and closing a descriptor should never fail */ - log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockcur, disk->name, esc_tag(report->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockcur, disk->name, esc_tag(report->sub), strerror(errno)); log_fatal_errno(errno, disk->name); log_fatal(errno, "Stopping at block %u\n", blockcur); @@ -80,7 +78,7 @@ static void dry_data_reader(struct snapraid_worker* worker, struct snapraid_task ret = handle_open(handle, task->file, state->file_mode, log_error, 0); /* for missing file don't output a message */ if (ret == -1) { - log_tag("%s:%u:%s:%s: Open error. %s.\n", es(errno), blockcur, disk->name, esc_tag(task->file->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Open error. %s.\n", es(errno), blockcur, disk->name, esc_tag(task->file->sub), strerror(errno)); if (is_hw(errno)) { /* LCOV_EXCL_START */ log_fatal_errno(errno, disk->name); @@ -96,7 +94,7 @@ static void dry_data_reader(struct snapraid_worker* worker, struct snapraid_task task->read_size = handle_read(handle, task->file_pos, buffer, state->block_size, log_error, 0); if (task->read_size == -1) { - log_tag("%s:%u:%s:%s: Read error at position %u. %s.\n", es(errno), blockcur, disk->name, esc_tag(task->file->sub, esc_buffer), task->file_pos, strerror(errno)); + log_tag("%s:%u:%s:%s: Read error at position %u. %s.\n", es(errno), blockcur, disk->name, esc_tag(task->file->sub), task->file_pos, strerror(errno)); if (is_hw(errno)) { /* LCOV_EXCL_START */ log_error_errno(errno, disk->name); @@ -161,8 +159,6 @@ static int state_dry_process(struct snapraid_state* state, struct snapraid_parit unsigned l; unsigned* waiting_map; unsigned waiting_mac; - char esc_buffer[ESC_MAX]; - handle = handle_mapping(state, &diskmax); /* we need 1 * data + 2 * parity */ @@ -370,7 +366,7 @@ bail: ret = handle_close(&handle[j]); if (ret == -1) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockcur, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockcur, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); if (is_hw(errno)) { diff --git a/cmdline/dup.c b/cmdline/dup.c index d59f7571..ab734b5b 100644 --- a/cmdline/dup.c +++ b/cmdline/dup.c @@ -79,9 +79,6 @@ void state_dup(struct snapraid_state* state) tommy_node* i; unsigned count; data_off_t size; - char esc_buffer[ESC_MAX]; - char esc_buffer_alt[ESC_MAX]; - tommy_hashdyn_init(&hashset); count = 0; @@ -116,8 +113,8 @@ void state_dup(struct snapraid_state* state) if (found) { ++count; size += found->file->size; - log_tag("dup:%s:%s:%s:%s:%" PRIu64 ": dup\n", disk->name, esc_tag(file->sub, esc_buffer), found->disk->name, esc_tag(found->file->sub, esc_buffer_alt), found->file->size); - printf("%12" PRIu64 " %s = %s\n", file->size, fmt_term(disk, file->sub, esc_buffer), fmt_term(found->disk, found->file->sub, esc_buffer_alt)); + log_tag("dup:%s:%s:%s:%s:%" PRIu64 ": dup\n", disk->name, esc_tag(file->sub), found->disk->name, esc_tag(found->file->sub), found->file->size); + printf("%12" PRIu64 " %s = %s\n", file->size, fmt_term(disk, file->sub), fmt_term(found->disk, found->file->sub)); hash_free(hash); } else { tommy_hashdyn_insert(&hashset, &hash->node, hash, hash32); diff --git a/cmdline/elem.c b/cmdline/elem.c index 36854e51..d260e001 100644 --- a/cmdline/elem.c +++ b/cmdline/elem.c @@ -1547,32 +1547,32 @@ int FMT_MODE = FMT_FILE; /** * Format a file path for poll reference */ -const char* fmt_poll(const struct snapraid_disk* disk, const char* str, char* buffer) +const char* fmt_poll(const struct snapraid_disk* disk, const char* str) { (void)disk; - return esc_shell(str, buffer); + return esc_shell(str, esc_buf()); } /** * Format a path name for terminal reference */ -const char* fmt_term(const struct snapraid_disk* disk, const char* str, char* buffer) +const char* fmt_term(const struct snapraid_disk* disk, const char* str) { const char* out[3]; switch (FMT_MODE) { case FMT_FILE : default : - return esc_shell(str, buffer); + return esc_shell(str, esc_buf()); case FMT_DISK : out[0] = disk->name; out[1] = ":"; out[2] = str; - return esc_shell_multi(out, 3, buffer); + return esc_shell_multi(out, 3, esc_buf()); case FMT_PATH : out[0] = disk->dir; out[1] = str; - return esc_shell_multi(out, 2, buffer); + return esc_shell_multi(out, 2, esc_buf()); } } diff --git a/cmdline/elem.h b/cmdline/elem.h index 9bb08e75..6c8e616f 100644 --- a/cmdline/elem.h +++ b/cmdline/elem.h @@ -1314,12 +1314,12 @@ extern int FMT_MODE; /** * Format a file path for poll reference */ -const char* fmt_poll(const struct snapraid_disk* disk, const char* str, char* buffer); +const char* fmt_poll(const struct snapraid_disk* disk, const char* str); /** * Format a path name for terminal reference */ -const char* fmt_term(const struct snapraid_disk* disk, const char* str, char* buffer); +const char* fmt_term(const struct snapraid_disk* disk, const char* str); /** * Format a size adding suffix K/M/G/T diff --git a/cmdline/list.c b/cmdline/list.c index df7bf6e8..fc41435b 100644 --- a/cmdline/list.c +++ b/cmdline/list.c @@ -18,9 +18,6 @@ void state_list(struct snapraid_state* state) unsigned file_count; data_off_t file_size; unsigned link_count; - char esc_buffer[ESC_MAX]; - char esc_buffer_alt[ESC_MAX]; - file_count = 0; file_size = 0; link_count = 0; @@ -48,7 +45,7 @@ void state_list(struct snapraid_state* state) file_size += file->size; if (state->opt.gui_verbose) - log_tag("file:%s:%s:%" PRIu64 ":%" PRIi64 ":%u:%" PRIu64 "\n", disk->name, esc_tag(file->sub, esc_buffer), file->size, file->mtime_sec, file->mtime_nsec, file->inode); + log_tag("file:%s:%s:%" PRIu64 ":%" PRIi64 ":%u:%" PRIu64 "\n", disk->name, esc_tag(file->sub), file->size, file->mtime_sec, file->mtime_nsec, file->inode); t = file->mtime_sec; #if HAVE_LOCALTIME_R @@ -64,7 +61,7 @@ void state_list(struct snapraid_state* state) printf(":%02u.%09u", tm->tm_sec, file->mtime_nsec); printf(" "); } - printf("%s\n", fmt_term(disk, file->sub, esc_buffer)); + printf("%s\n", fmt_term(disk, file->sub)); } /* sort by name */ @@ -88,13 +85,13 @@ void state_list(struct snapraid_state* state) ++link_count; if (state->opt.gui_verbose) - log_tag("link_%s:%s:%s:%s\n", type, disk->name, esc_tag(slink->sub, esc_buffer), esc_tag(slink->linkto, esc_buffer_alt)); + log_tag("link_%s:%s:%s:%s\n", type, disk->name, esc_tag(slink->sub), esc_tag(slink->linkto)); printf("%12s ", type); printf(" "); if (msg_level >= MSG_VERBOSE) printf(" "); - printf("%s -> %s\n", fmt_term(disk, slink->sub, esc_buffer), fmt_term(disk, slink->linkto, esc_buffer_alt)); + printf("%s -> %s\n", fmt_term(disk, slink->sub), fmt_term(disk, slink->linkto)); } } diff --git a/cmdline/locate.c b/cmdline/locate.c index c3fc42cb..07493aac 100644 --- a/cmdline/locate.c +++ b/cmdline/locate.c @@ -46,12 +46,11 @@ static int parity_entry_compare(const void* void_a, const void* void_b) static void dump_entry(void* void_entry) { - char esc_buffer[ESC_MAX]; struct snapraid_parity_entry* entry = void_entry; printf("%12" PRIu64 " ", entry->low * (uint64_t)entry->block_size); printf("%12" PRIu64 " ", (entry->high - entry->low + 1) * (uint64_t)entry->block_size); printf("%8u ", entry->fragments); - printf("%s\n", fmt_term(entry->disk, entry->file->sub, esc_buffer)); + printf("%s\n", fmt_term(entry->disk, entry->file->sub)); } static void add_size_to_sum(void* arg, void* void_entry) diff --git a/cmdline/mingw.c b/cmdline/mingw.c index 944f4005..1293b5c9 100644 --- a/cmdline/mingw.c +++ b/cmdline/mingw.c @@ -3225,13 +3225,11 @@ int devmap(void) h = CreateFileW(convert(conv_buf, wfile), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, 0); if (h == INVALID_HANDLE_VALUE) continue; - - char esc_buffer[ESC_MAX]; char serial[SMART_MAX]; serial[0] = 0; devattr_property(h, serial, 0, 0); if (serial[0]) { - log_tag("map:/dev/pd%d:%s\n", i, esc_tag(serial, esc_buffer)); + log_tag("map:/dev/pd%d:%s\n", i, esc_tag(serial)); } CloseHandle(h); diff --git a/cmdline/mingw.h b/cmdline/mingw.h index fb14489a..1ea1f4a4 100644 --- a/cmdline/mingw.h +++ b/cmdline/mingw.h @@ -393,6 +393,7 @@ typedef void* windows_key_t; #define thread_id_t windows_thread_t #define thread_mutex_t windows_mutex_t #define thread_cond_t windows_cond_t +#define thread_key_t windows_key_t #define pthread_mutex_init windows_mutex_init #define pthread_mutex_destroy windows_mutex_destroy #define pthread_mutex_lock windows_mutex_lock @@ -404,6 +405,10 @@ typedef void* windows_key_t; #define pthread_cond_wait windows_cond_wait #define pthread_create windows_create #define pthread_join windows_join +#define pthread_key_create windows_key_create +#define pthread_key_delete windows_key_delete +#define pthread_getspecific windows_getspecific +#define pthread_setspecific windows_setspecific /** * Like the pthread_* equivalent. diff --git a/cmdline/parity.c b/cmdline/parity.c index 989faae1..17c9ed9b 100644 --- a/cmdline/parity.c +++ b/cmdline/parity.c @@ -75,8 +75,6 @@ void parity_overflow(struct snapraid_state* state, data_off_t size) tommy_node* i; block_off_t blockalloc; int found = 0; - char esc_buffer[ESC_MAX]; - /* don't report if everything is outside or if the file is not accessible */ if (size == 0) { return; @@ -97,7 +95,7 @@ void parity_overflow(struct snapraid_state* state, data_off_t size) block_off_t parity_pos = fs_file2par_get(disk, file, file->blockmax - 1); if (parity_pos >= blockalloc) { found = 1; - log_tag("outofparity:%s:%s\n", disk->name, esc_tag(file->sub, esc_buffer)); + log_tag("outofparity:%s:%s\n", disk->name, esc_tag(file->sub)); log_fatal(ESOFT, "outofparity %s%s\n", disk->dir, file->sub); } } diff --git a/cmdline/scan.c b/cmdline/scan.c index 9a7049df..8b80e1f4 100644 --- a/cmdline/scan.c +++ b/cmdline/scan.c @@ -142,8 +142,6 @@ static void scan_link(struct snapraid_scan* scan, int is_diff, const char* sub, struct snapraid_state* state = scan->state; struct snapraid_disk* disk = scan->disk; struct snapraid_link* slink; - char esc_buffer[ESC_MAX]; - /* check if the link already exists */ slink = tommy_hashdyn_search(&disk->linkset, link_name_compare_to_arg, sub, link_name_hash(sub)); if (slink) { @@ -164,7 +162,7 @@ static void scan_link(struct snapraid_scan* scan, int is_diff, const char* sub, ++scan->count_equal; if (state->opt.gui_verbose) { - log_tag("scan:equal:%s:%s\n", disk->name, esc_tag(slink->sub, esc_buffer)); + log_tag("scan:equal:%s:%s\n", disk->name, esc_tag(slink->sub)); } } else { /* it's an update */ @@ -174,9 +172,9 @@ static void scan_link(struct snapraid_scan* scan, int is_diff, const char* sub, ++scan->count_change; - log_tag("scan:update:%s:%s\n", disk->name, esc_tag(slink->sub, esc_buffer)); + log_tag("scan:update:%s:%s\n", disk->name, esc_tag(slink->sub)); if (is_diff) { - msg_info("update %s\n", fmt_term(disk, slink->sub, esc_buffer)); + msg_info("update %s\n", fmt_term(disk, slink->sub)); } /* update it */ @@ -191,9 +189,9 @@ static void scan_link(struct snapraid_scan* scan, int is_diff, const char* sub, /* create the new link */ ++scan->count_insert; - log_tag("scan:add:%s:%s\n", disk->name, esc_tag(sub, esc_buffer)); + log_tag("scan:add:%s:%s\n", disk->name, esc_tag(sub)); if (is_diff) { - msg_info("add %s\n", fmt_term(disk, sub, esc_buffer)); + msg_info("add %s\n", fmt_term(disk, sub)); } /* and continue to insert it */ @@ -390,7 +388,6 @@ static void scan_file_deallocate(struct snapraid_scan* scan, struct snapraid_fil static void scan_file_delayed_allocate(struct snapraid_scan* scan, struct snapraid_file* file) { - char esc_buffer[ESC_MAX]; struct snapraid_state* state = scan->state; struct snapraid_disk* disk = scan->disk; @@ -404,7 +401,7 @@ static void scan_file_delayed_allocate(struct snapraid_scan* scan, struct snapra if (filephy(path_next, file->size, &file->physical) != 0) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: File physycal offset error. %s.\n", es(errno), 0, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: File physycal offset error. %s.\n", es(errno), 0, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal(errno, "Error in getting the physical offset of file '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -525,7 +522,6 @@ static int file_is_full_hashed_and_stable(struct snapraid_state* state, struct s static void scan_file_refresh(struct snapraid_scan* scan, const char* sub, struct stat* st, uint64_t* physical) { #if HAVE_LSTAT_SYNC - char esc_buffer[ESC_MAX]; struct snapraid_state* state = scan->state; struct snapraid_disk* disk = scan->disk; @@ -547,7 +543,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 */ - log_tag("%s:%u:%s:%s: Stat error. %s.\n", es(errno), 0, disk->name, esc_tag(path_next, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Stat error. %s.\n", es(errno), 0, disk->name, esc_tag(path_next), strerror(errno)); log_fatal(errno, "Error in stat file '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -570,7 +566,7 @@ 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 */ - log_tag("%s:%u:%s:%s: Uncached time change error.\n", es(ESOFT), 0, disk->name, esc_tag(sub, esc_buffer)); + log_tag("%s:%u:%s:%s: Uncached time change error.\n", es(ESOFT), 0, disk->name, esc_tag(sub)); log_fatal(ESOFT, "WARNING! Detected uncached time change from %" PRIu64 ".%09u to %" PRIu64 ".%09u for file '%s'\n", (uint64_t)st->st_mtime, (uint32_t)st->st_mtimensec, (uint64_t)synced_st.st_mtime, (uint32_t)synced_st.st_mtimensec, sub); log_fatal(ESOFT, "It's better if you run SnapRAID without other processes running.\n"); @@ -581,7 +577,7 @@ static void scan_file_refresh(struct snapraid_scan* scan, const char* sub, struc if (st->st_size != synced_st.st_size) { #ifndef _WIN32 - log_tag("%s:%u:%s:%s: Uncached size change error.\n", es(ESOFT), 0, disk->name, esc_tag(sub, esc_buffer)); + log_tag("%s:%u:%s:%s: Uncached size change error.\n", es(ESOFT), 0, disk->name, esc_tag(sub)); log_fatal(ESOFT, "WARNING! Detected uncached size change from %" PRIu64 " to %" PRIu64 " for file '%s'\n", (uint64_t)st->st_size, (uint64_t)synced_st.st_size, sub); log_fatal(ESOFT, "It's better if you run SnapRAID without other processes running.\n"); @@ -591,7 +587,7 @@ static void scan_file_refresh(struct snapraid_scan* scan, const char* sub, struc if (st->st_nlink != synced_st.st_nlink) { #ifndef _WIN32 - log_tag("%s:%u:%s:%s: Uncached nlink change error.\n", es(ESOFT), 0, disk->name, esc_tag(sub, esc_buffer)); + log_tag("%s:%u:%s:%s: Uncached nlink change error.\n", es(ESOFT), 0, disk->name, esc_tag(sub)); log_fatal(ESOFT, "WARNING! Detected uncached nlink change from %u to %u for file '%s'\n", (uint32_t)st->st_nlink, (uint32_t)synced_st.st_nlink, sub); log_fatal(ESOFT, "It's better if you run SnapRAID without other processes running.\n"); @@ -600,7 +596,7 @@ static void scan_file_refresh(struct snapraid_scan* scan, const char* sub, struc } if (st->st_ino != synced_st.st_ino) { - log_tag("%s:%u:%s:%s: Uncached inode change error.\n", es(ESOFT), 0, disk->name, esc_tag(sub, esc_buffer)); + log_tag("%s:%u:%s:%s: Uncached inode change error.\n", es(ESOFT), 0, disk->name, esc_tag(sub)); log_fatal(ESOFT, "DANGER! Detected uncached inode change from %" PRIu64 " to %" PRIu64 " for file '%s'\n", (uint64_t)st->st_ino, (uint64_t)synced_st.st_ino, sub); log_fatal(ESOFT, "It's better if you run SnapRAID without other processes running.\n"); @@ -702,9 +698,6 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, int64_t file_already_present_mtime_sec; int file_already_present_mtime_nsec; int is_file_reported; - char esc_buffer[ESC_MAX]; - char esc_buffer_alt[ESC_MAX]; - /* * If the disk has persistent inodes and UUID, try a search on the past inodes, * to detect moved files. @@ -784,9 +777,9 @@ 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; - log_tag("scan:move:%s:%s:%s\n", disk->name, esc_tag(file->sub, esc_buffer), esc_tag(sub, esc_buffer_alt)); + log_tag("scan:move:%s:%s:%s\n", disk->name, esc_tag(file->sub), esc_tag(sub)); if (is_diff) { - msg_info("move %s -> %s\n", fmt_term(disk, file->sub, esc_buffer), fmt_term(disk, sub, esc_buffer_alt)); + msg_info("move %s -> %s\n", fmt_term(disk, file->sub), fmt_term(disk, sub)); } /* remove from the name set */ @@ -805,7 +798,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, ++scan->count_equal; if (state->opt.gui_verbose) { - log_tag("scan:equal:%s:%s\n", disk->name, esc_tag(file->sub, esc_buffer)); + log_tag("scan:equal:%s:%s\n", disk->name, esc_tag(file->sub)); } } @@ -947,9 +940,9 @@ 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; - log_tag("scan:restore:%s:%s\n", disk->name, esc_tag(sub, esc_buffer)); + log_tag("scan:restore:%s:%s\n", disk->name, esc_tag(sub)); if (is_diff) { - msg_info("restore %s\n", fmt_term(disk, sub, esc_buffer)); + msg_info("restore %s\n", fmt_term(disk, sub)); } /* remove from the inode set */ @@ -970,7 +963,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, ++scan->count_equal; if (state->opt.gui_verbose) { - log_tag("scan:equal:%s:%s\n", disk->name, esc_tag(file->sub, esc_buffer)); + log_tag("scan:equal:%s:%s\n", disk->name, esc_tag(file->sub)); } } @@ -1015,7 +1008,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, /* LCOV_EXCL_START */ log_fatal(ESOFT, "The file '%s%s' has unexpected zero size!\n", disk->dir, sub); log_fatal(ESOFT, "It's possible that after a kernel crash this file was lost,\n"); - log_fatal(ESOFT, "and you can use 'snapraid fix -f /%s' to recover it.\n", fmt_poll(disk, sub, esc_buffer)); + log_fatal(ESOFT, "and you can use 'snapraid fix -f /%s' to recover it.\n", fmt_poll(disk, sub)); if (!is_diff) { log_fatal(ESOFT, "If this an expected condition you can '%s' anyway using 'snapraid --force-zero %s'\n", state->command, state->command); exit(EXIT_FAILURE); @@ -1080,16 +1073,16 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, if (lstat(path_other, &other_st) == 0) { ++scan->count_copy; - log_tag("scan:copy:%s:%s:%s:%s\n", other_disk->name, esc_tag(other_file->sub, esc_buffer), disk->name, esc_tag(file->sub, esc_buffer_alt)); + log_tag("scan:copy:%s:%s:%s:%s\n", other_disk->name, esc_tag(other_file->sub), disk->name, esc_tag(file->sub)); if (is_diff) { - msg_info("copy %s -> %s\n", fmt_term(other_disk, other_file->sub, esc_buffer), fmt_term(disk, file->sub, esc_buffer_alt)); + msg_info("copy %s -> %s\n", fmt_term(other_disk, other_file->sub), fmt_term(disk, file->sub)); } } else { ++scan->count_relocate; - log_tag("scan:relocate:%s:%s:%s:%s\n", other_disk->name, esc_tag(other_file->sub, esc_buffer), disk->name, esc_tag(file->sub, esc_buffer_alt)); + log_tag("scan:relocate:%s:%s:%s:%s\n", other_disk->name, esc_tag(other_file->sub), disk->name, esc_tag(file->sub)); if (is_diff) { - msg_info("relocate %s -> %s\n", fmt_term(other_disk, other_file->sub, esc_buffer), fmt_term(disk, file->sub, esc_buffer_alt)); + msg_info("relocate %s -> %s\n", fmt_term(other_disk, other_file->sub), fmt_term(disk, file->sub)); } } @@ -1108,20 +1101,20 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, if (is_file_already_present) { ++scan->count_change; - log_tag("scan:update:%s:%s: %" PRIu64 " %" PRIu64 ".%d -> %" PRIu64 " %" PRIu64 ".%d\n", disk->name, esc_tag(sub, esc_buffer), + log_tag("scan:update:%s:%s: %" PRIu64 " %" PRIu64 ".%d -> %" PRIu64 " %" PRIu64 ".%d\n", disk->name, esc_tag(sub), file_already_present_size, file_already_present_mtime_sec, file_already_present_mtime_nsec, file->size, file->mtime_sec, file->mtime_nsec ); if (is_diff) { - msg_info("update %s\n", fmt_term(disk, sub, esc_buffer)); + msg_info("update %s\n", fmt_term(disk, sub)); } } else { ++scan->count_insert; - log_tag("scan:add:%s:%s\n", disk->name, esc_tag(sub, esc_buffer)); + log_tag("scan:add:%s:%s\n", disk->name, esc_tag(sub)); if (is_diff) { - msg_info("add %s\n", fmt_term(disk, sub, esc_buffer)); + msg_info("add %s\n", fmt_term(disk, sub)); } } } @@ -1253,10 +1246,9 @@ struct stat* dstat(struct dirent_sorted* dd) #define DSTAT(file, dd, buf) dstat(disk, file, buf) struct stat* dstat(struct snapraid_disk* disk, const char* file, struct stat* st) { - char esc_buffer[ESC_MAX]; if (lstat(file, st) != 0) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Stat error. %s.\n", es(errno), 0, disk->name, esc_tag(file, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Stat error. %s.\n", es(errno), 0, disk->name, esc_tag(file), strerror(errno)); log_fatal(errno, "Error in stat file/directory '%s'. %s.\n", file, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -1271,7 +1263,6 @@ struct stat* dstat(struct snapraid_disk* disk, const char* file, struct stat* st */ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* path_next, char* sub_next, char* tmp) { - char esc_buffer[ESC_MAX]; struct snapraid_state* state = scan->state; struct snapraid_disk* disk = scan->disk; int processed = 0; @@ -1289,7 +1280,7 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa d = opendir(path_next); if (!d) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Open dir error. %s.\n", es(errno), 0, disk->name, esc_tag(path_next, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Open dir error. %s.\n", es(errno), 0, disk->name, esc_tag(path_next), strerror(errno)); log_fatal(errno, "Error opening directory '%s'. %s.\n", path_next, strerror(errno)); if (level == 0) log_fatal(errno, "If this is the disk mount point, remember to create it manually\n"); @@ -1320,7 +1311,7 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa /* restore removing additions */ path_next[path_len] = 0; sub_next[sub_len] = 0; - log_tag("%s:%u:%s:%s: Read dir error. %s.\n", es(errno), 0, disk->name, esc_tag(path_next, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Read dir error. %s.\n", es(errno), 0, disk->name, esc_tag(path_next), strerror(errno)); log_fatal(errno, "Error reading directory '%s'. %s.\n", path_next, strerror(errno)); log_fatal(errno, "You can exclude it in the config file with: exclude /%s\n", sub_next); exit(EXIT_FAILURE); @@ -1340,7 +1331,7 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa /* check for not supported file names */ if (name[0] == 0) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Unsupported name error.\n", es(ESOFT), 0, disk->name, esc_tag(path_next, esc_buffer)); + log_tag("%s:%u:%s:%s: Unsupported name error.\n", es(ESOFT), 0, disk->name, esc_tag(path_next)); log_fatal(ESOFT, "Unsupported name '%s' in file '%s'.\n", name, path_next); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -1388,7 +1379,7 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa /* LCOV_EXCL_START */ /* restore removing additions */ path_next[path_len] = 0; - log_tag("%s:%u:%s:%s: Close dir error. %s.\n", es(errno), 0, disk->name, esc_tag(path_next, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Close dir error. %s.\n", es(errno), 0, disk->name, esc_tag(path_next), strerror(errno)); log_fatal(errno, "Error closing directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -1453,7 +1444,7 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa if (st->st_mode == 0) { if (lstat(path_next, st) != 0) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Stat error. %s.\n", es(errno), 0, disk->name, esc_tag(path_next, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Stat error. %s.\n", es(errno), 0, disk->name, esc_tag(path_next), strerror(errno)); log_fatal(errno, "Error in stat file/directory '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -1485,7 +1476,7 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa if (st->st_ino == 0 || st->st_nlink == 0) { if (lstat_sync(path_next, st, 0) != 0) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Stat error. %s.\n", es(errno), 0, disk->name, esc_tag(path_next, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Stat error. %s.\n", es(errno), 0, disk->name, esc_tag(path_next), strerror(errno)); log_fatal(errno, "Error in stat file '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -1506,14 +1497,14 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa ret = readlink(path_next, tmp, PATH_MAX); if (ret >= PATH_MAX) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Readlink error. %s.\n", es(errno), 0, disk->name, esc_tag(path_next, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Readlink error. %s.\n", es(errno), 0, disk->name, esc_tag(path_next), strerror(errno)); log_fatal(EINTERNAL, "Error in readlink file '%s'. Symlink too long.\n", path_next); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } if (ret < 0) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Readlink error. %s.\n", es(errno), 0, disk->name, esc_tag(path_next, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Readlink error. %s.\n", es(errno), 0, disk->name, esc_tag(path_next), strerror(errno)); log_fatal(errno, "Error in readlink file '%s'. %s.\n", path_next, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -1543,7 +1534,7 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa * in Windows we are already skipping them reporting them as special files */ if ((uint64_t)st->st_dev != disk->device) { - log_tag("%s:%u:%s:%s: Ignoring mount point.\n", es(ESOFT), 0, disk->name, esc_tag(path_next, esc_buffer)); + log_tag("%s:%u:%s:%s: Ignoring mount point.\n", es(ESOFT), 0, disk->name, esc_tag(path_next)); log_fatal(ESOFT, "WARNING! Ignoring mount point '%s' because it appears to be in a different device\n", path_next); } else #endif @@ -1570,7 +1561,7 @@ static int scan_sub(struct snapraid_scan* scan, int level, int is_diff, char* pa if (!st) st = DSTAT(path_next, dd, &st_buf); - log_tag("%s:%u:%s:%s: Ignoring special file.\n", es(ESOFT), 0, disk->name, esc_tag(path_next, esc_buffer)); + log_tag("%s:%u:%s:%s: Ignoring special file.\n", es(ESOFT), 0, disk->name, esc_tag(path_next)); log_fatal(ESOFT, "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, tmp, PATH_MAX)); @@ -1606,7 +1597,6 @@ static int scan_dir(struct snapraid_scan* scan, int level, int is_diff, const ch static void* scan_disk(void* arg) { - char esc_buffer[ESC_MAX]; struct snapraid_scan* scan = arg; struct snapraid_disk* disk = scan->disk; int ret; @@ -1618,7 +1608,7 @@ static void* scan_disk(void* arg) ret = fsinfo(disk->dir, &has_persistent_inodes, &has_syncronized_hardlinks, 0, 0, 0, 0, 0, 0); if (ret < 0) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Filesystem info error. %s.\n", es(errno), 0, disk->name, esc_tag(disk->dir, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Filesystem info error. %s.\n", es(errno), 0, disk->name, esc_tag(disk->dir), strerror(errno)); log_fatal(errno, "Error accessing disk '%s' to get file-system info. %s.\n", disk->dir, strerror(errno)); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ @@ -1672,8 +1662,6 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) msg_ptr* msg; struct snapraid_scan total; int no_difference; - char esc_buffer[ESC_MAX]; - tommy_list_init(&scanlist); if (is_diff) @@ -1745,9 +1733,9 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) if (!file_flag_has(file, FILE_IS_RELOCATED)) { ++scan->count_remove; - log_tag("scan:remove:%s:%s\n", disk->name, esc_tag(file->sub, esc_buffer)); + log_tag("scan:remove:%s:%s\n", disk->name, esc_tag(file->sub)); if (is_diff) { - msg_info("remove %s\n", fmt_term(disk, file->sub, esc_buffer)); + msg_info("remove %s\n", fmt_term(disk, file->sub)); } } @@ -1767,9 +1755,9 @@ static int state_diffscan(struct snapraid_state* state, int is_diff) if (!link_flag_has(slink, FILE_IS_PRESENT)) { ++scan->count_remove; - log_tag("scan:remove:%s:%s\n", disk->name, esc_tag(slink->sub, esc_buffer)); + log_tag("scan:remove:%s:%s\n", disk->name, esc_tag(slink->sub)); if (is_diff) { - msg_info("remove %s\n", fmt_term(disk, slink->sub, esc_buffer)); + msg_info("remove %s\n", fmt_term(disk, slink->sub)); } scan_link_remove(scan, slink); diff --git a/cmdline/scrub.c b/cmdline/scrub.c index 72d24a36..04ae6e4c 100644 --- a/cmdline/scrub.c +++ b/cmdline/scrub.c @@ -103,8 +103,6 @@ static void scrub_data_reader(struct snapraid_worker* worker, struct snapraid_ta block_off_t blockcur = task->position; unsigned char* buffer = task->buffer; int ret; - char esc_buffer[ESC_MAX]; - /* if the disk position is not used */ if (!disk) { /* use an empty block */ @@ -136,7 +134,7 @@ static void scrub_data_reader(struct snapraid_worker* worker, struct snapraid_ta /* LCOV_EXCL_START */ /* This one is really an unexpected error, because we are only reading */ /* and closing a descriptor should never fail */ - log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockcur, disk->name, esc_tag(report->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockcur, disk->name, esc_tag(report->sub), strerror(errno)); log_fatal_errno(errno, disk->name); log_fatal(errno, "Stopping at block %u\n", blockcur); @@ -152,7 +150,7 @@ static void scrub_data_reader(struct snapraid_worker* worker, struct snapraid_ta ret = handle_open(handle, task->file, state->file_mode, log_error, 0); /* for missing file don't output a message */ if (ret == -1) { - log_tag("%s:%u:%s:%s: Open error. %s.\n", es(errno), blockcur, disk->name, esc_tag(task->file->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Open error. %s.\n", es(errno), blockcur, disk->name, esc_tag(task->file->sub), strerror(errno)); if (is_hw(errno)) { /* LCOV_EXCL_START */ log_fatal_errno(errno, disk->name); @@ -183,7 +181,7 @@ static void scrub_data_reader(struct snapraid_worker* worker, struct snapraid_ta task->read_size = handle_read(handle, task->file_pos, buffer, state->block_size, log_error, 0); if (task->read_size == -1) { - log_tag("%s:%u:%s:%s: Read error at position %u. %s.\n", es(errno), blockcur, disk->name, esc_tag(task->file->sub, esc_buffer), task->file_pos, strerror(errno)); + log_tag("%s:%u:%s:%s: Read error at position %u. %s.\n", es(errno), blockcur, disk->name, esc_tag(task->file->sub), task->file_pos, strerror(errno)); if (is_hw(errno)) { /* LCOV_EXCL_START */ log_error_errno(errno, disk->name); @@ -255,7 +253,6 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par unsigned l; unsigned* waiting_map; unsigned waiting_mac; - char esc_buffer[ESC_MAX]; bit_vect_t* block_enabled; /* maps the disks to handles */ @@ -476,11 +473,11 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par /* it's a silent error only if we are dealing with synced files */ if (file_is_unsynced) { - log_tag("error:%u:%s:%s: Data error at position %u, diff hash bits %u/%u\n", blockcur, disk->name, esc_tag(file->sub, esc_buffer), file_pos, diff, BLOCK_HASH_SIZE * 8); + log_tag("error:%u:%s:%s: Data error at position %u, diff hash bits %u/%u\n", blockcur, disk->name, esc_tag(file->sub), file_pos, diff, BLOCK_HASH_SIZE * 8); ++soft_error; error_on_this_block = 1; } else { - log_tag("error_data:%u:%s:%s: Data error at position %u, diff hash bits %u/%u\n", blockcur, disk->name, esc_tag(file->sub, esc_buffer), file_pos, diff, BLOCK_HASH_SIZE * 8); + log_tag("error_data:%u:%s:%s: Data error at position %u, diff hash bits %u/%u\n", blockcur, disk->name, esc_tag(file->sub), file_pos, diff, BLOCK_HASH_SIZE * 8); log_error(EDATA, "Data error in file '%s' at position '%u', diff hash bits %u/%u\n", task->path, file_pos, diff, BLOCK_HASH_SIZE * 8); ++silent_error; silent_error_on_this_block = 1; @@ -706,7 +703,7 @@ bail: ret = handle_close(&handle[j]); if (ret == -1) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockcur, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockcur, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); if (is_hw(errno)) { diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index b8bb4fa9..b421db44 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -106,15 +106,15 @@ void test(int argc, char* argv[]) assert(worddigitstr("needle2string", "needle") != 0); assert(worddigitstr("needle", "needle") != 0); - assert(strcmp(esc_tag("simple", buffer), "simple") == 0); - assert(strcmp(esc_tag("line1\nline2", buffer), "line1\\nline2") == 0); - assert(strcmp(esc_tag("line1\rline2", buffer), "line1\\rline2") == 0); - assert(strcmp(esc_tag("key:value", buffer), "key\\dvalue") == 0); - assert(strcmp(esc_tag("C:\\path\\file", buffer), "C\\d\\\\path\\\\file") == 0); - assert(strcmp(esc_tag("A\nB\rC:D\\E", buffer), "A\\nB\\rC\\dD\\\\E") == 0); - assert(strcmp(esc_tag("endwith\\", buffer), "endwith\\\\") == 0); - assert(strcmp(esc_tag("", buffer), "") == 0); - assert(strcmp(esc_tag("\n\r:\\\\", buffer), "\\n\\r\\d\\\\\\\\") == 0); + assert(strcmp(esc_tag("simple"), "simple") == 0); + assert(strcmp(esc_tag("line1\nline2"), "line1\\nline2") == 0); + assert(strcmp(esc_tag("line1\rline2"), "line1\\rline2") == 0); + assert(strcmp(esc_tag("key:value"), "key\\dvalue") == 0); + assert(strcmp(esc_tag("C:\\path\\file"), "C\\d\\\\path\\\\file") == 0); + assert(strcmp(esc_tag("A\nB\rC:D\\E"), "A\\nB\\rC\\dD\\\\E") == 0); + assert(strcmp(esc_tag("endwith\\"), "endwith\\\\") == 0); + assert(strcmp(esc_tag(""), "") == 0); + assert(strcmp(esc_tag("\n\r:\\\\"), "\\n\\r\\d\\\\\\\\") == 0); for (i = 2; i < argc; ++i) { printf("argv[%d]\n", i); @@ -935,7 +935,6 @@ void signal_init(void) int snapraid_main(int argc, char* argv[]) { - char esc_buffer[ESC_MAX]; int c; struct snapraid_option opt; char conf[PATH_MAX]; @@ -1750,7 +1749,7 @@ int snapraid_main(int argc, char* argv[]) } log_tag("command:%s\n", command); for (i = 0; i < argc; ++i) - log_tag("argv:%u:%s\n", i, esc_tag(argv[i], esc_buffer)); + log_tag("argv:%u:%s\n", i, esc_tag(argv[i])); log_flush(); if (!opt.skip_self) diff --git a/cmdline/state.c b/cmdline/state.c index a1ca4e41..3c4a4ced 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -546,9 +546,6 @@ void state_config(struct snapraid_state* state, const char* path, const char* co unsigned line; tommy_node* i; unsigned l, s; - char esc_buffer[ESC_MAX]; - char esc_buffer1[ESC_MAX]; - /* copy the options */ state->opt = *opt; @@ -567,7 +564,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co /* store current command */ state->command = command; - log_tag("conf:file:%s\n", esc_tag(path, esc_buffer)); + log_tag("conf:file:%s\n", esc_tag(path)); f = sopen_read(path, 0); if (!f) { @@ -1482,30 +1479,30 @@ void state_config(struct snapraid_state* state, const char* path, const char* co log_tag("blocksize:%u\n", state->block_size); for (i = state->disklist; i != 0; i = i->next) { struct snapraid_disk* disk = i->data; - log_tag("data:%s:%s:%s\n", esc_tag(disk->name, esc_buffer), esc_tag(disk->dir, esc_buffer1), disk->uuid); + log_tag("data:%s:%s:%s\n", esc_tag(disk->name), esc_tag(disk->dir), disk->uuid); } for (i = state->extralist; i != 0; i = i->next) { struct snapraid_extra* extra = i->data; - log_tag("extra:%s:%s:%s\n", esc_tag(extra->name, esc_buffer), esc_tag(extra->dir, esc_buffer1), extra->uuid); + log_tag("extra:%s:%s:%s\n", esc_tag(extra->name), esc_tag(extra->dir), extra->uuid); } log_tag("mode:%s\n", lev_raid_name(state->raid_mode, state->level)); for (l = 0; l < state->level; ++l) { - log_tag("%s:%s:%s\n", lev_config_name(l), esc_tag(state->parity[l].split_map[0].path, esc_buffer), state->parity[l].split_map[0].uuid); + log_tag("%s:%s:%s\n", lev_config_name(l), esc_tag(state->parity[l].split_map[0].path), state->parity[l].split_map[0].uuid); for (s = 1; s < state->parity[l].split_mac; ++s) { - log_tag("%s/%u:%s:%s\n", lev_config_name(l), s, esc_tag(state->parity[l].split_map[s].path, esc_buffer), state->parity[l].split_map[s].uuid); + log_tag("%s/%u:%s:%s\n", lev_config_name(l), s, esc_tag(state->parity[l].split_map[s].path), state->parity[l].split_map[s].uuid); } } if (state->pool[0] != 0) - log_tag("pool:%s\n", esc_tag(state->pool, esc_buffer)); + log_tag("pool:%s\n", esc_tag(state->pool)); if (state->share[0] != 0) - log_tag("share:%s\n", esc_tag(state->share, esc_buffer)); + log_tag("share:%s\n", esc_tag(state->share)); if (state->autosave != 0) 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; - log_tag("filter:%s\n", esc_tag(filter_type(filter, out, sizeof(out)), esc_buffer)); + log_tag("filter:%s\n", esc_tag(filter_type(filter, out, sizeof(out)))); } if (state->filter_hidden) log_tag("filter:nohidden:\n"); @@ -1785,7 +1782,6 @@ static void state_map(struct snapraid_state* state) void state_refresh(struct snapraid_state* state) { - char esc_buffer[ESC_MAX]; tommy_node* i; unsigned l, s; uint64_t bs = (uint64_t)state->block_size; @@ -1825,8 +1821,8 @@ void state_refresh(struct snapraid_state* state) disk->total_blocks = map->total_blocks; disk->free_blocks = map->free_blocks; - log_tag("fsinfo_data_split:%s:%" PRIu64 ":%" PRIu64 ":%s:%s\n", esc_tag(disk->name, esc_buffer), disk->total_blocks * bs, disk->free_blocks * bs, disk->fstype, disk->fslabel); - log_tag("fsinfo_data:%s:%" PRIu64 ":%" PRIu64 "\n", esc_tag(disk->name, esc_buffer), disk->total_blocks * bs, disk->free_blocks * bs); + log_tag("fsinfo_data_split:%s:%" PRIu64 ":%" PRIu64 ":%s:%s\n", esc_tag(disk->name), disk->total_blocks * bs, disk->free_blocks * bs, disk->fstype, disk->fslabel); + log_tag("fsinfo_data:%s:%" PRIu64 ":%" PRIu64 "\n", esc_tag(disk->name), disk->total_blocks * bs, disk->free_blocks * bs); } /* for all parities */ @@ -1894,7 +1890,7 @@ void state_refresh(struct snapraid_state* state) /* LCOV_EXCL_STOP */ } - log_tag("fsinfo_extra:%s:%" PRIu64 ":%" PRIu64 "\n", esc_tag(extra->name, esc_buffer), total_space, free_space); + log_tag("fsinfo_extra:%s:%" PRIu64 ":%" PRIu64 "\n", esc_tag(extra->name), total_space, free_space); } @@ -2091,7 +2087,6 @@ static void decoding_error(const char* path, STREAM* f) static void state_read_content(struct snapraid_state* state, const char* path, STREAM* f) { - char esc_buffer[ESC_MAX]; block_off_t blockmax; unsigned count_file; unsigned count_hardlink; @@ -2926,7 +2921,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S } log_tag("content_data:%s:%" PRIi64 ":%" PRIi64 "\n", - esc_tag(buffer, esc_buffer), + esc_tag(buffer), v_total_blocks * (uint64_t)state->block_size, v_free_blocks * (uint64_t)state->block_size); } else { @@ -2944,7 +2939,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S } log_tag("content_data_split:%s:%s\n", - esc_tag(buffer, esc_buffer), + esc_tag(buffer), uuid); /* find the disk */ @@ -3051,7 +3046,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S log_tag("content_parity_split:%s:%s:%s:%" PRIi64 "\n", lev_config_name(v_level), /* P command always has a single split */ state->parity[v_level].split_map[0].uuid, - esc_tag(state->parity[v_level].split_map[0].path, esc_buffer), + esc_tag(state->parity[v_level].split_map[0].path), state->parity[v_level].split_map[0].size); } } else if (c == 'Q') { @@ -3193,7 +3188,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S log_tag("content_parity_split:%s:%s:%s:%" PRIi64 "\n", parity_name, state->parity[v_level].split_map[s].uuid, - esc_tag(state->parity[v_level].split_map[s].path, esc_buffer), + esc_tag(state->parity[v_level].split_map[s].path), state->parity[v_level].split_map[s].size); } } @@ -3327,7 +3322,6 @@ struct state_write_thread_context { static void* state_write_thread(void* arg) { - char esc_buffer[ESC_MAX]; struct state_write_thread_context* context = arg; struct snapraid_state* state = context->state; block_off_t blockmax = context->blockmax; @@ -3454,11 +3448,11 @@ static void* state_write_thread(void* arg) sputbs(map->uuid, f); if (context->first) { log_tag("content_data:%s:%" PRIi64 ":%" PRIi64 "\n", - esc_tag(map->name, esc_buffer), + esc_tag(map->name), map->total_blocks * (uint64_t)state->block_size, map->free_blocks * (uint64_t)state->block_size); log_tag("content_data_split:%s:%s\n", - esc_tag(map->name, esc_buffer), + esc_tag(map->name), map->uuid); } if (serror(f)) { @@ -3949,11 +3943,10 @@ static void state_write_content(struct snapraid_state* state, uint32_t* out_crc) struct snapraid_content* content = i->data; struct state_write_thread_context* context; char tmp[PATH_MAX]; - char esc_buffer[ESC_MAX]; STREAM* f; msg_progress("Saving state to %s...\n", content->content); - log_tag("content_write:%s\n", esc_tag(content->content, esc_buffer)); + log_tag("content_write:%s\n", esc_tag(content->content)); pathprint(tmp, sizeof(tmp), "%s.tmp", content->content); @@ -4308,8 +4301,7 @@ void state_read(struct snapraid_state* state) } if (!state->no_conf) { - char esc_buffer[ESC_MAX]; - log_tag("content:%s\n", esc_tag(path, esc_buffer)); + log_tag("content:%s\n", esc_tag(path)); log_tag("content_info:read_unixtime:%" PRId64 "\n", (int64_t)st.st_mtime); log_flush(); } @@ -5442,7 +5434,6 @@ void generate_configuration(const char* path) { struct snapraid_state state; struct snapraid_content* content; - char esc_buffer[ESC_MAX]; unsigned l, s; tommy_node* j; @@ -5510,7 +5501,7 @@ void generate_configuration(const char* path) if (disk && disk->filelist) { struct snapraid_file* file = disk->filelist->data; if (file) { - printf("# and containing: %s\n", fmt_poll(disk, file->sub, esc_buffer)); + printf("# and containing: %s\n", fmt_poll(disk, file->sub)); } } printf("data %s ENTER_HERE_THE_DIR\n", map->name); diff --git a/cmdline/support.c b/cmdline/support.c index f2cff668..8635d518 100644 --- a/cmdline/support.c +++ b/cmdline/support.c @@ -5,6 +5,45 @@ #include "support.h" +/****************************************************************************/ +/* esc */ + +struct esc_thread_pool { + char pool[ESC_POOL_MAX][ESC_MAX]; + unsigned idx; +}; + +#if HAVE_THREAD +static thread_key_t esc_key; + +static void esc_pool_free(void* ptr) +{ + free(ptr); +} +#else +static struct esc_thread_pool esc_single_pool; +#endif + +char* esc_buf(void) +{ + struct esc_thread_pool* tp; + +#if HAVE_THREAD + tp = thread_getspecific(esc_key); + if (!tp) { + tp = calloc_nofail(1, sizeof(*tp)); + thread_setspecific(esc_key, tp); + } +#else + tp = &esc_single_pool; +#endif + + char* buffer = tp->pool[tp->idx]; + tp->idx = (tp->idx + 1) % ESC_POOL_MAX; + + return buffer; +} + /****************************************************************************/ /* lock */ @@ -59,7 +98,6 @@ void unlock_random(void) #endif } - void lock_init(void) { #if HAVE_THREAD @@ -67,12 +105,19 @@ void lock_init(void) thread_mutex_init(&msg_lock); thread_mutex_init(&memory_lock); thread_mutex_init(&random_lock); + thread_key_create(&esc_key, esc_pool_free); #endif } void lock_done(void) { #if HAVE_THREAD + void* tp = thread_getspecific(esc_key); + if (tp) { + esc_pool_free(tp); + thread_setspecific(esc_key, NULL); + } + thread_key_delete(esc_key); thread_mutex_destroy(&msg_lock); thread_mutex_destroy(&memory_lock); thread_mutex_destroy(&random_lock); @@ -637,8 +682,9 @@ void printp(double v, size_t pad) *p++ = (c); \ } while (0) -const char* esc_tag(const char* str, char* buffer) +const char* esc_tag(const char* str) { + char* buffer = esc_buf(); char* begin = buffer; char* end = begin + ESC_MAX; char* p = begin; @@ -2565,6 +2611,26 @@ void thread_yield(void) } #endif +int thread_key_create(thread_key_t* key, void (*destructor)(void*)) +{ + return pthread_key_create(key, destructor); +} + +int thread_key_delete(thread_key_t key) +{ + return pthread_key_delete(key); +} + +void* thread_getspecific(thread_key_t key) +{ + return pthread_getspecific(key); +} + +int thread_setspecific(thread_key_t key, void* value) +{ + return pthread_setspecific(key, value); +} + /****************************************************************************/ /* wnmatch */ diff --git a/cmdline/support.h b/cmdline/support.h index 61653582..d841a36a 100644 --- a/cmdline/support.h +++ b/cmdline/support.h @@ -241,15 +241,19 @@ void printp(double v, size_t pad); /* string */ #define ESC_MAX (PATH_MAX * 2 + 1) +#define ESC_POOL_MAX 8 /** * Escape a string for the log. * - * \param buffer Preallocated buffer of ESC_MAX size. - * * Chars ':', '\n', '\r' and '\' are escaped to '\d', '\\n', '\\r' and '\\'. */ -const char* esc_tag(const char* str, char* buffer); +const char* esc_tag(const char* str); + +/** + * Get a dynamically allocated buffer of ESC_MAX size from a circular pool. + */ +char* esc_buf(void); /** * Escape a string for the shell. @@ -502,6 +506,10 @@ void thread_cond_broadcast_and_unlock(thread_cond_t* cond, thread_mutex_t* mutex void thread_create(thread_id_t* thread, void* (*func)(void*), void* arg); void thread_join(thread_id_t thread, void** retval); void thread_yield(void); +int thread_key_create(thread_key_t* key, void (*destructor)(void*)); +int thread_key_delete(thread_key_t key); +void* thread_getspecific(thread_key_t key); +int thread_setspecific(thread_key_t key, void* value); #endif /****************************************************************************/ diff --git a/cmdline/sync.c b/cmdline/sync.c index 0cc0dc27..1b47d071 100644 --- a/cmdline/sync.c +++ b/cmdline/sync.c @@ -37,8 +37,6 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta unsigned soft_error; unsigned silent_error; unsigned io_error; - char esc_buffer[ESC_MAX]; - /* maps the disks to handles */ handle = handle_mapping(state, &diskmax); @@ -137,7 +135,7 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta /* LCOV_EXCL_START */ /* This one is really an unexpected error, because we are only reading */ /* and closing a descriptor should never fail */ - log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockcur, disk->name, esc_tag(report->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockcur, disk->name, esc_tag(report->sub), strerror(errno)); log_fatal_errno(errno, disk->name); log_fatal(errno, "Stopping at block %u\n", blockcur); @@ -153,7 +151,7 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta ret = handle_open(&handle[j], file, state->file_mode, log_error, log_error); /* output a message for missing files */ if (ret == -1) { - log_tag("%s:%u:%s:%s: Open error. %s.\n", es(errno), blockcur, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Open error. %s.\n", es(errno), blockcur, disk->name, esc_tag(file->sub), strerror(errno)); if (errno == ENOENT) { log_error_errno(errno, disk->name); @@ -178,7 +176,7 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta log_fatal(errno, "Stopping at block %u\n", blockcur); ++io_error; } else { - log_fatal(errno, "Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", fmt_poll(disk, file->sub, esc_buffer)); + log_fatal(errno, "Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", fmt_poll(disk, file->sub)); ++soft_error; } goto bail; @@ -192,14 +190,14 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta || handle[j].st.st_ino != file->inode ) { if (handle[j].st.st_size != file->size) { - log_tag("error:%u:%s:%s: Unexpected size change\n", blockcur, disk->name, esc_tag(file->sub, esc_buffer)); + log_tag("error:%u:%s:%s: Unexpected size change\n", blockcur, disk->name, esc_tag(file->sub)); log_error(ESOFT, "Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle[j].path, file->size, (uint64_t)handle[j].st.st_size); } else if (handle[j].st.st_mtime != file->mtime_sec || STAT_NSEC(&handle[j].st) != file->mtime_nsec) { - log_tag("error:%u:%s:%s: Unexpected time change\n", blockcur, disk->name, esc_tag(file->sub, esc_buffer)); + log_tag("error:%u:%s:%s: Unexpected time change\n", blockcur, disk->name, esc_tag(file->sub)); log_error(ESOFT, "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, STAT_NSEC(&handle[j].st)); } else { - log_tag("error:%u:%s:%s: Unexpected inode change\n", blockcur, disk->name, esc_tag(file->sub, esc_buffer)); + log_tag("error:%u:%s:%s: Unexpected inode change\n", blockcur, disk->name, esc_tag(file->sub)); log_error(ESOFT, "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_errno(ENOENT, disk->name); /* same message for ENOENT */ @@ -214,14 +212,14 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta read_size = handle_read(&handle[j], file_pos, buffer, state->block_size, log_fatal, 0); if (read_size == -1) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Read error at position %u. %s.\n", es(errno), blockcur, disk->name, esc_tag(file->sub, esc_buffer), file_pos, strerror(errno)); + log_tag("%s:%u:%s:%s: Read error at position %u. %s.\n", es(errno), blockcur, disk->name, esc_tag(file->sub), file_pos, strerror(errno)); log_fatal_errno(errno, disk->name); if (is_hw(errno)) { log_fatal(errno, "Stopping at block %u\n", blockcur); ++io_error; } else { - log_fatal(errno, "Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", fmt_poll(disk, file->sub, esc_buffer)); + log_fatal(errno, "Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", fmt_poll(disk, file->sub)); ++soft_error; } goto bail; @@ -248,7 +246,7 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta if (block_state == BLOCK_STATE_REP) { /* compare the hash */ if (memcmp(hash, block->hash, BLOCK_HASH_SIZE) != 0) { - log_tag("error_data:%u:%s:%s: Unexpected data change\n", blockcur, disk->name, esc_tag(file->sub, esc_buffer)); + log_tag("error_data:%u:%s:%s: Unexpected data change\n", blockcur, disk->name, esc_tag(file->sub)); log_error(EDATA, "Data change at file '%s' at position '%u'\n", handle[j].path, file_pos); log_error(EDATA, "WARNING! Unexpected data modification of a file without parity!\n"); @@ -299,7 +297,7 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta /* LCOV_EXCL_START */ /* This one is really an unexpected error, because we are only reading */ /* and closing a descriptor should never fail */ - log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockmax, disk->name, esc_tag(report->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockmax, disk->name, esc_tag(report->sub), strerror(errno)); log_fatal_errno(errno, disk->name); log_fatal(errno, "Stopping at block %u\n", blockmax); @@ -346,7 +344,7 @@ bail: ret = handle_close(&handle[j]); if (ret == -1) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockcur, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockcur, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); if (is_hw(errno)) { @@ -462,8 +460,6 @@ static void sync_data_reader(struct snapraid_worker* worker, struct snapraid_tas block_off_t blockcur = task->position; unsigned char* buffer = task->buffer; int ret; - char esc_buffer[ESC_MAX]; - /* if the disk position is not used */ if (!disk) { /* use an empty block */ @@ -496,7 +492,7 @@ static void sync_data_reader(struct snapraid_worker* worker, struct snapraid_tas /* LCOV_EXCL_START */ /* This one is really an unexpected error, because we are only reading */ /* and closing a descriptor should never fail */ - log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockcur, disk->name, esc_tag(report->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockcur, disk->name, esc_tag(report->sub), strerror(errno)); log_fatal_errno(errno, disk->name); log_fatal(errno, "Stopping at block %u\n", blockcur); @@ -512,7 +508,7 @@ static void sync_data_reader(struct snapraid_worker* worker, struct snapraid_tas ret = handle_open(handle, task->file, state->file_mode, log_error, log_error); /* output a message for missing files */ if (ret == -1) { - log_tag("%s:%u:%s:%s: Open error. %s.\n", es(errno), blockcur, disk->name, esc_tag(task->file->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Open error. %s.\n", es(errno), blockcur, disk->name, esc_tag(task->file->sub), strerror(errno)); if (errno == ENOENT) { log_error_errno(errno, disk->name); @@ -537,7 +533,7 @@ static void sync_data_reader(struct snapraid_worker* worker, struct snapraid_tas log_fatal(errno, "Stopping at block %u\n", blockcur); task->state = TASK_STATE_IOERROR; } else { - log_fatal(errno, "Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", fmt_poll(disk, task->file->sub, esc_buffer)); + log_fatal(errno, "Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", fmt_poll(disk, task->file->sub)); task->state = TASK_STATE_ERROR; } return; @@ -550,7 +546,7 @@ static void sync_data_reader(struct snapraid_worker* worker, struct snapraid_tas || STAT_NSEC(&handle->st) != task->file->mtime_nsec || handle->st.st_ino != task->file->inode ) { - log_tag("error:%u:%s:%s: Unexpected attribute change\n", blockcur, disk->name, esc_tag(task->file->sub, esc_buffer)); + log_tag("error:%u:%s:%s: Unexpected attribute change\n", blockcur, disk->name, esc_tag(task->file->sub)); if (handle->st.st_size != task->file->size) { log_error(ESOFT, "Unexpected size change at file '%s' from %" PRIu64 " to %" PRIu64 ".\n", handle->path, task->file->size, (uint64_t)handle->st.st_size); } else if (handle->st.st_mtime != task->file->mtime_sec @@ -570,7 +566,7 @@ static void sync_data_reader(struct snapraid_worker* worker, struct snapraid_tas task->read_size = handle_read(handle, task->file_pos, buffer, state->block_size, log_error, 0); if (task->read_size == -1) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Read error at position %u. %s.\n", es(errno), blockcur, disk->name, esc_tag(task->file->sub, esc_buffer), task->file_pos, strerror(errno)); + log_tag("%s:%u:%s:%s: Read error at position %u. %s.\n", es(errno), blockcur, disk->name, esc_tag(task->file->sub), task->file_pos, strerror(errno)); if (is_hw(errno)) { log_error_errno(errno, disk->name); @@ -578,7 +574,7 @@ static void sync_data_reader(struct snapraid_worker* worker, struct snapraid_tas task->state = TASK_STATE_IOERROR_CONTINUE; } else { log_fatal_errno(errno, disk->name); - log_fatal(errno, "Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", fmt_poll(disk, task->file->sub, esc_buffer)); + log_fatal(errno, "Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", fmt_poll(disk, task->file->sub)); task->state = TASK_STATE_ERROR; } return; @@ -654,7 +650,6 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari unsigned l; unsigned* waiting_map; unsigned waiting_mac; - char esc_buffer[ESC_MAX]; bit_vect_t* block_enabled; /* the sync process assumes that all the hashes are correct */ @@ -919,7 +914,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari if (memcmp(hash, block->hash, BLOCK_HASH_SIZE) != 0) { /* if the file has invalid parity, it's a REP changed during the sync */ if (block_has_invalid_parity(block)) { - log_tag("error:%u:%s:%s: Unexpected data change\n", blockcur, disk->name, esc_tag(file->sub, esc_buffer)); + log_tag("error:%u:%s:%s: Unexpected data change\n", blockcur, disk->name, esc_tag(file->sub)); log_error(ESOFT, "Data change at file '%s' at position '%u'\n", task->path, file_pos); log_error(ESOFT, "WARNING! Unexpected data modification of a file without parity!\n"); @@ -940,7 +935,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari continue; } else { /* otherwise it's a BLK with silent error */ unsigned diff = memdiff(hash, block->hash, BLOCK_HASH_SIZE); - log_tag("error_data:%u:%s:%s: Data error at position %u, diff hash bits %u/%u\n", blockcur, disk->name, esc_tag(file->sub, esc_buffer), file_pos, diff, BLOCK_HASH_SIZE * 8); + log_tag("error_data:%u:%s:%s: Data error at position %u, diff hash bits %u/%u\n", blockcur, disk->name, esc_tag(file->sub), file_pos, diff, BLOCK_HASH_SIZE * 8); log_error(EDATA, "Data error in file '%s' at position '%u', diff hash bits %u/%u\n", task->path, file_pos, diff, BLOCK_HASH_SIZE * 8); /* save the failed block for the fix */ @@ -1390,7 +1385,7 @@ bail: ret = handle_close(&handle[j]); if (ret == -1) { /* LCOV_EXCL_START */ - log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockcur, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); + log_tag("%s:%u:%s:%s: Close error. %s.\n", es(errno), blockcur, disk->name, esc_tag(file->sub), strerror(errno)); log_fatal_errno(errno, disk->name); if (is_hw(errno)) { diff --git a/cmdline/touch.c b/cmdline/touch.c index 768c74ca..f709fca4 100644 --- a/cmdline/touch.c +++ b/cmdline/touch.c @@ -11,8 +11,6 @@ void state_touch(struct snapraid_state* state) { tommy_node* i; - char esc_buffer[ESC_MAX]; - msg_progress("Setting sub-second timestamps...\n"); /* for all disks */ @@ -123,8 +121,8 @@ void state_touch(struct snapraid_state* state) /* state changed, we need to update it */ state->need_write = 1; - log_tag("touch:%s:%s: %" PRIu64 ".%d\n", disk->name, esc_tag(file->sub, esc_buffer), (uint64_t)st.st_mtime, STAT_NSEC(&st)); - msg_info("touch %s\n", fmt_term(disk, file->sub, esc_buffer)); + log_tag("touch:%s:%s: %" PRIu64 ".%d\n", disk->name, esc_tag(file->sub), (uint64_t)st.st_mtime, STAT_NSEC(&st)); + msg_info("touch %s\n", fmt_term(disk, file->sub)); } } } diff --git a/cmdline/unix.c b/cmdline/unix.c index 2805f2c5..499b3c1c 100644 --- a/cmdline/unix.c +++ b/cmdline/unix.c @@ -2710,7 +2710,6 @@ int ambient_temperature(void) int devmap(void) { #if HAVE_LINUX_DEVICE - char esc_buffer[ESC_MAX]; char path[PATH_MAX]; DIR* d = opendir("/sys/block"); if (!d) @@ -2735,49 +2734,49 @@ int devmap(void) /* device/serial */ pathprint(path, sizeof(path), "/sys/block/%s/device/serial", dd->d_name); if (sysattr(path, buf, sizeof(buf)) == 0 && buf[0] != 0) { - log_tag("map:/dev/%s:%s\n", dd->d_name, esc_tag(buf, esc_buffer)); + log_tag("map:/dev/%s:%s\n", dd->d_name, esc_tag(buf)); } /* device/vpd_pg80 */ pathprint(path, sizeof(path), "/sys/block/%s/device/vpd_pg80", dd->d_name); if (sysattr_vpd_pg80(path, buf, sizeof(buf)) == 0 && buf[0] != 0) { - log_tag("map:/dev/%s:%s\n", dd->d_name, esc_tag(buf, esc_buffer)); + log_tag("map:/dev/%s:%s\n", dd->d_name, esc_tag(buf)); } /* device/vpd_pg83 */ pathprint(path, sizeof(path), "/sys/block/%s/device/vpd_pg83", dd->d_name); if (sysattr_vpd_pg83(path, buf, sizeof(buf)) == 0 && buf[0] != 0) { - log_tag("map:/dev/%s:naa.%s\n", dd->d_name, esc_tag(buf, esc_buffer)); + log_tag("map:/dev/%s:naa.%s\n", dd->d_name, esc_tag(buf)); } /* device/WWN */ pathprint(path, sizeof(path), "/sys/block/%s/device/wwn", dd->d_name); if (sysattr(path, buf, sizeof(buf)) == 0 && buf[0] != 0) { - log_tag("map:/dev/%s:%s\n", dd->d_name, esc_tag(buf, esc_buffer)); + log_tag("map:/dev/%s:%s\n", dd->d_name, esc_tag(buf)); } /* device/WWID */ pathprint(path, sizeof(path), "/sys/block/%s/device/wwid", dd->d_name); if (sysattr(path, buf, sizeof(buf)) == 0 && buf[0] != 0) { - log_tag("map:/dev/%s:%s\n", dd->d_name, esc_tag(buf, esc_buffer)); + log_tag("map:/dev/%s:%s\n", dd->d_name, esc_tag(buf)); } /* WWN */ pathprint(path, sizeof(path), "/sys/block/%s/wwn", dd->d_name); if (sysattr(path, buf, sizeof(buf)) == 0 && buf[0] != 0) { - log_tag("map:/dev/%s:%s\n", dd->d_name, esc_tag(buf, esc_buffer)); + log_tag("map:/dev/%s:%s\n", dd->d_name, esc_tag(buf)); } /* WWID */ pathprint(path, sizeof(path), "/sys/block/%s/wwid", dd->d_name); if (sysattr(path, buf, sizeof(buf)) == 0 && buf[0] != 0) { - log_tag("map:/dev/%s:%s\n", dd->d_name, esc_tag(buf, esc_buffer)); + log_tag("map:/dev/%s:%s\n", dd->d_name, esc_tag(buf)); } /* uuid */ pathprint(path, sizeof(path), "/sys/block/%s/uuid", dd->d_name); if (sysattr(path, buf, sizeof(buf)) == 0 && buf[0] != 0) { - log_tag("map:/dev/%s:%s\n", dd->d_name, esc_tag(buf, esc_buffer)); + log_tag("map:/dev/%s:%s\n", dd->d_name, esc_tag(buf)); } } diff --git a/cmdline/unix.h b/cmdline/unix.h index caadde30..eae9d416 100644 --- a/cmdline/unix.h +++ b/cmdline/unix.h @@ -66,6 +66,7 @@ size_t direct_size(void); typedef pthread_t thread_id_t; typedef pthread_mutex_t thread_mutex_t; typedef pthread_cond_t thread_cond_t; +typedef pthread_key_t thread_key_t; #endif #endif