Skip to content

fix: load lib/poller.php before the process-helper compat shims - #476

Merged
TheWitness merged 1 commit into
developfrom
fix/poller-include-before-compat-shims
Nov 20, 2026
Merged

TheWitness merged 1 commit into
developfrom
fix/poller-include-before-compat-shims

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Summary

Fixes a fatal error seen in Cacti CI (e.g. Cacti/cacti#8859):

ERROR PHP ERROR: Cannot redeclare cacti_process_still_running() (previously declared in plugins/syslog/includes/functions.php:159) in file: lib/poller.php on line: 2843

Root cause

The cacti_process_still_running() / cacti_process_kill() compatibility shims in includes/functions.php are wrapped in function_exists() guards. Those guards only defer to core when lib/poller.php has already been loaded, but core declares the functions unconditionally.

syslog_check_upgrade() calls syslog_connect(), which require_onces includes/functions.php. At that point lib/poller.php is not loaded yet, so the shim is declared. The function then calls include_once lib/poller.php (setup.php lines 1093 and 1242), and on Cacti 1.2.32+ core fatals on the redeclaration. This happens while the plugin is installed or upgraded, which is why every PHP matrix job in Cacti's CI failed.

Fix

Load core's lib/poller.php before the shims when cacti_process_still_running() is not yet defined:

  • Cacti 1.2.32+: the native helpers are declared first and the shims are skipped.
  • Older Cacti: lib/poller.php lacks the helpers, so the shims still apply.
  • Unit tests: the bootstrap already stubs cacti_process_still_running(), so core is not pulled into the isolated test harness.

Testing

  • Reproduced the exact fatal against Cacti 1.2.x by loading includes/functions.php and then include_once lib/poller.php. With this change the function now comes from core lib/poller.php and the fatal is gone.
  • php -l includes/functions.php passes.
  • Pest suite against Cacti 1.2.x: 852 passed (1 warning that was already there), identical to develop.

The function_exists() guards around the cacti_process_still_running() and
cacti_process_kill() fallbacks only defer to core when lib/poller.php is
already loaded. syslog_check_upgrade() loads includes/functions.php via
syslog_connect() and later include_once's lib/poller.php, so on Cacti
1.2.32+ the shim was declared first and core then fataled with
"Cannot redeclare cacti_process_still_running()".

Include core's lib/poller.php ahead of the shims so the native helpers win
when present and the fallbacks still apply on older releases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 20, 2026 21:14
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the change that loads Cacti’s process helpers before compatibility shims.

No open issues 🎉

What changed in this PR

Fixes a process-helper redeclaration fatal during Syslog plugin installation and upgrade checks by loading Cacti’s poller library before defining compatibility shims.

Changes:

  • Conditionally loads lib/poller.php so native helpers take precedence while preserving fallback shims for older Cacti versions.
  • Documents the fix in the changelog.
File Description
includes/​functions.php Loads core process helpers before the compatibility guards.
CHANGELOG.md Records the fix for the redeclaration fatal on Cacti 1.2.32+.

Review effort: Balanced

@TheWitness
TheWitness merged commit 876bb4a into develop Nov 20, 2026
9 checks passed
@TheWitness
TheWitness deleted the fix/poller-include-before-compat-shims branch November 20, 2026 22:12
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.

3 participants