From cb81bb9fc7bbff49a5cfa7dbfef4f15f248d9407 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 18 Mar 2026 12:10:05 +0100 Subject: [PATCH 01/10] Rework makecheck and makedist --- makecheck.sh | 26 +++++++++++++++++++++++++- makedist.sh | 17 +++-------------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/makecheck.sh b/makecheck.sh index 918f46a9..a031f7ab 100755 --- a/makecheck.sh +++ b/makecheck.sh @@ -17,6 +17,30 @@ if ! $SOURCE/configure; then exit 1 fi -if ! time make check; then +if ! make -j4; then + exit 1 +fi + +if ! make check; then + exit 1 +fi + +if ! make distclean; then + exit 1 +fi + +if ! $SOURCE/configure --host=x86_64-w64-mingw32.static --build=`$SOURCE/config.guess`; then + exit 1 +fi + +if ! make -j4; then + exit 1 +fi + +if ! make check; then + exit 1 +fi + +if ! make distclean; then exit 1 fi diff --git a/makedist.sh b/makedist.sh index 4188914e..a52797b9 100755 --- a/makedist.sh +++ b/makedist.sh @@ -1,17 +1,6 @@ #!/bin/sh # -CHECK=check -DEBUG= - -if test "x$1" = "x-f"; then -CHECK=all -fi - -if test "x$1" = "x-d"; then -DEBUG=--enable-debug -fi - # Ask root permissions at the start sudo echo We are root @@ -20,7 +9,7 @@ make distclean # Reconfigure (with force) to get the latest revision from git autoreconf -f -if ! ./configure.windows-x86 $DEBUG; then +if ! ./configure.windows-x86; then exit 1 fi @@ -32,11 +21,11 @@ if ! make distwindows-x86 distclean; then exit 1 fi -if ! ./configure.windows-x64 $DEBUG; then +if ! ./configure.windows-x64; then exit 1 fi -if ! make -j4 $CHECK; then +if ! make -j4; then exit 1 fi From 62b506673af5ec3504aaa8eed9e4206148d5d6cb Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Wed, 18 Mar 2026 12:36:19 +0100 Subject: [PATCH 02/10] Update gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index bcc2dfb4..b46a1ca2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.txz *.deb *.rpm +*.zst # backups *~ @@ -63,6 +64,7 @@ pkg/.SRCINFO *.dst *.epr *.geany +session.conf # AFL makeafl.sh From 9146d02845ef2a8141f0bc1f4799ee74884906c1 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 19 Mar 2026 11:26:04 +0100 Subject: [PATCH 03/10] Update HISTORY --- HISTORY | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/HISTORY b/HISTORY index bf6bbac6..c0ce889c 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,10 @@ SnapRAID HISTORY ================ +14.0rc3d 22/03/2026 +=================== + * Fixed data race on the new RELOCATED flag + 14.0rc3c 16/03/2026 =================== * Log additional information to allow to handle dynamic devices associations From 66ebf5db8b4c4617b0cbbb18cc7325f1932b3b43 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 19 Mar 2026 11:56:22 +0100 Subject: [PATCH 04/10] Rename maketest to makevalg --- maketest.sh => makevalg.sh | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) rename maketest.sh => makevalg.sh (65%) diff --git a/maketest.sh b/makevalg.sh similarity index 65% rename from maketest.sh rename to makevalg.sh index 3adc7f63..c9b80372 100755 --- a/maketest.sh +++ b/makevalg.sh @@ -1,6 +1,6 @@ #!/bin/sh # -# Run all the Coverage and Valgrind tests +# Run all the Valgrind tests # # Source directory @@ -15,21 +15,6 @@ cd $DEST cp $SOURCE/valgrind.supp $DEST -# Coverage -if ! $SOURCE/configure --enable-coverage --enable-sde; then - exit 1 -fi - -if ! make lcov_reset check lcov_capture lcov_html; then - exit 1 -fi - -cp -a cov $SOURCE/cov - -if ! make distclean; then - exit 1 -fi - # Valgrind if ! $SOURCE/configure --enable-valgrind; then exit 1 From 1d2ab288d15273ee24f630f4ab536943a2f426b2 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 19 Mar 2026 12:55:01 +0100 Subject: [PATCH 05/10] Fix wrong variable use. No effect but also not correct. --- cmdline/snapraid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index 86ad7a9c..10467af2 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -906,7 +906,7 @@ int parse_option_size(const char* arg, uint64_t* out_size) char* e; /* parse the number part */ - data_off_t size = strtoul(optarg, &e, 10); + data_off_t size = strtoul(arg, &e, 10); if (!e || e == arg) return -1; From 8ee24aa26cedebad4ed99154ea162969c145a59e Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 19 Mar 2026 12:59:03 +0100 Subject: [PATCH 06/10] Avoid undefined behaviour parsing double --- cmdline/snapraid.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index 10467af2..af1e4129 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -1100,13 +1100,17 @@ int snapraid_main(int argc, char* argv[]) plan100 = SCRUB_FULL; } else { double plan_double = strtod(optarg, &e); - plan100 = plan_double * 100; - if (!e || *e || plan100 > 10000) { + if (!e || *e != 0 + || !isfinite(plan_double) + || plan_double < 0 + || plan_double > 100 + ) { /* LCOV_EXCL_START */ log_fatal(EUSER, "Invalid plan/percentage '%s'\n", optarg); exit(EXIT_FAILURE); /* LCOV_EXCL_STOP */ } + plan100 = plan_double * 100; } break; case 'o' : From 80bb5af22ed3dfed991ee720c1f2ca8a3123a180 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 19 Mar 2026 15:07:43 +0100 Subject: [PATCH 07/10] As option argument never accept an empty string for the 0 value --- cmdline/snapraid.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index af1e4129..56f65d7f 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -907,7 +907,7 @@ int parse_option_size(const char* arg, uint64_t* out_size) /* parse the number part */ data_off_t size = strtoul(arg, &e, 10); - if (!e || e == arg) + if (e == arg) return -1; /* Handle suffixes */ @@ -919,7 +919,7 @@ int parse_option_size(const char* arg, uint64_t* out_size) size *= GIGA; } else if ((e[0] == 't' || e[0] == 'T') && e[1] == 0) { size *= TERA; - } else if (e[0] != '\0') { + } else if (e[0] != 0) { return -1; } @@ -1100,7 +1100,8 @@ int snapraid_main(int argc, char* argv[]) plan100 = SCRUB_FULL; } else { double plan_double = strtod(optarg, &e); - if (!e || *e != 0 + if (e == optarg + || *e != 0 || !isfinite(plan_double) || plan_double < 0 || plan_double > 100 @@ -1115,7 +1116,7 @@ int snapraid_main(int argc, char* argv[]) break; case 'o' : olderthan = strtoul(optarg, &e, 10); - if (!e || *e || olderthan > 1000) { + if (e == optarg || *e || olderthan > 1000) { /* LCOV_EXCL_START */ log_fatal(EUSER, "Invalid number of days '%s'\n", optarg); exit(EXIT_FAILURE); @@ -1139,7 +1140,7 @@ int snapraid_main(int argc, char* argv[]) break; case 'S' : blockstart = strtoul(optarg, &e, 0); - if (!e || *e) { + if (e == optarg || *e) { /* LCOV_EXCL_START */ log_fatal(EUSER, "Invalid start position '%s'\n", optarg); exit(EXIT_FAILURE); @@ -1148,7 +1149,7 @@ int snapraid_main(int argc, char* argv[]) break; case 'B' : blockcount = strtoul(optarg, &e, 0); - if (!e || *e) { + if (e == optarg || *e) { /* LCOV_EXCL_START */ log_fatal(EUSER, "Invalid count number '%s'\n", optarg); exit(EXIT_FAILURE); @@ -1157,7 +1158,7 @@ int snapraid_main(int argc, char* argv[]) break; case 'L' : opt.io_error_limit = strtoul(optarg, &e, 0); - if (!e || *e) { + if (e == optarg || *e) { /* LCOV_EXCL_START */ log_fatal(EUSER, "Invalid error limit number '%s'\n", optarg); exit(EXIT_FAILURE); @@ -1262,7 +1263,7 @@ int snapraid_main(int argc, char* argv[]) break; case OPT_GUI_THRESHOLD_REMOVES : opt.gui_threshold_removes = strtoul(optarg, &e, 0); - if (!e || *e) { + if (e == optarg || *e) { /* LCOV_EXCL_START */ log_fatal(EUSER, "Invalid threshold '%s'\n", optarg); exit(EXIT_FAILURE); @@ -1271,7 +1272,7 @@ int snapraid_main(int argc, char* argv[]) break; case OPT_GUI_THRESHOLD_UPDATES : opt.gui_threshold_updates = strtoul(optarg, &e, 0); - if (!e || *e) { + if (e == optarg || *e) { /* LCOV_EXCL_START */ log_fatal(EUSER, "Invalid threshold '%s'\n", optarg); exit(EXIT_FAILURE); From 5b0bc91c49aaf989938723425489d96abe72c4a2 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 19 Mar 2026 15:08:41 +0100 Subject: [PATCH 08/10] Fix typo in message --- cmdline/state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmdline/state.c b/cmdline/state.c index fc61f86e..d211b9a0 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -2724,7 +2724,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S if (ret < 0 || mapping >= mapping_max) { /* LCOV_EXCL_START */ decoding_error(path, f); - log_fatal(EINTERNAL, "Internal inconsistency: Dir mapping index ouf of range!\n"); + log_fatal(EINTERNAL, "Internal inconsistency: Dir mapping index out of range!\n"); os_abort(); /* LCOV_EXCL_STOP */ } From 3696bccf6843c084adbde2889224757fa794c9c9 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 19 Mar 2026 15:16:48 +0100 Subject: [PATCH 09/10] On any error ensure to close the file handle It's not a leak, as it would be close anyway, but makes sense to close as early as possible. --- cmdline/handle.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/cmdline/handle.c b/cmdline/handle.c index bc36eeaa..32971946 100644 --- a/cmdline/handle.c +++ b/cmdline/handle.c @@ -83,12 +83,8 @@ int handle_create(struct snapraid_handle* handle, struct snapraid_file* file, in if (handle->f == -1) { /* LCOV_EXCL_START */ - /* invalidate for error */ - handle->file = 0; - handle->f = -1; - handle->valid_size = 0; - log_fatal(errno, "Error opening file '%s'. %s.\n", handle->path, strerror(errno)); + handle_close(handle); return -1; /* LCOV_EXCL_STOP */ } @@ -101,6 +97,7 @@ int handle_create(struct snapraid_handle* handle, struct snapraid_file* file, in if (ret != 0) { /* LCOV_EXCL_START */ log_fatal(errno, "Error accessing file '%s'. %s.\n", handle->path, strerror(errno)); + handle_close(handle); return -1; /* LCOV_EXCL_STOP */ } @@ -112,6 +109,7 @@ int handle_create(struct snapraid_handle* handle, struct snapraid_file* file, in if (ret != 0) { /* LCOV_EXCL_START */ log_fatal(errno, "Error advising file '%s'. %s.\n", handle->path, strerror(errno)); + handle_close(handle); return -1; /* LCOV_EXCL_STOP */ } @@ -168,17 +166,13 @@ int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int /* open for read */ handle->f = open_noatime(handle->path, flags | O_RDONLY); if (handle->f == -1) { - /* invalidate for error */ - handle->file = 0; - handle->f = -1; - handle->valid_size = 0; - if (errno == ENOENT) out_missing(errno, "Missing file '%s'.\n", handle->path); else if (errno == EACCES) out(errno, "Permission denied for file '%s'.\n", handle->path); else out(errno, "Error opening file '%s'. %s.\n", handle->path, strerror(errno)); + handle_close(handle); return -1; } @@ -190,6 +184,7 @@ int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int if (ret != 0) { /* LCOV_EXCL_START */ out(errno, "Error accessing file '%s'. %s.\n", handle->path, strerror(errno)); + handle_close(handle); return -1; /* LCOV_EXCL_STOP */ } @@ -201,6 +196,7 @@ int handle_open(struct snapraid_handle* handle, struct snapraid_file* file, int if (ret != 0) { /* LCOV_EXCL_START */ out(errno, "Error advising file '%s'. %s.\n", handle->path, strerror(errno)); + handle_close(handle); return -1; /* LCOV_EXCL_STOP */ } From ef3572ea73ea23df2d55033043d9d46b4609e157 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 19 Mar 2026 16:09:57 +0100 Subject: [PATCH 10/10] Make smartctl to ignore locale --- cmdline/mingw.c | 3 +++ cmdline/unix.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/cmdline/mingw.c b/cmdline/mingw.c index 64e35ec5..747cae9f 100644 --- a/cmdline/mingw.c +++ b/cmdline/mingw.c @@ -177,6 +177,9 @@ void os_init(int opt) } exedir_init(); + + /* set LC_ALL=C to make smartctl ignoring the locale when printing info */ + _wputenv_s(L"LC_ALL", L"C"); } void os_done(void) diff --git a/cmdline/unix.c b/cmdline/unix.c index 7343da0e..8cfc2601 100644 --- a/cmdline/unix.c +++ b/cmdline/unix.c @@ -2404,6 +2404,9 @@ void os_init(int opt) } #endif + /* set LC_ALL=C to make smartctl ignoring the locale when printing info */ + setenv("LC_ALL", "C", 1); + (void)opt; }