Skip to content

Commit

Permalink
Backport to v2.4:
Browse files Browse the repository at this point in the history
  *) 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
                  #350
     +1: ylavic, rpluem, minfrin



git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1911079 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
minfrin committed Jul 17, 2023
1 parent 5d0a1f2 commit 99ebeea
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 39 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
21 changes: 0 additions & 21 deletions STATUS
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion include/ap_mmn.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,14 +595,15 @@
* 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" */

#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
Expand Down
4 changes: 3 additions & 1 deletion include/util_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -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


/**
Expand Down Expand Up @@ -95,7 +97,7 @@ AP_DECLARE(apr_status_t) ap_recent_ctime(char *date_str, apr_time_t t);
* @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,
Expand Down
3 changes: 3 additions & 0 deletions server/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -2301,6 +2301,9 @@ AP_DECLARE(server_rec*) ap_read_config(process_rec *process, apr_pool_t *ptemp,
if (s == NULL) {
return s;
}
if (ap_server_conf == NULL) {
ap_server_conf = s;
}

init_config_globals(p);

Expand Down
5 changes: 5 additions & 0 deletions server/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,11 @@ static void *create_core_server_config(apr_pool_t *a, server_rec *s)
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;
}

Expand Down
41 changes: 34 additions & 7 deletions server/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,14 +652,32 @@ static int log_ctime(const ap_errorlog_info *info, const char *arg,
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);
Expand Down Expand Up @@ -1166,6 +1184,11 @@ static void log_error_core(const char *file, int line, int module_index,
#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) :
Expand Down Expand Up @@ -1219,6 +1242,10 @@ static void log_error_core(const char *file, int line, int module_index,
}
}
}
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;
Expand Down
10 changes: 6 additions & 4 deletions server/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,8 @@ int main(int argc, const char * const argv[])
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
Expand All @@ -688,6 +688,7 @@ int main(int argc, const char * const argv[])
}
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);

Expand Down Expand Up @@ -785,10 +786,11 @@ int main(int argc, const char * const argv[])
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 */
Expand Down
35 changes: 30 additions & 5 deletions server/util_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -181,7 +183,13 @@ AP_DECLARE(apr_status_t) ap_recent_ctime_ex(char *date_str, apr_time_t t,
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;
}
Expand All @@ -193,9 +201,10 @@ AP_DECLARE(apr_status_t) ap_recent_ctime_ex(char *date_str, apr_time_t t,
}

/* 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;
Expand Down Expand Up @@ -249,7 +258,23 @@ AP_DECLARE(apr_status_t) ap_recent_ctime_ex(char *date_str, apr_time_t t,
*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;
}
Expand Down

0 comments on commit 99ebeea

Please sign in to comment.