You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by mi...@apache.org on 2023/07/17 21:16:59 UTC

svn commit: r1911079 - in /httpd/httpd/branches/2.4.x: CHANGES STATUS include/ap_mmn.h include/util_time.h server/config.c server/core.c server/log.c server/main.c server/util_time.c

Author: minfrin
Date: Mon Jul 17 21:16:59 2023
New Revision: 1911079

URL: http://svn.apache.org/viewvc?rev=1911079&view=rev
Log:
Backport to v2.4:

  *) core: Add formats %{z} and %{strftime-format} to ErrorLogFormat, and make
     sure that if the format is configured early enough it applies to every log
     line.  PR 62161.
     trunk patch: https://svn.apache.org/r1908380
                  https://svn.apache.org/r1908383
                  https://svn.apache.org/r1908384
                  https://svn.apache.org/r1908388
                  https://svn.apache.org/r1908389
                  https://svn.apache.org/r1908390
                  https://svn.apache.org/r1908393
                  https://svn.apache.org/r1908394
                  https://svn.apache.org/r1908406
                  https://svn.apache.org/r1908407
                  https://svn.apache.org/r1908556
                  https://svn.apache.org/r1908557
     2.4.x patch: svn merge -c 1908380,1908383-1908384,1908388-1908390,1908393-1908394,1908406-1908407,1908556-1908557 ^/httpd/httpd/trunk .
                  (merge works modulo MMN, or patch/PR below)
                  https://patch-diff.githubusercontent.com/raw/apache/httpd/pull/350.diff
                  https://github.com/apache/httpd/pull/350
     +1: ylavic, rpluem, minfrin


Modified:
    httpd/httpd/branches/2.4.x/CHANGES
    httpd/httpd/branches/2.4.x/STATUS
    httpd/httpd/branches/2.4.x/include/ap_mmn.h
    httpd/httpd/branches/2.4.x/include/util_time.h
    httpd/httpd/branches/2.4.x/server/config.c
    httpd/httpd/branches/2.4.x/server/core.c
    httpd/httpd/branches/2.4.x/server/log.c
    httpd/httpd/branches/2.4.x/server/main.c
    httpd/httpd/branches/2.4.x/server/util_time.c

Modified: httpd/httpd/branches/2.4.x/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/CHANGES?rev=1911079&r1=1911078&r2=1911079&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/CHANGES [utf-8] (original)
+++ httpd/httpd/branches/2.4.x/CHANGES [utf-8] Mon Jul 17 21:16:59 2023
@@ -1,6 +1,10 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.4.58
 
+  *) core: Add formats %{z} and %{strftime-format} to ErrorLogFormat, and make
+     sure that if the format is configured early enough it applies to every log
+     line.  PR 62161.  [Yann Ylavic]
+
   *) mod_deflate: Add DeflateAlterETag to control how the ETag
      is modified. The 'NoChange' parameter mimics 2.2.x behavior.
      PR 45023, PR 39727. [Eric Covener]

Modified: httpd/httpd/branches/2.4.x/STATUS
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/STATUS?rev=1911079&r1=1911078&r2=1911079&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/STATUS (original)
+++ httpd/httpd/branches/2.4.x/STATUS Mon Jul 17 21:16:59 2023
@@ -152,27 +152,6 @@ RELEASE SHOWSTOPPERS:
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
 
