diff --git a/cmdline/scan.c b/cmdline/scan.c index 405d3652..0ce1aea7 100644 --- a/cmdline/scan.c +++ b/cmdline/scan.c @@ -902,7 +902,7 @@ static void scan_file(struct snapraid_scan* scan, int is_diff, const char* sub, /* LCOV_EXCL_START */ log_fatal("The file '%s%s' has unexpected zero size!\n", disk->dir, sub); log_fatal("It's possible that after a kernel crash this file was lost,\n"); - log_fatal("and you can use 'snapraid fix -f %s' to recover it.\n", esc_shell('/', sub, esc_buffer)); + log_fatal("and you can use 'snapraid fix -f /%s' to recover it.\n", esc_shell(sub, esc_buffer)); if (!is_diff) { log_fatal("If this an expected condition you can '%s' anyway using 'snapraid --force-zero %s'\n", state->command, state->command); exit(EXIT_FAILURE); diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index 3f6ad431..6b70252d 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -101,17 +101,17 @@ void test(int argc, char* argv[]) for (i = 2; i < argc; ++i) { printf("argv[%d]\n", i); printf("\t#%s#\n", argv[i]); - printf("\t#%s#\n", esc_shell(0, argv[i], buffer)); + printf("\t#%s#\n", esc_shell(argv[i], buffer)); } #ifdef _WIN32 - assert(strcmp(esc_shell(0, " ", buffer), "\" \"") == 0); - assert(strcmp(esc_shell(0, " \" ", buffer), "\" \"\\\"\" \"") == 0); - assert(strcmp(esc_shell(0, "&|()<>^", buffer), "^&^|^(^)^<^>^^") == 0); - assert(strcmp(esc_shell(0, "&|()<>^ ", buffer), "\"&|()<>^ \"") == 0); + assert(strcmp(esc_shell(" ", buffer), "\" \"") == 0); + assert(strcmp(esc_shell(" \" ", buffer), "\" \"\\\"\" \"") == 0); + assert(strcmp(esc_shell("&|()<>^", buffer), "^&^|^(^)^<^>^^") == 0); + assert(strcmp(esc_shell("&|()<>^ ", buffer), "\"&|()<>^ \"") == 0); #else - assert(strcmp(esc_shell(0, ",._+:@%%/-", buffer), ",._+:@%%/-") == 0); - assert(strcmp(esc_shell(0, " ", buffer), "\\ ") == 0); + assert(strcmp(esc_shell(",._+:@%%/-", buffer), ",._+:@%%/-") == 0); + assert(strcmp(esc_shell(" ", buffer), "\\ ") == 0); #endif printf("Everything OK\n"); diff --git a/cmdline/support.c b/cmdline/support.c index 8ce078e3..86cca28b 100644 --- a/cmdline/support.c +++ b/cmdline/support.c @@ -430,7 +430,7 @@ bail: /* LCOV_EXCL_STOP */ } -const char* esc_shell(char prefix, const char* str, char* buffer) +const char* esc_shell(const char* str, char* buffer) { char* begin = buffer; char* end = begin + ESC_MAX; @@ -446,13 +446,6 @@ const char* esc_shell(char prefix, const char* str, char* buffer) } #endif - /* add the prefix char, if any */ - if (prefix) { - if (p == end) - goto bail; - *p++ = prefix; - } - /* copy string with escaping */ while (*str) { char c = *str; diff --git a/cmdline/support.h b/cmdline/support.h index d81d104f..4c09c802 100644 --- a/cmdline/support.h +++ b/cmdline/support.h @@ -227,10 +227,9 @@ const char* esc_tag(const char* str, char* buffer); /** * Escape a string for the shell. * - * \param prefix Char to prefix at the string. * \param buffer Preallocated buffer of ESC_MAX size. */ -const char* esc_shell(char prefix, const char* str, char* buffer); +const char* esc_shell(const char* str, char* buffer); /** * Polish a string. diff --git a/cmdline/sync.c b/cmdline/sync.c index f6066d68..3469ecb3 100644 --- a/cmdline/sync.c +++ b/cmdline/sync.c @@ -195,7 +195,7 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta log_tag("error:%u:%s:%s: Open error. %s\n", i, disk->name, esc_tag(file->sub, esc_buffer), strerror(errno)); log_fatal("WARNING! Unexpected open error in a data disk, it isn't possible to sync.\n"); log_fatal("Ensure that file '%s' can be accessed.\n", handle[j].path); - log_fatal("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", esc_shell('/', file->sub, esc_buffer)); + log_fatal("Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", esc_shell(file->sub, esc_buffer)); ++error; goto bail; /* LCOV_EXCL_STOP */ @@ -239,7 +239,7 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta log_tag("error:%u:%s:%s: Read error at position %u. %s\n", i, disk->name, esc_tag(file->sub, esc_buffer), file_pos, strerror(errno)); log_fatal("WARNING! Unexpected read error in a data disk, it isn't possible to sync.\n"); log_fatal("Ensure that file '%s' can be read.\n", handle[j].path); - log_fatal("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", esc_shell('/', file->sub, esc_buffer)); + log_fatal("Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", esc_shell(file->sub, esc_buffer)); ++error; goto bail; /* LCOV_EXCL_STOP */ @@ -571,7 +571,7 @@ static void sync_data_reader(struct snapraid_worker* worker, struct snapraid_tas log_tag("error:%u:%s:%s: Open error. %s\n", blockcur, disk->name, esc_tag(task->file->sub, esc_buffer), strerror(errno)); log_fatal("WARNING! Unexpected open error in a data disk, it isn't possible to sync.\n"); log_fatal("Ensure that file '%s' can be accessed.\n", handle->path); - log_fatal("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", esc_shell('/', task->file->sub, esc_buffer)); + log_fatal("Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", esc_shell(task->file->sub, esc_buffer)); task->state = TASK_STATE_ERROR; return; /* LCOV_EXCL_STOP */ @@ -613,7 +613,7 @@ static void sync_data_reader(struct snapraid_worker* worker, struct snapraid_tas log_tag("error:%u:%s:%s: Read error at position %u. %s\n", blockcur, disk->name, esc_tag(task->file->sub, esc_buffer), task->file_pos, strerror(errno)); log_fatal("WARNING! Unexpected read error in a data disk, it isn't possible to sync.\n"); log_fatal("Ensure that file '%s' can be read.\n", handle->path); - log_fatal("Stopping to allow recovery. Try with 'snapraid check -f %s'\n", esc_shell('/', task->file->sub, esc_buffer)); + log_fatal("Stopping to allow recovery. Try with 'snapraid check -f /%s'\n", esc_shell(task->file->sub, esc_buffer)); task->state = TASK_STATE_ERROR; return; /* LCOV_EXCL_STOP */