Skip to content

Commit ba9a1dc

Browse files
committed
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
1 parent bb45b9b commit ba9a1dc

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22

33
--- develop ---
44

5+
* issue#199: Duplicate Partition name errors
56
* issue#250: Fix date filter persistence by validating before shift_span detection
7+
* issue#252: hardening: escape device hostname output in syslog view; parameterize alert API functions
8+
* issue#256: hardening: prevent CSV formula injection and malformed CSV output in exports
69
* issue#258: Execute CREATE TABLE SQL correctly during replication sync
10+
* issue#260: hardening: replace eval-based callback execution in syslog autocomplete JS
711
* issue#278: Extract duplicated alert command execution paths in syslog_process_alerts
812
* 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)
13+
* issue#298: syslog poller: lock timeout, signal handler, and earlier partition rotation
14+
* issue#300: Syslog table drop with no apparent reason
915
* issue: Making changes to support Cacti 1.3
1016
* issue: Don't use MyISAM for non-analytical tables
1117
* issue: The install advisor for Syslog was broken in current Cacti releases

setup.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ function syslog_setup_table_new($options) {
633633
$present = syslog_db_fetch_row("SHOW TABLES FROM `$syslogdb_default` LIKE 'syslog_reports'");
634634

635635
if (cacti_sizeof($present)) {
636-
$newreport = sizeof(syslog_db_fetch_row("SHOW COLUMNS FROM `$syslogdb_default`.`syslog_reports` LIKE 'body'"));
636+
$newreport = syslog_db_column_exists("$syslogdb_default`.`syslog_reports`", 'body');
637637
} else {
638638
$newreport = true;
639639
}
@@ -784,6 +784,9 @@ function syslog_setup_table_new($options) {
784784
set_config_option($name, $values['default']);
785785
}
786786
}
787+
788+
// ensure that the setting if set previously to truncate is switched to upgrade
789+
set_config_option('syslog_install_upgrade_type', 'upgrade');
787790
}
788791

789792
function syslog_replicate_out($data) {

syslog_process.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
+-------------------------------------------------------------------------+
2323
*/
2424

25+
if (function_exists('pcntl_async_signals')) {
26+
pcntl_async_signals(true);
27+
} else {
28+
declare(ticks = 100);
29+
}
30+
2531
include(__DIR__ . '/../../include/cli_check.php');
2632
include_once(__DIR__ . '/functions.php');
2733
include_once(__DIR__ . '/database.php');
@@ -32,9 +38,14 @@
3238
* Let it run for an hour if it has to, to clear up any big
3339
* bursts of incoming syslog events
3440
*/
41+
ini_set('output_buffering', 'Off');
42+
ini_set('max_runtime', '-1');
3543
ini_set('max_execution_time', 3600);
3644
ini_set('memory_limit', '-1');
3745

46+
set_time_limit(0);
47+
ob_implicit_flush();
48+
3849
global $debug, $syslog_facilities, $syslog_levels;
3950

4051
$debug = false;
@@ -82,6 +93,12 @@
8293
}
8394
}
8495

96+
// install signal handlers for UNIX only
97+
if (function_exists('pcntl_signal')) {
98+
pcntl_signal(SIGTERM, 'sig_handler');
99+
pcntl_signal(SIGINT, 'sig_handler');
100+
}
101+
85102
// record the start time
86103
$start_time = microtime(true);
87104

@@ -242,6 +259,31 @@
242259

243260
exit(0);
244261

262+
/**
263+
* sig_handler - provides a generic means to catch exceptions to the Cacti log.
264+
*
265+
* @param int $signo The signal that was thrown by the interface.
266+
*
267+
* @return (void)
268+
*/
269+
function sig_handler($signo) {
270+
global $config;
271+
272+
switch ($signo) {
273+
case SIGTERM:
274+
case SIGINT:
275+
cacti_log("WARNING: Syslog 'master' is shutting down by signal!", false, 'SYSLOG');
276+
277+
unregister_process('syslog', 'master', $config['poller_id'], getmypid());
278+
279+
exit(1);
280+
281+
break;
282+
default:
283+
// ignore all other signals
284+
}
285+
}
286+
245287
/**
246288
* display_version - displays version information
247289
*

0 commit comments

Comments
 (0)