-  *) core: Add formats %{z} and %{strftime-format} to ErrorLogFormat, and make
-     sure that if the format is configured early enough it applies to every log
-     line.  PR 62161.
-     trunk patch: https://svn.apache.org/r1908380
-                  https://svn.apache.org/r1908383
-                  https://svn.apache.org/r1908384
-                  https://svn.apache.org/r1908388
-                  https://svn.apache.org/r1908389
-                  https://svn.apache.org/r1908390
-                  https://svn.apache.org/r1908393
-                  https://svn.apache.org/r1908394
-                  https://svn.apache.org/r1908406
-                  https://svn.apache.org/r1908407
-                  https://svn.apache.org/r1908556
-                  https://svn.apache.org/r1908557
-     2.4.x patch: svn merge -c 1908380,1908383-1908384,1908388-1908390,1908393-1908394,1908406-1908407,1908556-1908557 ^/httpd/httpd/trunk .
-                  (merge works modulo MMN, or patch/PR below)
-                  https://patch-diff.githubusercontent.com/raw/apache/httpd/pull/350.diff
-                  https://github.com/apache/httpd/pull/350
-     +1: ylavic, rpluem, minfrin
-
 
 
 PATCHES PROPOSED TO BACKPORT FROM TRUNK:

Modified: httpd/httpd/branches/2.4.x/include/ap_mmn.h
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/include/ap_mmn.h?rev=1911079&r1=1911078&r2=1911079&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/include/ap_mmn.h (original)
+++ httpd/httpd/branches/2.4.x/include/ap_mmn.h Mon Jul 17 21:16:59 2023
@@ -595,6 +595,7 @@
  * 20120211.125 (2.4.55-dev) Export mod_http2.h as public header
  * 20120211.126 (2.4.55-dev) Add additional hcmethod_t enums and PROXY_WORKER_IS_ERROR
  * 20120211.127 (2.4.56-dev) Add ap_proxy_canonenc_ex
+ * 20120211.128 (2.4.55-dev) Add AP_CTIME_OPTION_GMTOFF to util_time.h
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */
@@ -602,7 +603,7 @@
 #ifndef MODULE_MAGIC_NUMBER_MAJOR
 #define MODULE_MAGIC_NUMBER_MAJOR 20120211
 #endif
-#define MODULE_MAGIC_NUMBER_MINOR 127                 /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 128                 /* 0...n */
 
 /**
  * Determine if the server's current MODULE_MAGIC_NUMBER is at least a

Modified: httpd/httpd/branches/2.4.x/include/util_time.h
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/include/util_time.h?rev=1911079&r1=1911078&r2=1911079&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/include/util_time.h (original)
+++ httpd/httpd/branches/2.4.x/include/util_time.h Mon Jul 17 21:16:59 2023
@@ -47,6 +47,8 @@ extern "C" {
 #define AP_CTIME_OPTION_USEC    0x1
 /* Use more compact ISO 8601 format */
 #define AP_CTIME_OPTION_COMPACT 0x2
