From 2267c0a41ceb5903c826c5fecb95308f1019dabd Mon Sep 17 00:00:00 2001 From: catch Date: Tue, 3 Apr 2012 16:25:05 +0900 Subject: [PATCH 1/3] Backport http://drupal.org/node/805702 using lock for cron. --- includes/common.inc | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/includes/common.inc b/includes/common.inc index 429cbe27b9a..74cd43f6af6 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -2751,31 +2751,15 @@ function drupal_cron_run() { if (function_exists('set_time_limit')) { @set_time_limit(240); } - - // Fetch the cron semaphore - $semaphore = variable_get('cron_semaphore', FALSE); - - if ($semaphore) { - if (time() - $semaphore > 3600) { - // Either cron has been running for more than an hour or the semaphore - // was not reset due to a database error. - watchdog('cron', 'Cron has been running for more than an hour and is most likely stuck.', array(), WATCHDOG_ERROR); - - // Release cron semaphore - variable_del('cron_semaphore'); - } - else { - // Cron is still running normally. - watchdog('cron', 'Attempting to re-run cron while it is already running.', array(), WATCHDOG_WARNING); - } + // Try to acquire cron lock. + if (!lock_acquire('cron', 240.0)) { + // Cron is still running normally. + watchdog('cron', 'Attempting to re-run cron while it is already running.', array(), WATCHDOG_WARNING); } else { // Register shutdown callback register_shutdown_function('drupal_cron_cleanup'); - // Lock cron semaphore - variable_set('cron_semaphore', time()); - // Iterate through the modules calling their cron handlers (if any): module_invoke_all('cron'); @@ -2783,8 +2767,8 @@ function drupal_cron_run() { variable_set('cron_last', time()); watchdog('cron', 'Cron run completed.', array(), WATCHDOG_NOTICE); - // Release cron semaphore - variable_del('cron_semaphore'); + // Release cron lock. + lock_release('cron'); // Return TRUE so other functions can check if it did run successfully return TRUE; From c50e92ca327e3ea0cb564fe5c46f647bbcbaa8e2 Mon Sep 17 00:00:00 2001 From: catch Date: Wed, 18 Apr 2012 12:02:12 +0900 Subject: [PATCH 2/3] Apply patch from http://drupal.org/node/659784 to remove theme() call from syslog_watchdog(). --- modules/syslog/syslog.module | 53 +++++++++++++++--------------------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/modules/syslog/syslog.module b/modules/syslog/syslog.module index ad2929dc480..5768701f006 100644 --- a/modules/syslog/syslog.module +++ b/modules/syslog/syslog.module @@ -52,6 +52,13 @@ function syslog_admin_settings() { '#description' => t('Select the syslog facility code under which Drupal\'s messages should be sent. On UNIX/Linux systems, Drupal can flag its messages with the code LOG_LOCAL0 through LOG_LOCAL7; for Microsoft Windows, all messages are flagged with the code LOG_USER. Depending on the system configuration, syslog and other logging tools use this code to identify or filter Drupal messages from within the entire system log. For more information on syslog, see Syslog help.', array( '@syslog_help' => url('admin/help/syslog'))), ); + + $form['syslog_format'] = array( + '#type' => 'textarea', + '#title' => t('Syslog format'), + '#default_value' => variable_get('syslog_format', '!base_url|!timestamp|!type|!ip|!request_uri|!referer|!uid|!link|!message'), + '#description' => t('Specify the format of the syslog entry. Available variables are:
!base_url
Base URL of the site.
!timestamp
Unix timestamp of the log entry.
!type
The category to which this message belongs.
!ip
IP address of the user triggering the message.
!request_uri
The requested URI.
!referer
HTTP Referer if available.
!uid
User ID.
!link
A link to associate with the message.
!message
The message to store in the log.
'), + ); return system_settings_form($form); } @@ -74,7 +81,8 @@ function syslog_facility_list() { return $facility_list; } -function syslog_watchdog($entry) { +function syslog_watchdog(array $log_entry) { + global $base_url; static $log_init = FALSE; if (!$log_init) { @@ -82,34 +90,17 @@ function syslog_watchdog($entry) { openlog(variable_get('syslog_identity', 'drupal'), LOG_NDELAY, variable_get('syslog_facility', DEFAULT_SYSLOG_FACILITY)); } - syslog($entry['severity'], theme('syslog_format', $entry)); -} - -function syslog_theme() { - return array( - 'syslog_format' => array( - 'arguments' => array('entry' => NULL), - ), - ); -} + $message = strtr(variable_get('syslog_format', '!base_url|!timestamp|!type|!ip|!request_uri|!referer|!uid|!link|!message'), array( + '!base_url' => $base_url, + '!timestamp' => $log_entry['timestamp'], + '!type' => $log_entry['type'], + '!ip' => $log_entry['ip'], + '!request_uri' => $log_entry['request_uri'], + '!referer' => $log_entry['referer'], + '!uid' => $log_entry['user']->uid, + '!link' => strip_tags($log_entry['link']), + '!message' => strip_tags(is_null($log_entry['variables']) ? $log_entry['message'] : strtr($log_entry['message'], $log_entry['variables'])), + )); -/** - * Format a system log entry. - * - * @ingroup themeable - */ -function theme_syslog_format($entry) { - global $base_url; - - $message = $base_url; - $message .= '|'. $entry['timestamp']; - $message .= '|'. $entry['type']; - $message .= '|'. $entry['ip']; - $message .= '|'. $entry['request_uri']; - $message .= '|'. $entry['referer']; - $message .= '|'. $entry['user']->uid; - $message .= '|'. strip_tags($entry['link']); - $message .= '|'. strip_tags(is_null($entry['variables']) ? $entry['message'] : strtr($entry['message'], $entry['variables'])); - - return $message; -} + syslog($log_entry['severity'], $message); +} \ No newline at end of file From bf7a34838b704b71a9de6863732696ca396a87b1 Mon Sep 17 00:00:00 2001 From: catch Date: Wed, 18 Apr 2012 12:04:05 +0900 Subject: [PATCH 3/3] Revert "Backport http://drupal.org/node/805702 using lock for cron." This reverts commit 2267c0a41ceb5903c826c5fecb95308f1019dabd. --- includes/common.inc | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/includes/common.inc b/includes/common.inc index 74cd43f6af6..429cbe27b9a 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -2751,15 +2751,31 @@ function drupal_cron_run() { if (function_exists('set_time_limit')) { @set_time_limit(240); } - // Try to acquire cron lock. - if (!lock_acquire('cron', 240.0)) { - // Cron is still running normally. - watchdog('cron', 'Attempting to re-run cron while it is already running.', array(), WATCHDOG_WARNING); + + // Fetch the cron semaphore + $semaphore = variable_get('cron_semaphore', FALSE); + + if ($semaphore) { + if (time() - $semaphore > 3600) { + // Either cron has been running for more than an hour or the semaphore + // was not reset due to a database error. + watchdog('cron', 'Cron has been running for more than an hour and is most likely stuck.', array(), WATCHDOG_ERROR); + + // Release cron semaphore + variable_del('cron_semaphore'); + } + else { + // Cron is still running normally. + watchdog('cron', 'Attempting to re-run cron while it is already running.', array(), WATCHDOG_WARNING); + } } else { // Register shutdown callback register_shutdown_function('drupal_cron_cleanup'); + // Lock cron semaphore + variable_set('cron_semaphore', time()); + // Iterate through the modules calling their cron handlers (if any): module_invoke_all('cron'); @@ -2767,8 +2783,8 @@ function drupal_cron_run() { variable_set('cron_last', time()); watchdog('cron', 'Cron run completed.', array(), WATCHDOG_NOTICE); - // Release cron lock. - lock_release('cron'); + // Release cron semaphore + variable_del('cron_semaphore'); // Return TRUE so other functions can check if it did run successfully return TRUE;