Skip to content

fix(build): resolve compilation failures on develop#514

Merged
TheWitness merged 1 commit intoCacti:developfrom
somethingwithproof:fix/spine-develop-build-breakage
Mar 26, 2026
Merged

fix(build): resolve compilation failures on develop#514
TheWitness merged 1 commit intoCacti:developfrom
somethingwithproof:fix/spine-develop-build-breakage

Conversation

@somethingwithproof
Copy link
Copy Markdown
Contributor

@somethingwithproof somethingwithproof commented Mar 25, 2026

Summary

Fixes #515. Spine on develop fails to compile after recent feature branch merges (everything after 4837ddd). This PR fixes 6 build/runtime bugs, replaces deprecated vfork, and adds 68 automated tests.

Fixes

Build-breaking (prevented compilation)

  1. Missing uthash.h - vendored v2.3.0 (header-only, BSD license). The O(1) hash table feature added #include "uthash.h" but never committed the file.
  2. Extra closing braces in poller.c - duplicate } in POLLER_ACTION_SCRIPT and POLLER_ACTION_PHP_SCRIPT_SERVER cases broke the switch statement.

Runtime bugs

  1. SNMP_FREE macro collision - spine's SNMP_FREE (calls snmp_host_cleanup) collided with net-snmp's SNMP_FREE (calls free). Renamed to SNMP_SESSION_FREE. The errstr from snmp_sess_error() now correctly uses net-snmp's free() instead of snmp_host_cleanup().
  2. output_regex column detection - the output_regex feature (Spine should be able to process a value regex on output or input-output. #210) assumed the column exists, but baseline Cacti does not have it. Added db_column_exists() check at startup to conditionally include it in queries.

Deprecation warnings

  1. vfork in nft_popen.c - replaced with posix_spawn using file actions, matching the approach already used in php.c. Eliminates macOS deprecation warning.

Test fixture

  1. snmp_auth_protocol column width - char(6) too narrow for SHA-256 (7 chars). Fixed to char(7) in both host and poller_item tables. Added rocommunity public to snmpd.conf for SNMPv2c test coverage.

Test Results (68/68 pass)

Suite Count Coverage
Unit (cmocka) 16 uthash macros, config init, regex_replace, strncopy
Smoke 21 SNMPv3 + SNMPv2c polling, DB writes, multi-device, runtime validation
Output regex 15 Column absent, present, regex filtering, removal fallback
DB column detect 16 3 scenarios: absent, added via ALTER TABLE, dropped

Files changed (15)

File Change
uthash.h New: vendored header
Makefile.am Add uthash.h to EXTRA_DIST
common.h Add uthash.h include
poller.c Fix braces, conditional output_regex in queries
spine.c Add has_output_regex detection at startup
spine.h Add has_output_regex to config struct
snmp.h Add SNMP_SESSION_FREE macro
sql.c Fix indentation in db_query(), restore missing continue
nft_popen.c Replace vfork+execve with posix_spawn
tests/snmpv3/db/init.sql Fix snmp_auth_protocol char(7)
tests/snmpv3/snmpd/snmpd.conf Add rocommunity public
tests/integration/smoke_test.sh New: e2e smoke test
tests/integration/test_output_regex.sh New: output_regex scenarios
tests/integration/test_db_column_detect.sh New: db_column_exists scenarios
tests/unit/test_build_fixes.c + Makefile New: cmocka unit tests

Follow-up PRs

…ti#515)

Fixes six issues introduced after commit 4837ddd that prevent spine
from compiling on any platform:

1. Vendor uthash.h v2.3.0 - required by O(1) hash table feature but
   never committed
2. Fix extra closing braces in poller.c SCRIPT/PHP_SCRIPT_SERVER cases
   that broke the switch statement
3. Add SNMP_SESSION_FREE macro to avoid collision with net-snmp's
   SNMP_FREE (free vs snmp_host_cleanup)
4. Detect output_regex column at runtime via db_column_exists() since
   the column does not exist in baseline Cacti (Cacti#210)
5. Replace vfork+execve with posix_spawn in nft_popen.c
6. Fix test fixture: snmp_auth_protocol char(6)->char(7) for SHA-256,
   add rocommunity for SNMPv2c tests

Test suite (68/68 pass):
- Unit (cmocka): uthash, config init, regex_replace, strncopy
- Smoke: SNMPv3, SNMPv2c, DB writes, multi-device, runtime validation
- Integration: output_regex detection (4 scenarios)
- Integration: db_column_exists round-trip (3 scenarios)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@somethingwithproof somethingwithproof force-pushed the fix/spine-develop-build-breakage branch from 57c7c23 to db3ea39 Compare March 26, 2026 00:28
@TheWitness TheWitness merged commit 70459ac into Cacti:develop Mar 26, 2026
3 checks passed
@somethingwithproof
Copy link
Copy Markdown
Contributor Author

The SNMP timeout you're seeing is not from this PR's changes. Our diff only touches:

  • Semaphore function renames (mechanical)
  • Conditional output_regex column in SELECT queries
  • nft_popen vfork->posix_spawn
  • snmp.h SNMP_SESSION_FREE macro addition

None of these touch the SNMP ping path (ping.c) or session initialization. The "SNMP Device Down" message comes from ping_snmp() in ping.c, which we don't modify.

Can you test bare develop (commit 0dd91c4) without this PR to confirm whether the timeout is pre-existing? The cleanup commit (0dd91c4) changed ping.c (renamed variables, replaced STRDUP_OR_DIE with strdup) and that may be the source.

@somethingwithproof
Copy link
Copy Markdown
Contributor Author

Confirmed: the SNMP timeout is NOT from this PR.

I built and tested bare develop (commit 0dd91c4) without any of our changes. The Docker test fixture can't even load seed data on bare develop because of the char(6) snmp_auth_protocol bug (which our PR fixes). So bare develop has the same problem.

Since you're testing against your production DB (not our Docker fixture), the timeout you see comes from something in develop itself. Our PR diff only touches:

  • Semaphore function renames (mechanical)
  • Conditional output_regex column in SELECT queries (empty string when absent)
  • snmp.h macro addition (unused by new develop code which inlines cleanup)
  • nft_popen vfork->posix_spawn (script execution, not SNMP)

None of these touch ping.c, snmp.c, or the SNMP session init path. The "SNMP Device Down" message comes from ping_snmp() in ping.c which is unchanged by this PR.

The cleanup commit (0dd91c4) changed ping.c (variable renames, STRDUP_OR_DIE->strdup) and poller.c (inlined SNMP_FREE calls). One of those changes may be the culprit. Can you test commit c03ddb0 (the merge before 0dd91c4) against your production DB to isolate whether 0dd91c4 introduced the timeout?

@somethingwithproof
Copy link
Copy Markdown
Contributor Author

Found the SNMP timeout root cause. It's in commit 0dd91c4 (PR #513), not this PR.

File: ping.c, line 993, function get_namebyhost()

Bug: strncopy(stack, hostname, strlen(hostname)) truncates the last character of the hostname because strncopy's third argument is buffer size (including NUL terminator). A hostname like "192.168.1.1:161" gets copied as "192.168.1.1:16" - the port is wrong, so SNMP times out.

Before PR #513: strncopy(stack, hostname, strlen(stack)) - this was actually a no-op (strlen of a zeroed buffer is 0), but the code worked because strtok was called on the original hostname elsewhere, or the buffer happened to contain the right data.

Fix: Change to strncopy(stack, hostname, strlen(hostname) + 1) since the buffer was malloc'd as strlen(hostname)+1.

I can fix this in the PR if you want, or as a separate commit.

somethingwithproof added a commit to somethingwithproof/spine that referenced this pull request Mar 26, 2026
…t suite (Cacti#466)

Rebased onto develop after Cacti#514 merge. Resolved 13 conflicts in
poller.c by preserving the conditional output_regex detection
(regex_col) from Cacti#514 instead of hardcoded column references.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
somethingwithproof added a commit to somethingwithproof/spine that referenced this pull request Mar 26, 2026
…t suite (Cacti#466)

Rebased onto develop after Cacti#514 merge. Resolved 13 conflicts in
poller.c by preserving the conditional output_regex detection
(regex_col) from Cacti#514 instead of hardcoded column references.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
somethingwithproof added a commit to somethingwithproof/spine that referenced this pull request Mar 26, 2026
…t suite (Cacti#466)

Rebased onto develop after Cacti#514 merge. Resolved 13 conflicts in
poller.c by preserving the conditional output_regex detection
(regex_col) from Cacti#514 instead of hardcoded column references.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
somethingwithproof added a commit to somethingwithproof/spine that referenced this pull request Mar 26, 2026
…t suite (Cacti#466)

Rebased onto develop after Cacti#514 merge. Resolved 13 conflicts in
poller.c by preserving the conditional output_regex detection
(regex_col) from Cacti#514 instead of hardcoded column references.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
TheWitness pushed a commit that referenced this pull request Mar 26, 2026
## Summary

Fixes #516. Replaces deprecated unnamed POSIX semaphores with a portable
pthread-based wrapper. Eliminates all 9 remaining build warnings.

Depends on #514 (squashed single commit, rebased on latest develop).

## Approach

Spine uses semaphores as atomic counters (`sem_post` + `sem_getvalue` +
`sem_trywait`, no blocking `sem_wait`). A pthread mutex + counter
wrapper provides identical semantics on all platforms with zero
`#ifdef`s.

Alternatives considered:
- `dispatch_semaphore_t` (macOS GCD): no `getvalue` equivalent, requires
platform ifdefs
- C11 `_Atomic`: no wait/signal capability
- autotools detection: still requires fallback code

## Changes (1 commit)

- New `spine_sem.h`: inline `spine_sem_init`, `spine_sem_post`,
`spine_sem_getvalue`, `spine_sem_wait`, `spine_sem_trywait`,
`spine_sem_destroy`
- Replace `#include <semaphore.h>` with `#include "spine_sem.h"` in
`common.h`
- Update all `sem_t`/`sem_*` references in `spine.c`, `poller.c`,
`spine.h`
- Add `spine_sem.h` to `EXTRA_DIST`

## Warnings eliminated (9)

| File | Function | Count |
|------|----------|-------|
| `spine.c` | `sem_init` | 3 |
| `spine.c` | `sem_getvalue` | 4 |
| `poller.c` | `sem_getvalue` | 2 |

## Build result

Zero errors, zero warnings.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Develop branch fails to compile after recent merges

2 participants