+/* Add timezone offset from GMT ([+-]hhmm) */
+#define AP_CTIME_OPTION_GMTOFF  0x4
 
 
 /**
@@ -95,7 +97,7 @@ AP_DECLARE(apr_status_t) ap_recent_ctime
  * @param option Additional formatting options (AP_CTIME_OPTION_*).
  * @param len Pointer to an int containing the length of the provided buffer.
  *        On successful return it contains the number of bytes written to the
- *        buffer.
+ *        buffer (including trailing NUL byte).
  * @return APR_SUCCESS iff successful, APR_ENOMEM if buffer was to short.
  */
 AP_DECLARE(apr_status_t) ap_recent_ctime_ex(char *date_str, apr_time_t t,

Modified: httpd/httpd/branches/2.4.x/server/config.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/server/config.c?rev=1911079&r1=1911078&r2=1911079&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/server/config.c (original)
+++ httpd/httpd/branches/2.4.x/server/config.c Mon Jul 17 21:16:59 2023
@@ -2301,6 +2301,9 @@ AP_DECLARE(server_rec*) ap_read_config(p
     if (s == NULL) {
         return s;
     }
+    if (ap_server_conf == NULL) {
+        ap_server_conf = s;
+    }
 
     init_config_globals(p);
 

Modified: httpd/httpd/branches/2.4.x/server/core.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/server/core.c?rev=1911079&r1=1911078&r2=1911079&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/server/core.c (original)
+++ httpd/httpd/branches/2.4.x/server/core.c Mon Jul 17 21:16:59 2023
@@ -489,6 +489,11 @@ static void *create_core_server_config(a
         conf->flush_max_pipelined = AP_FLUSH_MAX_PIPELINED;
     }
     else {
+        /* Use main ErrorLogFormat while the vhost is loading */
+        core_server_config *main_conf =
+            ap_get_core_module_config(ap_server_conf->module_config);
+        conf->error_log_format = main_conf->error_log_format;
+
         conf->flush_max_pipelined = -1;
     }
 

Modified: httpd/httpd/branches/2.4.x/server/log.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/server/log.c?rev=1911079&r1=1911078&r2=1911079&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/server/log.c (original)
+++ httpd/httpd/branches/2.4.x/server/log.c Mon Jul 17 21:16:59 2023
@@ -652,14 +652,32 @@ static int log_ctime(const ap_errorlog_i
     int time_len = buflen;
     int option = AP_CTIME_OPTION_NONE;
 
-    while (arg && *arg) {
-        switch (*arg) {
-            case 'u':   option |= AP_CTIME_OPTION_USEC;
-                        break;
-            case 'c':   option |= AP_CTIME_OPTION_COMPACT;
-                        break;
+    if (arg) {
+        if (arg[0] == 'u' && !arg[1]) { /* no ErrorLogFormat (fast path) */
+            option |= AP_CTIME_OPTION_USEC;
+        }
+        else if (!ap_strchr_c(arg, '%')) { /* special "%{cuz}t" formats */
+            while (*arg) {
+                switch (*arg++) {
+                case 'u':
+                    option |= AP_CTIME_OPTION_USEC;
+                    break;
+                case 'c':
+                    option |= AP_CTIME_OPTION_COMPACT;
+                    break;
+                case 'z':
+                    option |= AP_CTIME_OPTION_GMTOFF;
+                    break;
+                }
+            }
+        }
+        else { /* "%{strftime %-format}t" */
+            apr_size_t len = 0;
+            apr_time_exp_t expt;
+            ap_explode_recent_localtime(&expt, apr_time_now());
+            apr_strftime(buf, &len, buflen, arg, &expt);
+            return (int)len;
         }
-        arg++;
     }
 
     ap_recent_ctime_ex(buf, apr_time_now(), option, &time_len);
@@ -1166,6 +1184,11 @@ static void log_error_core(const char *f
 #endif
 
         logf = stderr_log;
+
+        /* Use the main ErrorLogFormat if any */
+        if (ap_server_conf) {
+            sconf = ap_get_core_module_config(ap_server_conf->module_config);
+        }
     }
     else {
         int configured_level = r ? ap_get_request_module_loglevel(r, module_index)        :
@@ -1219,6 +1242,10 @@ static void log_error_core(const char *f
                 }
             }
         }
+        else if (ap_server_conf) {
+            /* Use the main ErrorLogFormat if any */
+            sconf = ap_get_core_module_config(ap_server_conf->module_config);
+        }
     }
 
     info.s             = s;

Modified: httpd/httpd/branches/2.4.x/server/main.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/server/main.c?rev=1911079&r1=1911078&r2=1911079&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/server/main.c (original)
+++ httpd/httpd/branches/2.4.x/server/main.c Mon Jul 17 21:16:59 2023
@@ -678,8 +678,8 @@ int main(int argc, const char * const ar
     if (temp_error_log) {
         ap_replace_stderr_log(process->pool, temp_error_log);
     }
-    ap_server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
-    if (!ap_server_conf) {
+    ap_server_conf = NULL; /* set early by ap_read_config() for logging */
+    if (!ap_read_config(process, ptemp, confname, &ap_conftree)) {
         if (showcompile) {
             /* Well, we tried. Show as much as we can, but exit nonzero to
              * indicate that something's not right. The cause should have
@@ -688,6 +688,7 @@ int main(int argc, const char * const ar
         }
         destroy_and_exit_process(process, 1);
     }
+    ap_assert(ap_server_conf != NULL);
     apr_pool_cleanup_register(pconf, &ap_server_conf, ap_pool_cleanup_set_null,
                               apr_pool_cleanup_null);
 
@@ -785,10 +786,11 @@ int main(int argc, const char * const ar
         apr_pool_create(&ptemp, pconf);
         apr_pool_tag(ptemp, "ptemp");
         ap_server_root = def_server_root;
-        ap_server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
-        if (!ap_server_conf) {
+        ap_server_conf = NULL; /* set early by ap_read_config() for logging */
+        if (!ap_read_config(process, ptemp, confname, &ap_conftree)) {
             destroy_and_exit_process(process, 1);
         }
+        ap_assert(ap_server_conf != NULL);
         apr_pool_cleanup_register(pconf, &ap_server_conf,
                                   ap_pool_cleanup_set_null, apr_pool_cleanup_null);
         /* sort hooks here to make sure pre_config hooks are sorted properly */

Modified: httpd/httpd/branches/2.4.x/server/util_time.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/server/util_time.c?rev=1911079&r1=1911078&r2=1911079&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/server/util_time.c (original)
+++ httpd/httpd/branches/2.4.x/server/util_time.c Mon Jul 17 21:16:59 2023
@@ -22,9 +22,11 @@
  *   */
 #define AP_CTIME_USEC_LENGTH      7
 
-/* Length of ISO 8601 date/time */
+/* Length of ISO 8601 date/time (including trailing '\0') */
 #define AP_CTIME_COMPACT_LEN      20
 
+/* Length of timezone offset from GMT ([+-]hhmm) plus leading space */
+#define AP_CTIME_GMTOFF_LEN       6
 
 /* Cache for exploded values of recent timestamps
  */
@@ -181,7 +183,13 @@ AP_DECLARE(apr_status_t) ap_recent_ctime
         needed += AP_CTIME_USEC_LENGTH;
     }
 
-    /* Check the provided buffer length */
+    if (option & AP_CTIME_OPTION_GMTOFF) {
+        needed += AP_CTIME_GMTOFF_LEN;
+    }
+
+    /* Check the provided buffer length (note: above AP_CTIME_COMPACT_LEN
+     * and APR_CTIME_LEN include the trailing '\0'; so does 'needed' then).
+     */
     if (len && *len >= needed) {
         *len = needed;
     }
@@ -193,9 +201,10 @@ AP_DECLARE(apr_status_t) ap_recent_ctime
     }
 
     /* example without options: "Wed Jun 30 21:49:08 1993" */
-    /*                           123456789012345678901234  */
     /* example for compact format: "1993-06-30 21:49:08" */
-    /*                              1234567890123456789  */
+    /* example for compact+usec+gmtoff format:
+     *     "1993-06-30 22:49:08.123456 +0100"
+     */
 
     ap_explode_recent_localtime(&xt, t);
     real_year = 1900 + xt.tm_year;
@@ -249,7 +258,23 @@ AP_DECLARE(apr_status_t) ap_recent_ctime
         *date_str++ = real_year % 100 / 10 + '0';
         *date_str++ = real_year % 10 + '0';
     }
-    *date_str++ = 0;
+    if (option & AP_CTIME_OPTION_GMTOFF) {
+        int off = xt.tm_gmtoff, off_hh, off_mm;
+        char sign = '+';
+        if (off < 0) {
+            off = -off;
+            sign = '-';
+        }
+        off_hh = off / 3600;
+        off_mm = off % 3600 / 60;
+        *date_str++ = ' ';
+        *date_str++ = sign;
+        *date_str++ = off_hh / 10 + '0';
+        *date_str++ = off_hh % 10 + '0';
+        *date_str++ = off_mm / 10 + '0';
+        *date_str++ = off_mm % 10 + '0';
+    }
+    *date_str = 0;
 
     return APR_SUCCESS;
 }