From 994a064416579453452054e1fee17268bbb74ab2 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Mon, 29 Dec 2014 12:38:28 +0545 Subject: [PATCH 1/2] Minimise config updates when checking cron jobs --- etc/inc/services.inc | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/etc/inc/services.inc b/etc/inc/services.inc index f22e646eb3..aaa90bd627 100644 --- a/etc/inc/services.inc +++ b/etc/inc/services.inc @@ -2363,6 +2363,7 @@ function install_cron_job($command, $active=false, $minute="0", $hour="*", $mont global $config, $g; $is_installed = false; + $cron_changed = true; if (!is_array($config['cron'])) $config['cron'] = array(); @@ -2391,8 +2392,19 @@ function install_cron_job($command, $active=false, $minute="0", $hour="*", $mont $config['cron']['item'][] = $cron_item; write_config(sprintf(gettext("Installed cron job for %s"), $command)); } else { - $config['cron']['item'][$x] = $cron_item; - write_config(sprintf(gettext("Updated cron job for %s"), $command)); + if (($config['cron']['item'][$x]['minute'] == $cron_item['minute']) && + ($config['cron']['item'][$x]['hour'] == $cron_item['hour']) && + ($config['cron']['item'][$x]['mday'] == $cron_item['mday']) && + ($config['cron']['item'][$x]['month'] == $cron_item['month']) && + ($config['cron']['item'][$x]['wday'] == $cron_item['wday']) && + ($config['cron']['item'][$x]['who'] == $cron_item['who']) && + ($config['cron']['item'][$x]['command'] == $cron_item['command'])) { + $cron_changed = false; + log_error(sprintf(gettext("Checked cron job for %s, no change needed"), $command)); + } else { + $config['cron']['item'][$x] = $cron_item; + write_config(sprintf(gettext("Updated cron job for %s"), $command)); + } } } else { if($is_installed == true) { @@ -2400,7 +2412,9 @@ function install_cron_job($command, $active=false, $minute="0", $hour="*", $mont write_config(sprintf(gettext("Removed cron job for %s"), $command)); } } - configure_cron(); + + if ($cron_changed) + configure_cron(); } ?> From aff83787a3c7b24a342b3d7ce720887b30072865 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Mon, 29 Dec 2014 20:16:28 +0545 Subject: [PATCH 2/2] Simplify cron array comparison This works fine - I had not thought about how arrays are compared. Using "==" checks that the key/value pairs match in both arrays, regardless of the order the arrays happen to be in, which is what we want here. Using "===" would insist that the key/value pairs are also in the same order in the array and that the types and everything match identically, which we do not require. --- etc/inc/services.inc | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/etc/inc/services.inc b/etc/inc/services.inc index aaa90bd627..194b4f308b 100644 --- a/etc/inc/services.inc +++ b/etc/inc/services.inc @@ -2392,13 +2392,7 @@ function install_cron_job($command, $active=false, $minute="0", $hour="*", $mont $config['cron']['item'][] = $cron_item; write_config(sprintf(gettext("Installed cron job for %s"), $command)); } else { - if (($config['cron']['item'][$x]['minute'] == $cron_item['minute']) && - ($config['cron']['item'][$x]['hour'] == $cron_item['hour']) && - ($config['cron']['item'][$x]['mday'] == $cron_item['mday']) && - ($config['cron']['item'][$x]['month'] == $cron_item['month']) && - ($config['cron']['item'][$x]['wday'] == $cron_item['wday']) && - ($config['cron']['item'][$x]['who'] == $cron_item['who']) && - ($config['cron']['item'][$x]['command'] == $cron_item['command'])) { + if ($config['cron']['item'][$x] == $cron_item) { $cron_changed = false; log_error(sprintf(gettext("Checked cron job for %s, no change needed"), $command)); } else {