diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-25 04:41:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-25 04:41:27 +0000 |
commit | c54018b07a9085c0a3aedbc2bd01a85a3b3e20cf (patch) | |
tree | f6e1d6fcf9f6db3794c418b2f89ecf9e08ff41c8 /server/log.c | |
parent | Adding debian version 2.4.38-3+deb10u10. (diff) | |
download | apache2-c54018b07a9085c0a3aedbc2bd01a85a3b3e20cf.tar.xz apache2-c54018b07a9085c0a3aedbc2bd01a85a3b3e20cf.zip |
Merging upstream version 2.4.59.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | server/log.c | 94 |
1 files changed, 71 insertions, 23 deletions
diff --git a/server/log.c b/server/log.c index 42d0b8f..22d2f8d 100644 --- a/server/log.c +++ b/server/log.c @@ -55,7 +55,7 @@ #include "ap_mpm.h" #include "ap_listen.h" -#if HAVE_GETTID +#ifdef HAVE_SYS_GETTID #include <sys/syscall.h> #include <sys/types.h> #endif @@ -276,7 +276,7 @@ AP_DECLARE(apr_status_t) ap_replace_stderr_log(apr_pool_t *p, /* * You might ponder why stderr_pool should survive? * The trouble is, stderr_pool may have s_main->error_log, - * so we aren't in a position to destory stderr_pool until + * so we aren't in a position to destroy stderr_pool until * the next recycle. There's also an apparent bug which * is not; if some folk decided to call this function before * the core open error logs hook, this pool won't survive. @@ -303,7 +303,7 @@ static void log_child_errfn(apr_pool_t *pool, apr_status_t err, } /* Create a child process running PROGNAME with a pipe connected to - * the childs stdin. The write-end of the pipe will be placed in + * the child's stdin. The write-end of the pipe will be placed in * *FPIN on successful return. If dummy_stderr is non-zero, the * stderr for the child will be the same as the stdout of the parent. * Otherwise the child will inherit the stderr from the parent. */ @@ -341,8 +341,10 @@ static int log_child(apr_pool_t *p, const char *progname, rc = apr_procattr_child_err_set(procattr, errfile, NULL); } - rc = apr_proc_create(procnew, args[0], (const char * const *)args, - NULL, procattr, p); + if (rc == APR_SUCCESS) { + rc = apr_proc_create(procnew, args[0], (const char * const *)args, + NULL, procattr, p); + } if (rc == APR_SUCCESS) { apr_pool_note_subprocess(p, procnew, APR_KILL_AFTER_TIMEOUT); @@ -625,14 +627,18 @@ static int log_tid(const ap_errorlog_info *info, const char *arg, #if APR_HAS_THREADS int result; #endif -#if HAVE_GETTID +#if defined(HAVE_GETTID) || defined(HAVE_SYS_GETTID) if (arg && *arg == 'g') { +#ifdef HAVE_GETTID + pid_t tid = gettid(); +#else pid_t tid = syscall(SYS_gettid); +#endif if (tid == -1) return 0; return apr_snprintf(buf, buflen, "%"APR_PID_T_FMT, tid); } -#endif +#endif /* HAVE_GETTID || HAVE_SYS_GETTID */ #if APR_HAS_THREADS if (ap_mpm_query(AP_MPMQ_IS_THREADED, &result) == APR_SUCCESS && result != AP_MPMQ_NOT_SUPPORTED) @@ -650,14 +656,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); @@ -1164,6 +1188,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) : @@ -1217,6 +1246,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; @@ -1598,6 +1631,9 @@ AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *filename) pid_t mypid; apr_status_t rv; const char *fname; + char *temp_fname; + apr_fileperms_t perms; + char pidstr[64]; if (!filename) { return; @@ -1626,19 +1662,31 @@ AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *filename) fname); } - if ((rv = apr_file_open(&pid_file, fname, - APR_WRITE | APR_CREATE | APR_TRUNCATE, - APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD, p)) - != APR_SUCCESS) { + temp_fname = apr_pstrcat(p, fname, ".XXXXXX", NULL); + rv = apr_file_mktemp(&pid_file, temp_fname, + APR_FOPEN_WRITE | APR_FOPEN_CREATE | APR_FOPEN_TRUNCATE, p); + if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL, APLOGNO(00099) - "could not create %s", fname); + "could not create %s", temp_fname); ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, APLOGNO(00100) "%s: could not log pid to file %s", ap_server_argv0, fname); exit(1); } - apr_file_printf(pid_file, "%" APR_PID_T_FMT APR_EOL_STR, mypid); - apr_file_close(pid_file); + + apr_snprintf(pidstr, sizeof pidstr, "%" APR_PID_T_FMT APR_EOL_STR, mypid); + + perms = APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD; + if (((rv = apr_file_perms_set(temp_fname, perms)) != APR_SUCCESS && rv != APR_ENOTIMPL) + || (rv = apr_file_write_full(pid_file, pidstr, strlen(pidstr), NULL)) != APR_SUCCESS + || (rv = apr_file_close(pid_file)) != APR_SUCCESS + || (rv = apr_file_rename(temp_fname, fname, p)) != APR_SUCCESS) { + ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL, APLOGNO(10231) + "%s: Failed creating pid file %s", + ap_server_argv0, temp_fname); + exit(1); + } + saved_pid = mypid; } @@ -1930,8 +1978,8 @@ AP_DECLARE(void) ap_close_piped_log(piped_log *pl) AP_DECLARE(const char *) ap_parse_log_level(const char *str, int *val) { - char *err = "Log level keyword must be one of emerg/alert/crit/error/warn/" - "notice/info/debug/trace1/.../trace8"; + const char *err = "Log level keyword must be one of emerg/alert/crit/error/" + "warn/notice/info/debug/trace1/.../trace8"; int i = 0; if (str == NULL) |