diff --git a/Makefile.am b/Makefile.am index 32f81bcf..738e9898 100644 --- a/Makefile.am +++ b/Makefile.am @@ -361,7 +361,7 @@ CHECKFLAGS_ALPHA = $(CHECKFLAGS_COMMON) --test-force-order-alpha CHECKFLAGS_DIR = $(CHECKFLAGS_COMMON) --test-force-order-dir -q -q -q # Verbose options -CHECKFLAGS_VERBOSE = $(CHECKFLAGS_ALPHA) -v +CHECKFLAGS_VERBOSE = $(CHECKFLAGS_ALPHA) -v --gui # Quiet options CHECKFLAGS = $(CHECKFLAGS_ALPHA) -q -q -q @@ -893,14 +893,14 @@ endif # HAVE_POSIX $(FAILENV) $(SNAPRAID) $(CHECKFLAGS_VERBOSE) -c $(PAR1) --test-expect-need-sync diff > output.log $(TESTENV) $(SNAPRAID) $(CHECKFLAGS) --test-skip-fallocate -c $(PAR1) sync $(MSG) Modified hardlink scan and recovery - $(TESTENV) $(SNAPRAID) $(CHECKFLAGS_VERBOSE) -c $(PAR1) list -l test.log --gui-verbose > output.log + $(TESTENV) $(SNAPRAID) $(CHECKFLAGS_VERBOSE) --gui-verbose -c $(PAR1) list -l test.log > output.log grep -q '^file:disk1:a-hardlink-main:' test.log grep -q '^link_hardlink:disk1:b-hardlink-link:a-hardlink-main$$' test.log ! grep -q '^file:disk1:b-hardlink-link:' test.log echo MODIFIED-CONTENT-WITH-DIFFERENT-SIZE > bench/hardlink-expected echo MODIFIED-CONTENT-WITH-DIFFERENT-SIZE > bench/disk1/a-hardlink-main $(TESTENV) $(SNAPRAID) $(CHECKFLAGS) -c $(PAR1) sync - $(TESTENV) $(SNAPRAID) $(CHECKFLAGS_VERBOSE) -c $(PAR1) list -l test.log --gui-verbose > output.log + $(TESTENV) $(SNAPRAID) $(CHECKFLAGS_VERBOSE) --gui-verbose -c $(PAR1) list -l test.log > output.log grep -q '^file:disk1:a-hardlink-main:' test.log grep -q '^link_hardlink:disk1:b-hardlink-link:a-hardlink-main$$' test.log ! grep -q '^file:disk1:b-hardlink-link:' test.log diff --git a/cmdline/main.c b/cmdline/main.c index 7c85a812..7e36f904 100644 --- a/cmdline/main.c +++ b/cmdline/main.c @@ -213,7 +213,7 @@ int main(int argc, char* argv[]) int i; int pos; int mode; - int gui; + int lock_options; int ret; (void)argc; @@ -247,12 +247,16 @@ int main(int argc, char* argv[]) utf8_argc = 1; mode = MODE_DEFAULT; - gui = 0; + lock_options = 0; for (i = 1; i < wide_argc; i++) { - if (wcscmp(wide_argv[i], L"--gui") == 0 || wcscmp(wide_argv[i], L"--gui-verbose") == 0) - gui = 1; + if (wcscmp(wide_argv[i], L"--lock-options") == 0) + lock_options = 1; if (wcscmp(wide_argv[i], L"-s") == 0 || wcscmp(wide_argv[i], L"--spin-down-on-error") == 0) { + if (lock_options) { + fprintf(stderr, "The --spin-down-on-error option cannot be used after --lock-options.\n"); + exit(EXIT_FAILURE); + } mode = MODE_SPINDOWN; } else { pos = argcat(cmd_buffer, COMMAND_LINE_MAX, pos, wide_argv[i]); @@ -269,11 +273,6 @@ int main(int argc, char* argv[]) utf8_argv[utf8_argc] = 0; cmd_buffer[pos] = 0; - if (mode == MODE_SPINDOWN && gui) { - fprintf(stderr, "The --spin-down-on-error option cannot be used with --gui.\n"); - exit(EXIT_FAILURE); - } - LocalFree(wide_argv); if (mode == MODE_DEFAULT) { @@ -380,18 +379,22 @@ static void forward_signal(int sig) int main(int argc, char* argv[]) { int mode; - int gui; + int lock_options; int i, j; int ret; mode = MODE_DEFAULT; - gui = 0; + lock_options = 0; j = 1; for (i = 1; i < argc; ++i) { - if (strcmp(argv[i], "--gui") == 0 || strcmp(argv[i], "--gui-verbose") == 0) - gui = 1; + if (strcmp(argv[i], "--lock-options") == 0) + lock_options = 1; if (strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--spin-down-on-error") == 0) { + if (lock_options) { + fprintf(stderr, "The --spin-down-on-error option cannot be used after --lock-options.\n"); + exit(EXIT_FAILURE); + } mode = MODE_SPINDOWN; } else { argv[j] = argv[i]; @@ -401,11 +404,6 @@ int main(int argc, char* argv[]) argc = j; argv[argc] = 0; - if (mode == MODE_SPINDOWN && gui) { - fprintf(stderr, "The --spin-down-on-error option cannot be used with --gui.\n"); - exit(EXIT_FAILURE); - } - if (mode == MODE_DEFAULT) { ret = snapraid_main(argc, argv); } else { diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index 4f2b024d..be45fa7b 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -203,6 +203,7 @@ void log_close(const char* file) #define OPT_GUI_TOUCH_BEFORE 504 #define OPT_GUI_THRESHOLD_REMOVES 505 #define OPT_GUI_THRESHOLD_UPDATES 506 +#define OPT_LOCK_OPTIONS 507 /** * Test options @@ -300,6 +301,7 @@ static struct option long_options[] = { { "version", 0, 0, 'V' }, { "no-warnings", 0, 0, OPT_NO_WARNINGS }, /* disable annoying warnings */ + { "lock-options", 0, 0, OPT_LOCK_OPTIONS }, /* lock options to avoid unintended injection */ { "gui", 0, 0, OPT_GUI }, /* undocumented GUI interface option (it was also 'G' in the past) */ { "gui-verbose", 0, 0, OPT_GUI_VERBOSE }, /* undocumented GUI interface option */ { "gui-rescan-after", 0, 0, OPT_GUI_RESCAN_AFTER }, /* undocumented GUI, force a rescan after the command to log differences */ @@ -460,7 +462,7 @@ static struct option long_options[] = { */ #define OPTIONS "t:c:f:d:mebp:o:S:B:L:i:l:AZEUDNFRW:ahTC:vqHVw:" -static int option_gui_locked(int c) +static int option_locked(int c) { if (c >= OPT_TEST_FIRST && c <= OPT_TEST_LAST) return 1; @@ -564,7 +566,7 @@ int snapraid_main(int argc, char* argv[]) const char* import_content; const char* log_file; int lock; - int gui_locked; + int lock_options; const char* gen_conf; #if HAVE_CHECKER const char* run; @@ -605,7 +607,7 @@ int snapraid_main(int argc, char* argv[]) import_content = 0; log_file = 0; lock = 0; - gui_locked = 0; + lock_options = 0; gen_conf = 0; speedtest = 0; #if HAVE_CHECKER @@ -620,8 +622,8 @@ int snapraid_main(int argc, char* argv[]) getopt(argc, argv, OPTIONS)) #endif != EOF) { - if (gui_locked && option_gui_locked(c)) { - log_fatal(EUSER, "Option not allowed after --gui.\n"); + if (lock_options && option_locked(c)) { + log_fatal(EUSER, "Option not allowed after --lock-options.\n"); exit(EXIT_FAILURE); } @@ -832,13 +834,14 @@ int snapraid_main(int argc, char* argv[]) case OPT_NO_WARNINGS : opt.no_warnings = 1; break; + case OPT_LOCK_OPTIONS : + lock_options = 1; + break; case OPT_GUI : opt.gui = 1; - gui_locked = 1; break; case OPT_GUI_VERBOSE : opt.gui = 1; - gui_locked = 1; opt.gui_verbose = 1; break; case OPT_GUI_RESCAN_AFTER :