From 41b3f398c8dbfa97f86c24081b7ed0087a2bfcee Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Sat, 5 Sep 2026 15:54:13 -0700 Subject: [PATCH 1/5] build: establish src core layout Signed-off-by: Thomas Vincent --- Makefile.am | 13 ++++++++----- keywords.c => src/core/keywords.c | 0 keywords.h => src/core/keywords.h | 0 locks.c => src/core/locks.c | 0 locks.h => src/core/locks.h | 0 tests/fuzz/Makefile | 5 +++-- 6 files changed, 11 insertions(+), 7 deletions(-) rename keywords.c => src/core/keywords.c (100%) rename keywords.h => src/core/keywords.h (100%) rename locks.c => src/core/locks.c (100%) rename locks.h => src/core/locks.h (100%) diff --git a/Makefile.am b/Makefile.am index 2ecbf61b..df91587a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,7 +22,8 @@ AUTOMAKE_OPTIONS = foreign ACLOCAL_AMFLAGS = -I m4 -spine_SOURCES = sql.c spine.c util.c snmp.c locks.c poller.c nft_popen.c php.c ping.c keywords.c error.c +spine_SOURCES = sql.c spine.c util.c snmp.c src/core/locks.c poller.c \ + nft_popen.c php.c ping.c src/core/keywords.c error.c configdir = $(sysconfdir) config_DATA = spine.conf.dist @@ -33,8 +34,9 @@ man_MANS = spine.1 # Headers are not referenced by any _SOURCES, so automake will not distribute # them unless they are listed. Without this the release tarball builds nothing. -noinst_HEADERS = common.h error.h keywords.h locks.h nft_popen.h php.h \ - ping.h poller.h snmp.h spine.h spine_sem.h sql.h uthash.h util.h +noinst_HEADERS = common.h error.h src/core/keywords.h src/core/locks.h \ + nft_popen.h php.h ping.h poller.h snmp.h spine.h spine_sem.h sql.h \ + uthash.h util.h EXTRA_DIST = spine.1 spine.conf.dist @@ -56,7 +58,7 @@ cppcheck: docker-dev --suppress=missingIncludeSystem --suppress=unusedFunction \ --suppress=checkersReport --suppress=toomanyconfigs $(spine_SOURCES)" -AM_CPPFLAGS = -I$(top_srcdir) -I$(top_builddir) +AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/src/core -I$(top_builddir) check_PROGRAMS = @@ -83,7 +85,8 @@ tests_unit_test_safety_fixes_LDADD = $(CMOCKA_LIBS) # Everything except spine.c is linked as built; tests/fuzz/stubs.c supplies the # globals that spine.c would define. tests_unit_test_linked_SOURCES = tests/unit/test_linked.c tests/fuzz/stubs.c \ - sql.c util.c snmp.c locks.c poller.c nft_popen.c php.c ping.c keywords.c error.c + sql.c util.c snmp.c src/core/locks.c poller.c nft_popen.c php.c ping.c \ + src/core/keywords.c error.c tests_unit_test_linked_LDADD = $(CMOCKA_LIBS) $(LIBS) TESTS = $(check_PROGRAMS) diff --git a/keywords.c b/src/core/keywords.c similarity index 100% rename from keywords.c rename to src/core/keywords.c diff --git a/keywords.h b/src/core/keywords.h similarity index 100% rename from keywords.h rename to src/core/keywords.h diff --git a/locks.c b/src/core/locks.c similarity index 100% rename from locks.c rename to src/core/locks.c diff --git a/locks.h b/src/core/locks.h similarity index 100% rename from locks.h rename to src/core/locks.h diff --git a/tests/fuzz/Makefile b/tests/fuzz/Makefile index 49460224..63c2d6d9 100644 --- a/tests/fuzz/Makefile +++ b/tests/fuzz/Makefile @@ -24,10 +24,11 @@ NETSNMP_CFLAGS := $(filter -I% -D%, $(shell net-snmp-config --base-cflags 2>/dev NETSNMP_LIBS := $(filter -l% -L%, $(shell net-snmp-config --libs 2>/dev/null)) SPINE_SRC := $(addprefix $(SPINE_ROOT)/, \ - ping.c util.c sql.c snmp.c locks.c poller.c nft_popen.c php.c keywords.c error.c) + ping.c util.c sql.c snmp.c src/core/locks.c poller.c nft_popen.c php.c \ + src/core/keywords.c error.c) FUZZ_CFLAGS := $(SANITIZERS) -g -O1 -DHAVE_CONFIG_H \ - -I$(SPINE_ROOT) -I$(SPINE_ROOT)/config \ + -I$(SPINE_ROOT) -I$(SPINE_ROOT)/src/core -I$(SPINE_ROOT)/config \ $(NETSNMP_CFLAGS) \ $(shell mysql_config --include 2>/dev/null) From 03861df41d86bdd6d155906f64427f1517153d61 Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Sat, 5 Sep 2026 16:07:55 -0700 Subject: [PATCH 2/5] build: update verification for core layout Signed-off-by: Thomas Vincent --- Makefile.am | 1 + configure.ac | 2 +- scripts/verify.sh | 12 +++++++++++- tests/unit/Makefile | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index df91587a..2ea1a98b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -55,6 +55,7 @@ verify: docker-dev cppcheck: docker-dev docker run --rm spine-dev bash -c \ "cppcheck --enable=all --std=c11 --error-exitcode=1 \ + -I. -Isrc/core \ --suppress=missingIncludeSystem --suppress=unusedFunction \ --suppress=checkersReport --suppress=toomanyconfigs $(spine_SOURCES)" diff --git a/configure.ac b/configure.ac index df11158b..36fff034 100644 --- a/configure.ac +++ b/configure.ac @@ -30,7 +30,7 @@ AC_CONFIG_SRCDIR(spine.c) AC_PREFIX_DEFAULT(/usr/local/spine) AC_LANG(C) -AM_INIT_AUTOMAKE([foreign]) +AM_INIT_AUTOMAKE([foreign subdir-objects]) AM_SILENT_RULES([yes]) AC_CONFIG_HEADERS(config/config.h) diff --git a/scripts/verify.sh b/scripts/verify.sh index ef21dcba..2ad4bb71 100755 --- a/scripts/verify.sh +++ b/scripts/verify.sh @@ -2,12 +2,22 @@ set -euo pipefail echo "=== cppcheck ===" +mapfile -d '' source_files < <( + find . \ + -path './autom4te.cache' -prune -o \ + -path './config' -prune -o \ + -path './m4' -prune -o \ + -path './spine-*' -prune -o \ + -path './tests' -prune -o \ + -type f \( -name '*.c' -o -name '*.h' \) -print0 +) cppcheck --enable=all --std=c11 --error-exitcode=1 \ + -I. -Isrc/core \ --suppress=missingIncludeSystem \ --suppress=unusedFunction \ --suppress=checkersReport \ --suppress=toomanyconfigs \ - -- *.c *.h 2>&1 | tee /tmp/cppcheck.txt + -- "${source_files[@]}" 2>&1 | tee /tmp/cppcheck.txt echo "" echo "=== scan-build ===" diff --git a/tests/unit/Makefile b/tests/unit/Makefile index dd278a64..ce7587de 100644 --- a/tests/unit/Makefile +++ b/tests/unit/Makefile @@ -35,6 +35,7 @@ CFLAGS += \ -std=c99 \ -D_DEFAULT_SOURCE \ -I$(SPINE_ROOT) \ + -I$(SPINE_ROOT)/src/core \ -I$(SPINE_ROOT)/config \ $(CMOCKA_CFLAGS) \ $(MYSQL_CFLAGS) \ From 53e5a49836f2750b3feb3e625e479f8a3333c6ea Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Sat, 5 Sep 2026 17:00:56 -0700 Subject: [PATCH 3/5] build: ignore automake directory stamps Signed-off-by: Thomas Vincent --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f2a12c8b..833a125f 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ # +-------------------------------------------------------------------------+ .deps +.dirstamp Makefile Makefile.in configure From 293f3176c0359f6059add9acd072804f90938249 Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Sat, 5 Sep 2026 17:12:08 -0700 Subject: [PATCH 4/5] build: harden nested source verification Signed-off-by: Thomas Vincent --- .dockerignore | 16 ++++++++-------- scripts/verify.sh | 23 ++++++++++++++--------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/.dockerignore b/.dockerignore index 8f103fa1..bc22c062 100644 --- a/.dockerignore +++ b/.dockerignore @@ -23,14 +23,14 @@ configure configure~ libtool stamp-h1 -.deps/ -.dirstamp -.libs/ -*.o -*.lo -*.la -*.gcda -*.gcno +**/.deps/ +**/.dirstamp +**/.libs/ +**/*.o +**/*.lo +**/*.la +**/*.gcda +**/*.gcno *.log *.tar.gz diff --git a/scripts/verify.sh b/scripts/verify.sh index 2ad4bb71..ca337344 100755 --- a/scripts/verify.sh +++ b/scripts/verify.sh @@ -2,15 +2,20 @@ set -euo pipefail echo "=== cppcheck ===" -mapfile -d '' source_files < <( - find . \ - -path './autom4te.cache' -prune -o \ - -path './config' -prune -o \ - -path './m4' -prune -o \ - -path './spine-*' -prune -o \ - -path './tests' -prune -o \ - -type f \( -name '*.c' -o -name '*.h' \) -print0 -) +source_list=$(mktemp) +trap 'rm -f "$source_list"' EXIT +find . \ + -path './autom4te.cache' -prune -o \ + -path './config' -prune -o \ + -path './m4' -prune -o \ + -path './spine-*' -prune -o \ + -path './tests' -prune -o \ + -type f \( -name '*.c' -o -name '*.h' \) -print0 > "$source_list" +mapfile -d '' source_files < "$source_list" +if (( ${#source_files[@]} == 0 )); then + echo "ERROR: no C sources or headers found" >&2 + exit 1 +fi cppcheck --enable=all --std=c11 --error-exitcode=1 \ -I. -Isrc/core \ --suppress=missingIncludeSystem \ From 5fa6411ec5d0e403fe6a1c025fd99b64042bd278 Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Sat, 5 Sep 2026 17:30:51 -0700 Subject: [PATCH 5/5] build: unify cppcheck source discovery Signed-off-by: Thomas Vincent --- .dockerignore | 4 ++-- Makefile.am | 6 +----- scripts/verify.sh | 20 ++++++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.dockerignore b/.dockerignore index bc22c062..955b538d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -31,8 +31,8 @@ stamp-h1 **/*.la **/*.gcda **/*.gcno -*.log -*.tar.gz +**/*.log +**/*.tar.gz # the built binary itself /spine diff --git a/Makefile.am b/Makefile.am index 2ea1a98b..08f7def3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -53,11 +53,7 @@ verify: docker-dev docker run --rm spine-dev cppcheck: docker-dev - docker run --rm spine-dev bash -c \ - "cppcheck --enable=all --std=c11 --error-exitcode=1 \ - -I. -Isrc/core \ - --suppress=missingIncludeSystem --suppress=unusedFunction \ - --suppress=checkersReport --suppress=toomanyconfigs $(spine_SOURCES)" + docker run --rm -e VERIFY_CPPCHECK_ONLY=1 spine-dev AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/src/core -I$(top_builddir) diff --git a/scripts/verify.sh b/scripts/verify.sh index ca337344..769e0b08 100755 --- a/scripts/verify.sh +++ b/scripts/verify.sh @@ -4,14 +4,14 @@ set -euo pipefail echo "=== cppcheck ===" source_list=$(mktemp) trap 'rm -f "$source_list"' EXIT -find . \ - -path './autom4te.cache' -prune -o \ - -path './config' -prune -o \ - -path './m4' -prune -o \ - -path './spine-*' -prune -o \ - -path './tests' -prune -o \ - -type f \( -name '*.c' -o -name '*.h' \) -print0 > "$source_list" -mapfile -d '' source_files < "$source_list" +find . -maxdepth 1 -type f \( -name '*.c' -o -name '*.h' \) \ + -print0 > "$source_list" +find src -type f \( -name '*.c' -o -name '*.h' \) \ + -print0 >> "$source_list" +source_files=() +while IFS= read -r -d '' source_file; do + source_files+=("$source_file") +done < "$source_list" if (( ${#source_files[@]} == 0 )); then echo "ERROR: no C sources or headers found" >&2 exit 1 @@ -24,6 +24,10 @@ cppcheck --enable=all --std=c11 --error-exitcode=1 \ --suppress=toomanyconfigs \ -- "${source_files[@]}" 2>&1 | tee /tmp/cppcheck.txt +if [[ "${VERIFY_CPPCHECK_ONLY:-0}" == "1" ]]; then + exit 0 +fi + echo "" echo "=== scan-build ===" make clean