From db0457b3b27d776a00217908ae20411bcb9398b4 Mon Sep 17 00:00:00 2001 From: Jim Jagielski Date: Tue, 3 Jun 2014 16:02:44 +0000 Subject: [PATCH] Break out common code to be share-able git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1599641 13f79535-47bb-0310-9956-ffa450edef68 --- include/ap_mmn.h | 3 ++- include/util_time.h | 6 ++++++ server/mpm/event/event.c | 23 ++--------------------- server/mpm/eventopt/eventopt.c | 23 ++--------------------- server/mpm/prefork/prefork.c | 2 ++ server/mpm/worker/worker.c | 2 ++ server/util_time.c | 21 +++++++++++++++++++++ 7 files changed, 37 insertions(+), 43 deletions(-) diff --git a/include/ap_mmn.h b/include/ap_mmn.h index b4c33a038f..7ba28e13fd 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -455,6 +455,7 @@ * 20140207.5 (2.5.0-dev) Add ap_mpm_resume_suspended(), AP_MPMQ_CAN_SUSPEND to * ap_mpm_query(), and suspended_baton to conn_rec * 20140207.6 (2.5.0-dev) Added ap_log_common(). + * 20140207.7 (2.5.0-dev) Added ap_force_set_tz(). */ #define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */ @@ -462,7 +463,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20140207 #endif -#define MODULE_MAGIC_NUMBER_MINOR 6 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 7 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a diff --git a/include/util_time.h b/include/util_time.h index 2cd283306e..9f54c912a3 100644 --- a/include/util_time.h +++ b/include/util_time.h @@ -109,6 +109,12 @@ AP_DECLARE(apr_status_t) ap_recent_ctime_ex(char *date_str, apr_time_t t, */ AP_DECLARE(apr_status_t) ap_recent_rfc822_date(char *date_str, apr_time_t t); +/** + * Force an unset TZ to UTC + * @param p the pool to use + */ +AP_DECLARE(void) ap_force_set_tz(apr_pool_t *p); + #ifdef __cplusplus } #endif diff --git a/server/mpm/event/event.c b/server/mpm/event/event.c index d307abecde..2a7455af02 100644 --- a/server/mpm/event/event.c +++ b/server/mpm/event/event.c @@ -57,7 +57,6 @@ #include "apr_atomic.h" #define APR_WANT_STRFUNC #include "apr_want.h" -#include "apr_env.h" #include "apr_version.h" @@ -97,6 +96,7 @@ #include "http_vhost.h" #include "unixd.h" #include "apr_skiplist.h" +#include "util_time.h" #include #include /* for INT_MAX */ @@ -2420,25 +2420,6 @@ static void join_start_thread(apr_thread_t * start_thread_id) } } -static void force_set_tz(apr_pool_t *p) { - /* If the TZ variable is unset, many operationg systems, - * such as Linux, will at runtime read from /etc/localtime - * and call fstat on it. - * - * By forcing the time zone to UTC if it is unset, we gain - * about 2% in raw requests/second (since we format log files - * in the local time, if present) - * - * For more info, see: - * - */ - char *v = NULL; - - if (apr_env_get(&v, "TZ", p) != APR_SUCCESS) { - apr_env_set("TZ", "UTC+0", p); - } -} - static void child_main(int child_num_arg) { apr_thread_t **threads; @@ -3587,7 +3568,7 @@ static void event_hooks(apr_pool_t * p) */ static const char *const aszSucc[] = { "core.c", NULL }; one_process = 0; - force_set_tz(p); + ap_force_set_tz(p); ap_hook_open_logs(event_open_logs, NULL, aszSucc, APR_HOOK_REALLY_FIRST); /* we need to set the MPM state before other pre-config hooks use MPM query diff --git a/server/mpm/eventopt/eventopt.c b/server/mpm/eventopt/eventopt.c index 1a4a146210..6cd24e283a 100644 --- a/server/mpm/eventopt/eventopt.c +++ b/server/mpm/eventopt/eventopt.c @@ -57,7 +57,6 @@ #include "apr_atomic.h" #define APR_WANT_STRFUNC #include "apr_want.h" -#include "apr_env.h" #if APR_HAVE_UNISTD_H #include @@ -91,6 +90,7 @@ #include "mpm_default.h" #include "http_vhost.h" #include "unixd.h" +#include "util_time.h" #include #include /* for INT_MAX */ @@ -2231,25 +2231,6 @@ static void join_start_thread(apr_thread_t * start_thread_id) } } -static void force_set_tz(apr_pool_t *p) { - /* If the TZ variable is unset, many operationg systems, - * such as Linux, will at runtime read from /etc/localtime - * and call fstat on it. - * - * By forcing the time zone to UTC if it is unset, we gain - * about 2% in raw requests/second (since we format log files - * in the local time, if present) - * - * For more info, see: - * - */ - char *v = NULL; - - if (apr_env_get(&v, "TZ", p) != APR_SUCCESS) { - apr_env_set("TZ", "UTC+0", p); - } -} - static void child_main(int child_num_arg) { apr_thread_t **threads; @@ -3395,7 +3376,7 @@ static void event_hooks(apr_pool_t * p) */ static const char *const aszSucc[] = { "core.c", NULL }; one_process = 0; - force_set_tz(p); + ap_force_set_tz(p); ap_hook_open_logs(event_open_logs, NULL, aszSucc, APR_HOOK_REALLY_FIRST); /* we need to set the MPM state before other pre-config hooks use MPM query diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c index b7b3f4e26b..beab93f6fe 100644 --- a/server/mpm/prefork/prefork.c +++ b/server/mpm/prefork/prefork.c @@ -47,6 +47,7 @@ #include "ap_listen.h" #include "ap_mmn.h" #include "apr_poll.h" +#include "util_time.h" #include @@ -1521,6 +1522,7 @@ static void prefork_hooks(apr_pool_t *p) * console. */ static const char *const aszSucc[] = {"core.c", NULL}; + ap_force_set_tz(p); ap_hook_open_logs(prefork_open_logs, NULL, aszSucc, APR_HOOK_REALLY_FIRST); /* we need to set the MPM state before other pre-config hooks use MPM query diff --git a/server/mpm/worker/worker.c b/server/mpm/worker/worker.c index 07dc1f9c5a..90510005d5 100644 --- a/server/mpm/worker/worker.c +++ b/server/mpm/worker/worker.c @@ -68,6 +68,7 @@ #include "mpm_default.h" #include "util_mutex.h" #include "unixd.h" +#include "util_time.h" #include #include /* for INT_MAX */ @@ -2367,6 +2368,7 @@ static void worker_hooks(apr_pool_t *p) */ static const char *const aszSucc[] = {"core.c", NULL}; one_process = 0; + ap_force_set_tz(p); ap_hook_open_logs(worker_open_logs, NULL, aszSucc, APR_HOOK_REALLY_FIRST); /* we need to set the MPM state before other pre-config hooks use MPM query diff --git a/server/util_time.c b/server/util_time.c index 3632d0d583..4e8794d19a 100644 --- a/server/util_time.c +++ b/server/util_time.c @@ -15,6 +15,8 @@ */ #include "util_time.h" +#include "apr_env.h" + /* Number of characters needed to format the microsecond part of a timestamp. @@ -304,3 +306,22 @@ AP_DECLARE(apr_status_t) ap_recent_rfc822_date(char *date_str, apr_time_t t) *date_str++ = 0; return APR_SUCCESS; } + +AP_DECLARE(void) ap_force_set_tz(apr_pool_t *p) { + /* If the TZ variable is unset, many operationg systems, + * such as Linux, will at runtime read from /etc/localtime + * and call fstat on it. + * + * By forcing the time zone to UTC if it is unset, we gain + * about 2% in raw requests/second (since we format log files + * in the local time, if present) + * + * For more info, see: + * + */ + char *v = NULL; + + if (apr_env_get(&v, "TZ", p) != APR_SUCCESS) { + apr_env_set("TZ", "UTC+0", p); + } +} -- 2.40.0