From ba9a1dcd013eefe179ca27cf60452051d7a19849 Mon Sep 17 00:00:00 2001 From: TheWitness Date: Fri, 10 Apr 2026 14:58:11 -0400 Subject: [PATCH 1/5] Fixing: #298 and #300 - Signal Handler and Table Truncation * This should stop the table truncation after install, it will flip the table to use the 'upgrade' process over the truncate process. * Most of the issues around #298 have been corrected with the exception of signal handling in syslog_process which is now addressed. * Also doing CHANGELOG.md catchup commit --- CHANGELOG.md | 6 ++++++ setup.php | 5 ++++- syslog_process.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e74346..7a22b42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,16 @@ --- develop --- +* issue#199: Duplicate Partition name errors * issue#250: Fix date filter persistence by validating before shift_span detection +* issue#252: hardening: escape device hostname output in syslog view; parameterize alert API functions +* issue#256: hardening: prevent CSV formula injection and malformed CSV output in exports * issue#258: Execute CREATE TABLE SQL correctly during replication sync +* issue#260: hardening: replace eval-based callback execution in syslog autocomplete JS * issue#278: Extract duplicated alert command execution paths in syslog_process_alerts * issue#278: Extract alert command execution into shared helper in functions.php; command tokenization now uses preg_split (handles tabs and consecutive spaces); /bin/sh fallback for non-executable command templates removed (use absolute paths with execute bit set) +* issue#298: syslog poller: lock timeout, signal handler, and earlier partition rotation +* issue#300: Syslog table drop with no apparent reason * issue: Making changes to support Cacti 1.3 * issue: Don't use MyISAM for non-analytical tables * issue: The install advisor for Syslog was broken in current Cacti releases diff --git a/setup.php b/setup.php index 6fe9f52..4c8edb6 100644 --- a/setup.php +++ b/setup.php @@ -633,7 +633,7 @@ function syslog_setup_table_new($options) { $present = syslog_db_fetch_row("SHOW TABLES FROM `$syslogdb_default` LIKE 'syslog_reports'"); if (cacti_sizeof($present)) { - $newreport = sizeof(syslog_db_fetch_row("SHOW COLUMNS FROM `$syslogdb_default`.`syslog_reports` LIKE 'body'")); + $newreport = syslog_db_column_exists("$syslogdb_default`.`syslog_reports`", 'body'); } else { $newreport = true; } @@ -784,6 +784,9 @@ function syslog_setup_table_new($options) { set_config_option($name, $values['default']); } } + + // ensure that the setting if set previously to truncate is switched to upgrade + set_config_option('syslog_install_upgrade_type', 'upgrade'); } function syslog_replicate_out($data) { diff --git a/syslog_process.php b/syslog_process.php index 7a59513..70d8235 100644 --- a/syslog_process.php +++ b/syslog_process.php @@ -22,6 +22,12 @@ +-------------------------------------------------------------------------+ */ +if (function_exists('pcntl_async_signals')) { + pcntl_async_signals(true); +} else { + declare(ticks = 100); +} + include(__DIR__ . '/../../include/cli_check.php'); include_once(__DIR__ . '/functions.php'); include_once(__DIR__ . '/database.php'); @@ -32,9 +38,14 @@ * Let it run for an hour if it has to, to clear up any big * bursts of incoming syslog events */ +ini_set('output_buffering', 'Off'); +ini_set('max_runtime', '-1'); ini_set('max_execution_time', 3600); ini_set('memory_limit', '-1'); +set_time_limit(0); +ob_implicit_flush(); + global $debug, $syslog_facilities, $syslog_levels; $debug = false; @@ -82,6 +93,12 @@ } } +// install signal handlers for UNIX only +if (function_exists('pcntl_signal')) { + pcntl_signal(SIGTERM, 'sig_handler'); + pcntl_signal(SIGINT, 'sig_handler'); +} + // record the start time $start_time = microtime(true); @@ -242,6 +259,31 @@ exit(0); +/** + * sig_handler - provides a generic means to catch exceptions to the Cacti log. + * + * @param int $signo The signal that was thrown by the interface. + * + * @return (void) + */ +function sig_handler($signo) { + global $config; + + switch ($signo) { + case SIGTERM: + case SIGINT: + cacti_log("WARNING: Syslog 'master' is shutting down by signal!", false, 'SYSLOG'); + + unregister_process('syslog', 'master', $config['poller_id'], getmypid()); + + exit(1); + + break; + default: + // ignore all other signals + } +} + /** * display_version - displays version information * From 7fad26851973fe7b25ed076b20e691d6c0d6950f Mon Sep 17 00:00:00 2001 From: TheWitness Date: Fri, 10 Apr 2026 15:51:13 -0400 Subject: [PATCH 2/5] Update syslog_process.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- syslog_process.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syslog_process.php b/syslog_process.php index 70d8235..05d722c 100644 --- a/syslog_process.php +++ b/syslog_process.php @@ -274,7 +274,7 @@ function sig_handler($signo) { case SIGINT: cacti_log("WARNING: Syslog 'master' is shutting down by signal!", false, 'SYSLOG'); - unregister_process('syslog', 'master', $config['poller_id'], getmypid()); + unregister_process('syslog', 'master', $config['poller_id']); exit(1); From e038d7c00f2831feeb46fed805b3c40f2f2cca24 Mon Sep 17 00:00:00 2001 From: TheWitness Date: Fri, 10 Apr 2026 15:51:22 -0400 Subject: [PATCH 3/5] Update syslog_process.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- syslog_process.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/syslog_process.php b/syslog_process.php index 05d722c..ee57737 100644 --- a/syslog_process.php +++ b/syslog_process.php @@ -39,11 +39,10 @@ * bursts of incoming syslog events */ ini_set('output_buffering', 'Off'); -ini_set('max_runtime', '-1'); ini_set('max_execution_time', 3600); ini_set('memory_limit', '-1'); -set_time_limit(0); +set_time_limit(3600); ob_implicit_flush(); global $debug, $syslog_facilities, $syslog_levels; From a3d5299952ee1872b9e7170ca2491ad048a911de Mon Sep 17 00:00:00 2001 From: TheWitness Date: Fri, 10 Apr 2026 15:51:55 -0400 Subject: [PATCH 4/5] Update syslog_process.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- syslog_process.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syslog_process.php b/syslog_process.php index ee57737..ef705fa 100644 --- a/syslog_process.php +++ b/syslog_process.php @@ -259,9 +259,9 @@ exit(0); /** - * sig_handler - provides a generic means to catch exceptions to the Cacti log. + * sig_handler - handles UNIX signals and logs shutdown events to the Cacti log. * - * @param int $signo The signal that was thrown by the interface. + * @param int $signo The signal received by the process. * * @return (void) */ From 4d55642c1a357b81ee5575e1e186fb51dae1473f Mon Sep 17 00:00:00 2001 From: TheWitness Date: Fri, 10 Apr 2026 15:52:14 -0400 Subject: [PATCH 5/5] Update setup.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- setup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.php b/setup.php index 4c8edb6..d1e7d8d 100644 --- a/setup.php +++ b/setup.php @@ -633,7 +633,7 @@ function syslog_setup_table_new($options) { $present = syslog_db_fetch_row("SHOW TABLES FROM `$syslogdb_default` LIKE 'syslog_reports'"); if (cacti_sizeof($present)) { - $newreport = syslog_db_column_exists("$syslogdb_default`.`syslog_reports`", 'body'); + $newreport = syslog_db_column_exists('syslog_reports', 'body'); } else { $newreport = true; }