Backports the memory-safety, process-lifecycle, and polling-correctness fixes identified in the 1.2.x review. Memory safety and resource handling: - fix the `strncopy` one-byte overflow and keep its scan portable to older Solaris - reserve the `php_readpipe` terminator byte, enforce one aggregate response/startup deadline, and recycle a server whose partial or oversized response leaves unread protocol data - keep log newline appends inside `flogmessage` and initialize the buffer before `strftime` - free settings-query results on missing rows and check allocation results before dereference - preserve allocation ownership when trimming recache command output Process and privilege lifecycle: - send quit to every PHP server before a shared grace period, then signal/reap in parallel rounds with bounded SIGTERM-to-SIGKILL escalation - normalize `SIGCHLD` to `SIG_DFL`, verify retained children with `waitpid` before signaling, and prevent active slots from overwriting unreaped PIDs - bound failed-server restart churn and make every no-server caller return `U` - block SIGPIPE only around complete script-server writes and consume only a newly generated pending signal - create pipe/socket descriptors close-on-exec, using `pipe2`/`SOCK_CLOEXEC` when available and a serialized fallback otherwise - serialize `vfork`, optional libc `popen`, and the complete process-wide euid-0 raw-socket window so data-input children cannot inherit root - remove unnecessary privilege elevation when closing raw sockets and fail closed if privileges cannot be dropped Polling correctness: - preserve complete database hostnames, including bare IPv6 literals. The removed host:port parser was dead: callers do not consume its method/port outputs and overwrite those fields from the database, while tokenizing the hostname truncated valid IPv6 input. - validate IPv4 and ICMP header lengths before access, consume rejected peeked datagrams, and correlate echo replies by host, type, identifier, and sequence - make `snmp_count` stop on internal Net-SNMP errors, distinguish SNMPv1 `noSuchName` walk completion, and avoid turning internal errors into valid zero counts - fail closed when device/item-count rows cannot be fetched, preventing zero counts from becoming unbounded duplicate polls - make CLI fatal paths return failure and guard nullable database row fields Verification: - `./bootstrap` completes (using Homebrew `glibtoolize`; the initial unavailable GNU `libtoolize` probe is non-fatal) - default configure/build succeeds against Homebrew mysql-client, net-snmp, and OpenSSL 3 - `--enable-popen` configure/build also succeeds - both builds use `--enable-warnings` and `make -j4`; remaining warnings are pre-existing macOS deprecations and unrelated unused variables - `git diff --check` passes - the blocking pre-push review gate passes all stages (critical/high, secondary scanners, medium, and missing-test review) Scope notes: - The new close-on-exec handling covers descriptors created by the changed PHP/script/ICMP paths. Existing MySQL, log, and Net-SNMP descriptors do not yet have comprehensive close-on-exec coverage; that broader descriptor audit should be a separate change rather than implied by this backport. - In the non-default `--enable-popen` mode, the existing timeout path intentionally skips `pclose` and can retain a child until it exits. This PR secures that mode's fork against the euid window but does not redesign its legacy timeout ownership. - Spine has no in-tree C test harness. The failure-mode paths were statically reviewed and both supported build variants were compiled, but deployment validation should still exercise PHP restart/orphan handling, partial-response timeouts, SNMPv1 count behavior, and malformed/foreign ICMP replies. Closes #564 Closes #565 Closes #566 Closes #573 Closes #601 Closes #604 Closes #606 Closes #608 --------- Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> Co-authored-by: TheWitness <thewitness@cacti.net>
Spine: a poller for Cacti
Spine is a high speed poller replacement for cmd.php. It is almost 100%
compatible with the legacy cmd.php processor and provides much more flexibility,
speed and concurrency than cmd.php.
Make sure that you have the proper development environment to compile Spine. This includes compilers, header files and things such as libtool. If you have questions please consult the forums and/or online documentation.
Unix Installation
These instructions assume the default install location for spine of
/usr/local/spine. If you choose to use another prefix, make sure you update
the commands as required for that new path.
To compile and install Spine using MySQL versions 5.5 or higher please do the following:
./bootstrap
./configure
make
make install
chown root:root /usr/local/spine/bin/spine
chmod u+s /usr/local/spine/bin/spine
To compile and install Spine using MySQL versions previous to 5.5 please do the following:
./bootstrap
./configure --with-reentrant
make
make install
chown root:root /usr/local/spine/bin/spine
chmod +s /usr/local/spine/bin/spine
Windows Installation
CYGWIN Prerequisite
-
Download Cygwin for Window from https://www.cygwin.com/
-
Install Cygwin by executing the downloaded setup program
-
Select Install from Internet
-
Select Root Directory: C:\cygwin
-
Select a mirror which is close to your location
-
Once on the package selection section make sure to select the following (TIP: use the search!):
- autoconf
- automake
- dos2unix
- gcc-core
- gzip
- help2man
- inetutils-src
- libmysqlclient
- libmariadb-devel
- libssl-devel
- libtool
- m4
- make
- net-snmp-devel
- openssl-devel
- wget
-
Wait for installation to complete, coffee time!
-
Move the cygwin setup to the C:\cygwin\ folder for future usage.
Compile Spine
-
Open Cygwin shell prompt (C:\Cygwin\cygwin.bat) and brace yourself to use unix commands on Windows.
-
Download the Spine source to the current directory:
-
Extract Spine into C:\Cygwin\usr\src<spineversion>:
tar xzvf cacti-spine-*.tar.gz -
Change into the Spine directory:
cd /usr/src/cacti-spine-* -
Run bootstrap to prepare Spine for compilation:
./bootstrap -
Follow the instruction which bootstrap outputs.
-
Update the spine.conf file for your installation of Cacti. You can optionally move it to a better location if you choose to do so, make sure to copy the spine.conf as well.
-
Ensure that Spine runs well by running with
/usr/local/spine/spine -R -S -V 3 -
Update Cacti
PathsSetting to point to the Spine binary and update thePoller Typeto Spine. For the spine binary on Windows x64, and using default locations, that would beC:\cygwin64\usr\local\spine\bin\spine.exe -
If all is good Spine will be run from the poller in place of cmd.php.
Known Issues
-
On Windows, Microsoft does not support a TCP Socket send timeout. Therefore, if you are using TCP ping on Windows, spine will not perform a second or subsequent retries to connect and the host will be assumed down on the first failure.
If this is a problem it is suggested to use another Availability/Reachability method, or moving to Linux/UNIX.
-
Spine takes quite a few MySQL connections. The number of connections is calculated as follows: (1 for main poller + 1 per each thread + 1 per each script server)
Therefore, if you have 4 processes, with 10 threads each, and 5 script servers each your spine will take approximately:
total connections = 4 * ( 1 + 10 + 5 ) = 64 -
On older MySQL versions, different libraries had to be used to make MySQL thread safe. MySQL versions 5.0 and 5.1 require this flag. If you are using these version of MySQL, you must use the --with-reentrant configure flag.
Copyright (c) 2004-2024 - The Cacti Group, Inc.