mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-25 18:40:19 -04:00
Lock unsafe command-line options after enabling GUI mode
Some checks are pending
Build / build-mac (push) Waiting to run
Build / build-linux (push) Waiting to run
Build / build-arm32 (push) Waiting to run
Build / build-win (push) Waiting to run
Build / build-freebsd (push) Waiting to run
Build / build-musl (push) Waiting to run
CodeQL Advanced / Analyze (c-cpp) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
Some checks are pending
Build / build-mac (push) Waiting to run
Build / build-linux (push) Waiting to run
Build / build-arm32 (push) Waiting to run
Build / build-win (push) Waiting to run
Build / build-freebsd (push) Waiting to run
Build / build-musl (push) Waiting to run
CodeQL Advanced / Analyze (c-cpp) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run
This commit is contained in:
parent
209b902301
commit
a11ebd8ad3
3 changed files with 52 additions and 3 deletions
|
|
@ -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 --gui
|
||||
CHECKFLAGS_VERBOSE = $(CHECKFLAGS_ALPHA) -v
|
||||
|
||||
# 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) --gui-verbose -c $(PAR1) list -l test.log > output.log
|
||||
$(TESTENV) $(SNAPRAID) $(CHECKFLAGS_VERBOSE) -c $(PAR1) list -l test.log --gui-verbose > 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) --gui-verbose -c $(PAR1) list -l test.log > output.log
|
||||
$(TESTENV) $(SNAPRAID) $(CHECKFLAGS_VERBOSE) -c $(PAR1) list -l test.log --gui-verbose > 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
|
||||
|
|
|
|||
|
|
@ -213,6 +213,7 @@ int main(int argc, char* argv[])
|
|||
int i;
|
||||
int pos;
|
||||
int mode;
|
||||
int gui;
|
||||
int ret;
|
||||
|
||||
(void)argc;
|
||||
|
|
@ -246,7 +247,11 @@ int main(int argc, char* argv[])
|
|||
utf8_argc = 1;
|
||||
|
||||
mode = MODE_DEFAULT;
|
||||
gui = 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"-s") == 0 || wcscmp(wide_argv[i], L"--spin-down-on-error") == 0) {
|
||||
mode = MODE_SPINDOWN;
|
||||
} else {
|
||||
|
|
@ -264,6 +269,11 @@ 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) {
|
||||
|
|
@ -370,12 +380,17 @@ static void forward_signal(int sig)
|
|||
int main(int argc, char* argv[])
|
||||
{
|
||||
int mode;
|
||||
int gui;
|
||||
int i, j;
|
||||
int ret;
|
||||
|
||||
mode = MODE_DEFAULT;
|
||||
gui = 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], "-s") == 0 || strcmp(argv[i], "--spin-down-on-error") == 0) {
|
||||
mode = MODE_SPINDOWN;
|
||||
} else {
|
||||
|
|
@ -386,6 +401,11 @@ 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 {
|
||||
|
|
|
|||
|
|
@ -207,6 +207,7 @@ void log_close(const char* file)
|
|||
/**
|
||||
* Test options
|
||||
*/
|
||||
#define OPT_TEST_FIRST 256
|
||||
#define OPT_TEST_SKIP_SELF 256
|
||||
#define OPT_TEST_KILL_AFTER_SYNC 257
|
||||
#define OPT_TEST_EXPECT_UNRECOVERABLE 258
|
||||
|
|
@ -257,6 +258,7 @@ void log_close(const char* file)
|
|||
#define OPT_TEST_SPEED_BLOCKS_SIZE 309
|
||||
#define OPT_TEST_KILL_BEFORE_SYNC 310
|
||||
#define OPT_TEST_KILL_AFTER_RESIZE 311
|
||||
#define OPT_TEST_LAST 311
|
||||
|
||||
#if HAVE_GETOPT_LONG
|
||||
static struct option long_options[] = {
|
||||
|
|
@ -458,6 +460,24 @@ 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)
|
||||
{
|
||||
if (c >= OPT_TEST_FIRST && c <= OPT_TEST_LAST)
|
||||
return 1;
|
||||
|
||||
switch (c) {
|
||||
case 'c' : /* --conf */
|
||||
case 'C' : /* --gen-conf */
|
||||
case 'l' : /* --log */
|
||||
case 'H' : /* --help */
|
||||
case 'V' : /* --version */
|
||||
case 'T' : /* --speed-test */
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_option_size(const char* arg, uint64_t* out_size)
|
||||
{
|
||||
char* e;
|
||||
|
|
@ -544,6 +564,7 @@ int snapraid_main(int argc, char* argv[])
|
|||
const char* import_content;
|
||||
const char* log_file;
|
||||
int lock;
|
||||
int gui_locked;
|
||||
const char* gen_conf;
|
||||
#if HAVE_CHECKER
|
||||
const char* run;
|
||||
|
|
@ -584,6 +605,7 @@ int snapraid_main(int argc, char* argv[])
|
|||
import_content = 0;
|
||||
log_file = 0;
|
||||
lock = 0;
|
||||
gui_locked = 0;
|
||||
gen_conf = 0;
|
||||
speedtest = 0;
|
||||
#if HAVE_CHECKER
|
||||
|
|
@ -598,6 +620,11 @@ 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");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
case 'c' :
|
||||
pathimport(conf, sizeof(conf), optarg);
|
||||
|
|
@ -807,9 +834,11 @@ int snapraid_main(int argc, char* argv[])
|
|||
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 :
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue