842ae4bd224140319ae7feec1872b93dfd491143fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
842ae4bd224140319ae7feec1872b93dfd491143fielding * contributor license agreements. See the NOTICE file distributed with
842ae4bd224140319ae7feec1872b93dfd491143fielding * this work for additional information regarding copyright ownership.
842ae4bd224140319ae7feec1872b93dfd491143fielding * The ASF licenses this file to You under the Apache License, Version 2.0
842ae4bd224140319ae7feec1872b93dfd491143fielding * (the "License"); you may not use this file except in compliance with
842ae4bd224140319ae7feec1872b93dfd491143fielding * the License. You may obtain a copy of the License at
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * http://www.apache.org/licenses/LICENSE-2.0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * Unless required by applicable law or agreed to in writing, software
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * distributed under the License is distributed on an "AS IS" BASIS,
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * See the License for the specific language governing permissions and
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * limitations under the License.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * http_log.c: Dealing with the logs and errors
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Rob McCool
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein#include "apr.h"
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein#include "apr_general.h" /* for signal stuff */
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein#include "apr_strings.h"
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein#include "apr_errno.h"
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein#include "apr_thread_proc.h"
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#include "apr_lib.h"
be3223a6a18d9a3a3cf7155d5430a5d92bcddceegstein#include "apr_signal.h"
573394373c777e1624a481160f3d02f8fb09f3ffrjung#include "apr_portable.h"
e302f38fd646764ce1a1e1c578d794aef514a9e5sf#include "apr_base64.h"
1b21d7b3d97def358b2e923655edeb16613a1c31gstein
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#define APR_WANT_STDIO
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#define APR_WANT_STRFUNC
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#include "apr_want.h"
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein#if APR_HAVE_STDARG_H
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein#include <stdarg.h>
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein#endif
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#if APR_HAVE_UNISTD_H
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#include <unistd.h>
1b21d7b3d97def358b2e923655edeb16613a1c31gstein#endif
d633ae407c3c956cb2d67ff27055ff0e640967adfuankg#if APR_HAVE_PROCESS_H
d633ae407c3c956cb2d67ff27055ff0e640967adfuankg#include <process.h> /* for getpid() on Win32 */
d633ae407c3c956cb2d67ff27055ff0e640967adfuankg#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb#include "ap_config.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "httpd.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_config.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_core.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_log.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "http_main.h"
cf8fe49d9d89cfa4b62cb2b1376ca6f25b81b362trawick#include "util_time.h"
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick#include "ap_mpm.h"
56589be3d7a3e9343370df240010c6928cc78b39jkaluza#include "ap_provider.h"
d981a6ecf6f7d394f1f017b19c52383e177a125ejim#include "ap_listen.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf#if HAVE_GETTID
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf#include <sys/syscall.h>
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf#include <sys/types.h>
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf#endif
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf/* we know core's module_index is 0 */
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf#undef APLOG_MODULE_INDEX
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf#define APLOG_MODULE_INDEX AP_CORE_MODULE_INDEX
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingtypedef struct {
963f8b44ac95132458ea3b6aaa8ebc135188e473takashi const char *t_name;
963f8b44ac95132458ea3b6aaa8ebc135188e473takashi int t_val;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding} TRANS;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
a7318397b355119d990d1f311b951dea2aafc53arbbAPR_HOOK_STRUCT(
a7318397b355119d990d1f311b951dea2aafc53arbb APR_HOOK_LINK(error_log)
ce4dc40a4e87991087488f70d96d3447d7557294sf APR_HOOK_LINK(generate_log_id)
a7318397b355119d990d1f311b951dea2aafc53arbb)
a7318397b355119d990d1f311b951dea2aafc53arbb
cb9e6e5c78f5a1690214e9548250fc6af1fc73b5wroweint AP_DECLARE_DATA ap_default_loglevel = DEFAULT_LOGLEVEL;
cb9e6e5c78f5a1690214e9548250fc6af1fc73b5wrowe
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const TRANS priorities[] = {
8a3228198adb03e6996f7738c361a612777ecab6aaron {"emerg", APLOG_EMERG},
8a3228198adb03e6996f7738c361a612777ecab6aaron {"alert", APLOG_ALERT},
8a3228198adb03e6996f7738c361a612777ecab6aaron {"crit", APLOG_CRIT},
8a3228198adb03e6996f7738c361a612777ecab6aaron {"error", APLOG_ERR},
8a3228198adb03e6996f7738c361a612777ecab6aaron {"warn", APLOG_WARNING},
8a3228198adb03e6996f7738c361a612777ecab6aaron {"notice", APLOG_NOTICE},
8a3228198adb03e6996f7738c361a612777ecab6aaron {"info", APLOG_INFO},
8a3228198adb03e6996f7738c361a612777ecab6aaron {"debug", APLOG_DEBUG},
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf {"trace1", APLOG_TRACE1},
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf {"trace2", APLOG_TRACE2},
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf {"trace3", APLOG_TRACE3},
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf {"trace4", APLOG_TRACE4},
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf {"trace5", APLOG_TRACE5},
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf {"trace6", APLOG_TRACE6},
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf {"trace7", APLOG_TRACE7},
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf {"trace8", APLOG_TRACE8},
8a3228198adb03e6996f7738c361a612777ecab6aaron {NULL, -1},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding};
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
649c9dd342a580016d29c2866de88a4609eb6457wrowestatic apr_pool_t *stderr_pool = NULL;
649c9dd342a580016d29c2866de88a4609eb6457wrowe
0f57a69cc84c59eacda1179763ae42ca88f1a577wrowestatic apr_file_t *stderr_log = NULL;
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick/* track pipe handles to close in child process */
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawicktypedef struct read_handle_t {
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick struct read_handle_t *next;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick apr_file_t *handle;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick} read_handle_t;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickstatic read_handle_t *read_handles;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton/**
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * @brief The piped logging structure.
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton *
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * Piped logs are used to move functionality out of the main server.
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton * For example, log rotation is done with piped logs.
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton */
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jortonstruct piped_log {
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton /** The pool to use for the piped log */
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton apr_pool_t *p;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton /** The pipe between the server and the logging process */
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton apr_file_t *read_fd, *write_fd;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton#ifdef AP_HAVE_RELIABLE_PIPED_LOGS
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton /** The name of the program the logging process is running */
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton char *program;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton /** The pid of the logging process */
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton apr_proc_t *pid;
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe /** How to reinvoke program when it must be replaced */
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe apr_cmdtype_e cmdtype;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton#endif
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton};
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jortonAP_DECLARE(apr_file_t *) ap_piped_log_read_fd(piped_log *pl)
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton{
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton return pl->read_fd;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton}
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jortonAP_DECLARE(apr_file_t *) ap_piped_log_write_fd(piped_log *pl)
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton{
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton return pl->write_fd;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton}
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe/* remember to close this handle in the child process
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe *
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe * On Win32 this makes zero sense, because we don't
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe * take the parent process's child procs.
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe * If the win32 parent instead passed each and every
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe * logger write handle from itself down to the child,
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * and the parent manages all aspects of keeping the
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe * reliable pipe log children alive, this would still
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe * make no sense :) Cripple it on Win32.
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe */
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickstatic void close_handle_in_child(apr_pool_t *p, apr_file_t *f)
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick{
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe#ifndef WIN32
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick read_handle_t *new_handle;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick new_handle = apr_pcalloc(p, sizeof(read_handle_t));
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick new_handle->next = read_handles;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick new_handle->handle = f;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick read_handles = new_handle;
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe#endif
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick}
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickvoid ap_logs_child_init(apr_pool_t *p, server_rec *s)
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick{
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick read_handle_t *cur = read_handles;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick while (cur) {
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick apr_file_close(cur->handle);
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick cur = cur->next;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick }
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick}
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick
ebc18d48bea83ee5ed7a1b4e30007e5192539829wroweAP_DECLARE(void) ap_open_stderr_log(apr_pool_t *p)
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick{
066877f1a045103acfdd376d48cdd473c33f409bdougm apr_file_open_stderr(&stderr_log, p);
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick}
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick
e8f95a682820a599fe41b22977010636be5c2717jimAP_DECLARE(apr_status_t) ap_replace_stderr_log(apr_pool_t *p,
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe const char *fname)
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe{
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe apr_file_t *stderr_file;
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe apr_status_t rc;
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe char *filename = ap_server_root_relative(p, fname);
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe if (!filename) {
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT,
185aa71728867671e105178b4c66fbc22b65ae26sf APR_EBADPATH, NULL, APLOGNO(00085) "Invalid -E error log file %s",
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe fname);
85c435ceda98eab940615e4466d9c5955252e745wrowe return APR_EBADPATH;
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe }
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe if ((rc = apr_file_open(&stderr_file, filename,
92eed7d377d8be7cd8e48d1299412fc8c742b7f5jorton APR_APPEND | APR_WRITE | APR_CREATE | APR_LARGEFILE,
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe APR_OS_DEFAULT, p)) != APR_SUCCESS) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL, APLOGNO(00086)
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe "%s: could not open error log file %s.",
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe ap_server_argv0, fname);
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe return rc;
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe if (!stderr_pool) {
649c9dd342a580016d29c2866de88a4609eb6457wrowe /* This is safe provided we revert it when we are finished.
649c9dd342a580016d29c2866de88a4609eb6457wrowe * We don't manager the callers pool!
649c9dd342a580016d29c2866de88a4609eb6457wrowe */
649c9dd342a580016d29c2866de88a4609eb6457wrowe stderr_pool = p;
649c9dd342a580016d29c2866de88a4609eb6457wrowe }
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim if ((rc = apr_file_open_stderr(&stderr_log, stderr_pool))
649c9dd342a580016d29c2866de88a4609eb6457wrowe == APR_SUCCESS) {
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe apr_file_flush(stderr_log);
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim if ((rc = apr_file_dup2(stderr_log, stderr_file, stderr_pool))
649c9dd342a580016d29c2866de88a4609eb6457wrowe == APR_SUCCESS) {
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe apr_file_close(stderr_file);
649c9dd342a580016d29c2866de88a4609eb6457wrowe /*
649c9dd342a580016d29c2866de88a4609eb6457wrowe * You might ponder why stderr_pool should survive?
649c9dd342a580016d29c2866de88a4609eb6457wrowe * The trouble is, stderr_pool may have s_main->error_log,
649c9dd342a580016d29c2866de88a4609eb6457wrowe * so we aren't in a position to destory stderr_pool until
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * the next recycle. There's also an apparent bug which
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * is not; if some folk decided to call this function before
649c9dd342a580016d29c2866de88a4609eb6457wrowe * the core open error logs hook, this pool won't survive.
649c9dd342a580016d29c2866de88a4609eb6457wrowe * Neither does the stderr logger, so this isn't a problem.
649c9dd342a580016d29c2866de88a4609eb6457wrowe */
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe }
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe }
649c9dd342a580016d29c2866de88a4609eb6457wrowe /* Revert, see above */
649c9dd342a580016d29c2866de88a4609eb6457wrowe if (stderr_pool == p)
649c9dd342a580016d29c2866de88a4609eb6457wrowe stderr_pool = NULL;
649c9dd342a580016d29c2866de88a4609eb6457wrowe
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe if (rc != APR_SUCCESS) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_error(APLOG_MARK, APLOG_CRIT, rc, NULL, APLOGNO(00087)
760b90f5b0bb414646deb6a3a2a53c14bf49bf3dwrowe "unable to replace stderr with error log file");
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe }
15405e91bb3fad5a80f7abe828a00b44a3a65bf8jerenkrantz return rc;
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe}
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe
76185d819b745e953dd2cd636fbdd515c333e4a4trawickstatic void log_child_errfn(apr_pool_t *pool, apr_status_t err,
76185d819b745e953dd2cd636fbdd515c333e4a4trawick const char *description)
76185d819b745e953dd2cd636fbdd515c333e4a4trawick{
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_error(APLOG_MARK, APLOG_ERR, err, NULL, APLOGNO(00088)
76185d819b745e953dd2cd636fbdd515c333e4a4trawick "%s", description);
76185d819b745e953dd2cd636fbdd515c333e4a4trawick}
76185d819b745e953dd2cd636fbdd515c333e4a4trawick
399cf0e5e061b49593817421b94305889fa6bc1fjorton/* Create a child process running PROGNAME with a pipe connected to
399cf0e5e061b49593817421b94305889fa6bc1fjorton * the childs stdin. The write-end of the pipe will be placed in
399cf0e5e061b49593817421b94305889fa6bc1fjorton * *FPIN on successful return. If dummy_stderr is non-zero, the
399cf0e5e061b49593817421b94305889fa6bc1fjorton * stderr for the child will be the same as the stdout of the parent.
399cf0e5e061b49593817421b94305889fa6bc1fjorton * Otherwise the child will inherit the stderr from the parent. */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic int log_child(apr_pool_t *p, const char *progname,
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe apr_file_t **fpin, apr_cmdtype_e cmdtype,
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe int dummy_stderr)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Child process code for 'ErrorLog "|..."';
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * may want a common framework for this, since I expect it will
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * be common for other foo-loggers to want this sort of thing...
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
f5fccb8eae1f1a5f212a5bda878479c281f36512trawick apr_status_t rc;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_procattr_t *procattr;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_proc_t *procnew;
399cf0e5e061b49593817421b94305889fa6bc1fjorton apr_file_t *errfile;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh if (((rc = apr_procattr_create(&procattr, p)) == APR_SUCCESS)
5a6a87d8920e385b1ed14177d74ab9786f3acddfwrowe && ((rc = apr_procattr_dir_set(procattr,
5a6a87d8920e385b1ed14177d74ab9786f3acddfwrowe ap_server_root)) == APR_SUCCESS)
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe && ((rc = apr_procattr_cmdtype_set(procattr, cmdtype)) == APR_SUCCESS)
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh && ((rc = apr_procattr_io_set(procattr,
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh APR_FULL_BLOCK,
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh APR_NO_PIPE,
76185d819b745e953dd2cd636fbdd515c333e4a4trawick APR_NO_PIPE)) == APR_SUCCESS)
76185d819b745e953dd2cd636fbdd515c333e4a4trawick && ((rc = apr_procattr_error_check_set(procattr, 1)) == APR_SUCCESS)
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim && ((rc = apr_procattr_child_errfn_set(procattr, log_child_errfn))
ff0436077dc959b17a6f87825e4a106d211224c1wrowe == APR_SUCCESS)) {
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb char **args;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_tokenize_to_argv(progname, &args, p);
8a3228198adb03e6996f7738c361a612777ecab6aaron procnew = (apr_proc_t *)apr_pcalloc(p, sizeof(*procnew));
ff0436077dc959b17a6f87825e4a106d211224c1wrowe
ff0436077dc959b17a6f87825e4a106d211224c1wrowe if (dummy_stderr) {
ff0436077dc959b17a6f87825e4a106d211224c1wrowe if ((rc = apr_file_open_stdout(&errfile, p)) == APR_SUCCESS)
ff0436077dc959b17a6f87825e4a106d211224c1wrowe rc = apr_procattr_child_err_set(procattr, errfile, NULL);
ff0436077dc959b17a6f87825e4a106d211224c1wrowe }
ff0436077dc959b17a6f87825e4a106d211224c1wrowe
f205c4528c66355765990fe9785c17832c656d97trawick if (rc == APR_SUCCESS) {
f205c4528c66355765990fe9785c17832c656d97trawick rc = apr_proc_create(procnew, args[0], (const char * const *)args,
f205c4528c66355765990fe9785c17832c656d97trawick NULL, procattr, p);
f205c4528c66355765990fe9785c17832c656d97trawick }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb if (rc == APR_SUCCESS) {
d521bfef0e1a65993d5e302628ac68a2c91a195ftrawick apr_pool_note_subprocess(p, procnew, APR_KILL_AFTER_TIMEOUT);
20c85ca0d404e29972fb94c3d6236a264d1c77abstoddard (*fpin) = procnew->in;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick /* read handle to pipe not kept open, so no need to call
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick * close_handle_in_child()
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick */
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb }
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb }
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb
8a3228198adb03e6996f7738c361a612777ecab6aaron return rc;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
399cf0e5e061b49593817421b94305889fa6bc1fjorton/* Open the error log for the given server_rec. If IS_MAIN is
399cf0e5e061b49593817421b94305889fa6bc1fjorton * non-zero, s is the main server. */
399cf0e5e061b49593817421b94305889fa6bc1fjortonstatic int open_error_log(server_rec *s, int is_main, apr_pool_t *p)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
061c3874622b67beff724876b9bd1b1f291f2eaafielding const char *fname;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb int rc;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (*s->error_fname == '|') {
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung apr_file_t *dummy = NULL;
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe apr_cmdtype_e cmdtype = APR_PROGRAM_ENV;
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe fname = s->error_fname + 1;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe /* In 2.4 favor PROGRAM_ENV, accept "||prog" syntax for compatibility
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe * and "|$cmd" to override the default.
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * Any 2.2 backport would continue to favor SHELLCMD_ENV so there
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe * accept "||prog" to override, and "|$cmd" to ease conversion.
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe */
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe if (*fname == '|')
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe ++fname;
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe if (*fname == '$') {
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe cmdtype = APR_SHELLCMD_ENV;
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe ++fname;
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
399cf0e5e061b49593817421b94305889fa6bc1fjorton /* Spawn a new child logger. If this is the main server_rec,
399cf0e5e061b49593817421b94305889fa6bc1fjorton * the new child must use a dummy stderr since the current
399cf0e5e061b49593817421b94305889fa6bc1fjorton * stderr might be a pipe to the old logger. Otherwise, the
399cf0e5e061b49593817421b94305889fa6bc1fjorton * child inherits the parents stderr. */
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe rc = log_child(p, fname, &dummy, cmdtype, is_main);
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung if (rc != APR_SUCCESS) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL, APLOGNO(00089)
19702a9985f3b2f794d22be9102d9d4fbf6bebe7rjung "Couldn't start ErrorLog process '%s'.",
783e3e4bd40b8c276b72b49470bfabb8693fb5c2rjung s->error_fname + 1);
85c435ceda98eab940615e4466d9c5955252e745wrowe return DONE;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung s->error_log = dummy;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
56589be3d7a3e9343370df240010c6928cc78b39jkaluza else if (s->errorlog_provider) {
56589be3d7a3e9343370df240010c6928cc78b39jkaluza s->errorlog_provider_handle = s->errorlog_provider->init(p, s);
8a3228198adb03e6996f7738c361a612777ecab6aaron s->error_log = NULL;
c62cc8593d17deefcd6879923ccfcd80f07eaa40trawick if (!s->errorlog_provider_handle) {
c62cc8593d17deefcd6879923ccfcd80f07eaa40trawick /* provider must log something to the console */
c62cc8593d17deefcd6879923ccfcd80f07eaa40trawick return DONE;
c62cc8593d17deefcd6879923ccfcd80f07eaa40trawick }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
8a3228198adb03e6996f7738c361a612777ecab6aaron fname = ap_server_root_relative(p, s->error_fname);
32c4bc04f89b16521718145dc731f750144d7b38wrowe if (!fname) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_error(APLOG_MARK, APLOG_STARTUP, APR_EBADPATH, NULL, APLOGNO(00090)
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung "%s: Invalid error log path %s.",
32c4bc04f89b16521718145dc731f750144d7b38wrowe ap_server_argv0, s->error_fname);
85c435ceda98eab940615e4466d9c5955252e745wrowe return DONE;
32c4bc04f89b16521718145dc731f750144d7b38wrowe }
32c4bc04f89b16521718145dc731f750144d7b38wrowe if ((rc = apr_file_open(&s->error_log, fname,
92eed7d377d8be7cd8e48d1299412fc8c742b7f5jorton APR_APPEND | APR_WRITE | APR_CREATE | APR_LARGEFILE,
32c4bc04f89b16521718145dc731f750144d7b38wrowe APR_OS_DEFAULT, p)) != APR_SUCCESS) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL, APLOGNO(00091)
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung "%s: could not open error log file %s.",
c25e9633c29be3a5b74f0bf75079d54e5417115dwrowe ap_server_argv0, fname);
85c435ceda98eab940615e4466d9c5955252e745wrowe return DONE;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
85c435ceda98eab940615e4466d9c5955252e745wrowe
85c435ceda98eab940615e4466d9c5955252e745wrowe return OK;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
e8f95a682820a599fe41b22977010636be5c2717jimint ap_open_logs(apr_pool_t *pconf, apr_pool_t *p /* plog */,
85c435ceda98eab940615e4466d9c5955252e745wrowe apr_pool_t *ptemp, server_rec *s_main)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
649c9dd342a580016d29c2866de88a4609eb6457wrowe apr_pool_t *stderr_p;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_rec *virt, *q;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int replace_stderr;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
649c9dd342a580016d29c2866de88a4609eb6457wrowe
649c9dd342a580016d29c2866de88a4609eb6457wrowe /* Register to throw away the read_handles list when we
649c9dd342a580016d29c2866de88a4609eb6457wrowe * cleanup plog. Upon fork() for the apache children,
649c9dd342a580016d29c2866de88a4609eb6457wrowe * this read_handles list is closed so only the parent
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * can relaunch a lost log child. These read handles
649c9dd342a580016d29c2866de88a4609eb6457wrowe * are always closed on exec.
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * We won't care what happens to our stderr log child
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * between log phases, so we don't mind losing stderr's
649c9dd342a580016d29c2866de88a4609eb6457wrowe * read_handle a little bit early.
649c9dd342a580016d29c2866de88a4609eb6457wrowe */
f6e47621625cca111811e84e407be84b5b18e9c5sf apr_pool_cleanup_register(p, &read_handles, ap_pool_cleanup_set_null,
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick apr_pool_cleanup_null);
649c9dd342a580016d29c2866de88a4609eb6457wrowe
649c9dd342a580016d29c2866de88a4609eb6457wrowe /* HERE we need a stdout log that outlives plog.
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * We *presume* the parent of plog is a process
649c9dd342a580016d29c2866de88a4609eb6457wrowe * or global pool which spans server restarts.
649c9dd342a580016d29c2866de88a4609eb6457wrowe * Create our stderr_pool as a child of the plog's
649c9dd342a580016d29c2866de88a4609eb6457wrowe * parent pool.
649c9dd342a580016d29c2866de88a4609eb6457wrowe */
649c9dd342a580016d29c2866de88a4609eb6457wrowe apr_pool_create(&stderr_p, apr_pool_parent_get(p));
649c9dd342a580016d29c2866de88a4609eb6457wrowe apr_pool_tag(stderr_p, "stderr_pool");
aef88024529c64e3e634c6f3f255e4419ad9182drjung
649c9dd342a580016d29c2866de88a4609eb6457wrowe if (open_error_log(s_main, 1, stderr_p) != OK) {
85c435ceda98eab940615e4466d9c5955252e745wrowe return DONE;
85c435ceda98eab940615e4466d9c5955252e745wrowe }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding replace_stderr = 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (s_main->error_log) {
ab43b4a17b2ac31ccb1cf280be8c42a8a314cecbjorton apr_status_t rv;
aef88024529c64e3e634c6f3f255e4419ad9182drjung
ab43b4a17b2ac31ccb1cf280be8c42a8a314cecbjorton /* Replace existing stderr with new log. */
066877f1a045103acfdd376d48cdd473c33f409bdougm apr_file_flush(s_main->error_log);
649c9dd342a580016d29c2866de88a4609eb6457wrowe rv = apr_file_dup2(stderr_log, s_main->error_log, stderr_p);
ab43b4a17b2ac31ccb1cf280be8c42a8a314cecbjorton if (rv != APR_SUCCESS) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s_main, APLOGNO(00092)
ec727afb817df0e5202135278c0d2902923cc980stoddard "unable to replace stderr with error_log");
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh else {
649c9dd342a580016d29c2866de88a4609eb6457wrowe /* We are done with stderr_pool, close it, killing
649c9dd342a580016d29c2866de88a4609eb6457wrowe * the previous generation's stderr logger
649c9dd342a580016d29c2866de88a4609eb6457wrowe */
649c9dd342a580016d29c2866de88a4609eb6457wrowe if (stderr_pool)
649c9dd342a580016d29c2866de88a4609eb6457wrowe apr_pool_destroy(stderr_pool);
649c9dd342a580016d29c2866de88a4609eb6457wrowe stderr_pool = stderr_p;
ec727afb817df0e5202135278c0d2902923cc980stoddard replace_stderr = 0;
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe /*
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe * Now that we have dup'ed s_main->error_log to stderr_log
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe * close it and set s_main->error_log to stderr_log. This avoids
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe * this fd being inherited by the next piped logger who would
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe * keep open the writing end of the pipe that this one uses
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe * as stdin. This in turn would prevent the piped logger from
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe * exiting.
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe */
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe apr_file_close(s_main->error_log);
188dff19ac1e71ffd25752d1a4f8d71f9f563305wrowe s_main->error_log = stderr_log;
ec727afb817df0e5202135278c0d2902923cc980stoddard }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* note that stderr may still need to be replaced with something
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * because it points to the old error log, or back to the tty
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * of the submitter.
0f57a69cc84c59eacda1179763ae42ca88f1a577wrowe * XXX: This is BS - /dev/null is non-portable
6850c836b8c7c688ef8a8ec280e798e1d0bfbf01trawick * errno-as-apr_status_t is also non-portable
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
72fb9432f4764a8f49b69b5010c39a5ddd16f173trawick
72fb9432f4764a8f49b69b5010c39a5ddd16f173trawick#ifdef WIN32
72fb9432f4764a8f49b69b5010c39a5ddd16f173trawick#define NULL_DEVICE "nul"
72fb9432f4764a8f49b69b5010c39a5ddd16f173trawick#else
72fb9432f4764a8f49b69b5010c39a5ddd16f173trawick#define NULL_DEVICE "/dev/null"
72fb9432f4764a8f49b69b5010c39a5ddd16f173trawick#endif
72fb9432f4764a8f49b69b5010c39a5ddd16f173trawick
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza if (replace_stderr) {
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza if (freopen(NULL_DEVICE, "w", stderr) == NULL) {
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza ap_log_error(APLOG_MARK, APLOG_CRIT, errno, s_main, APLOGNO(00093)
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza "unable to replace stderr with %s", NULL_DEVICE);
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza }
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza stderr_log = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding for (virt = s_main->next; virt; virt = virt->next) {
8a3228198adb03e6996f7738c361a612777ecab6aaron if (virt->error_fname) {
8a3228198adb03e6996f7738c361a612777ecab6aaron for (q=s_main; q != virt; q = q->next) {
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh if (q->error_fname != NULL
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh && strcmp(q->error_fname, virt->error_fname) == 0) {
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh break;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
8a3228198adb03e6996f7738c361a612777ecab6aaron if (q == virt) {
399cf0e5e061b49593817421b94305889fa6bc1fjorton if (open_error_log(virt, 0, p) != OK) {
85c435ceda98eab940615e4466d9c5955252e745wrowe return DONE;
85c435ceda98eab940615e4466d9c5955252e745wrowe }
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron else {
8a3228198adb03e6996f7738c361a612777ecab6aaron virt->error_log = q->error_log;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron }
96993ca23bcd7be8de934a111988e59e96187d81trawick else if (virt->errorlog_provider) {
96993ca23bcd7be8de934a111988e59e96187d81trawick /* separately-configured vhost-specific provider */
96993ca23bcd7be8de934a111988e59e96187d81trawick if (open_error_log(virt, 0, p) != OK) {
96993ca23bcd7be8de934a111988e59e96187d81trawick return DONE;
96993ca23bcd7be8de934a111988e59e96187d81trawick }
96993ca23bcd7be8de934a111988e59e96187d81trawick }
96993ca23bcd7be8de934a111988e59e96187d81trawick else if (s_main->errorlog_provider) {
96993ca23bcd7be8de934a111988e59e96187d81trawick /* inherit provider from s_main */
96993ca23bcd7be8de934a111988e59e96187d81trawick virt->errorlog_provider = s_main->errorlog_provider;
96993ca23bcd7be8de934a111988e59e96187d81trawick virt->errorlog_provider_handle = s_main->errorlog_provider_handle;
96993ca23bcd7be8de934a111988e59e96187d81trawick virt->error_log = NULL;
96993ca23bcd7be8de934a111988e59e96187d81trawick }
8a3228198adb03e6996f7738c361a612777ecab6aaron else {
8a3228198adb03e6996f7738c361a612777ecab6aaron virt->error_log = s_main->error_log;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
85c435ceda98eab940615e4466d9c5955252e745wrowe return OK;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
3d96ee83babeec32482c9082c9426340cee8c44dwroweAP_DECLARE(void) ap_error_log2stderr(server_rec *s) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_file_t *errfile = NULL;
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh apr_file_open_stderr(&errfile, s->process->pool);
4e1e8abb2a6e588366a4680b039b460fc5fe1ccdstoddard if (s->error_log != NULL) {
bdf833c0329ee171eb99efe9c037b6ed653c5007aaron apr_file_dup2(s->error_log, errfile, s->process->pool);
40303323ae9960bd38a0f03d2c10e897a7badd88rbb }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic int cpystrn(char *buf, const char *arg, int buflen)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char *end;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!arg)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf end = apr_cpystrn(buf, arg, buflen);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return end - buf;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
e34223f72e630187c4d8ac7c22da5096c833eb20trawick
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic int log_remote_address(const ap_errorlog_info *info, const char *arg,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char *buf, int buflen)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
c6c1730850cd8c7149f62efb3f5e8afa25e24f4fminfrin if (info->r && !(arg && *arg == 'c'))
4240daa133bbeddbc3141553879eda4fccfe93feminfrin return apr_snprintf(buf, buflen, "%s:%d", info->r->useragent_ip,
6d6cd31bddca0b7d9cf9d18e46cd2361530e24f3sf info->r->useragent_addr ? info->r->useragent_addr->port : 0);
49fd87ed00b95bdd7a4cfc874e5c5fe4a04faf5aminfrin else if (info->c)
c41be3600a58bd39a76d1215abcdbbd8e9b1c356minfrin return apr_snprintf(buf, buflen, "%s:%d", info->c->client_ip,
6d6cd31bddca0b7d9cf9d18e46cd2361530e24f3sf info->c->client_addr ? info->c->client_addr->port : 0);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic int log_local_address(const ap_errorlog_info *info, const char *arg,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char *buf, int buflen)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (info->c)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return apr_snprintf(buf, buflen, "%s:%d", info->c->local_ip,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf info->c->local_addr->port);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic int log_pid(const ap_errorlog_info *info, const char *arg,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char *buf, int buflen)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf pid_t pid = getpid();
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return apr_snprintf(buf, buflen, "%" APR_PID_T_FMT, pid);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic int log_tid(const ap_errorlog_info *info, const char *arg,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char *buf, int buflen)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf#if APR_HAS_THREADS
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int result;
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf#endif
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf#if HAVE_GETTID
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf if (arg && *arg == 'g') {
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf pid_t tid = syscall(SYS_gettid);
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf if (tid == -1)
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf return 0;
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf return apr_snprintf(buf, buflen, "%"APR_PID_T_FMT, tid);
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf }
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf#endif
b08558bf6a64f9501ad3eca34eaf4d978bd928cfsf#if APR_HAS_THREADS
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (ap_mpm_query(AP_MPMQ_IS_THREADED, &result) == APR_SUCCESS
e302f38fd646764ce1a1e1c578d794aef514a9e5sf && result != AP_MPMQ_NOT_SUPPORTED)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_os_thread_t tid = apr_os_thread_current();
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return apr_snprintf(buf, buflen, "%pT", &tid);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf#endif
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
efd83d1dd1a25688a3093c5a542ae16bacef62ddsf
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic int log_ctime(const ap_errorlog_info *info, const char *arg,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char *buf, int buflen)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int time_len = buflen;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int option = AP_CTIME_OPTION_NONE;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf while(arg && *arg) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf switch (*arg) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf case 'u': option |= AP_CTIME_OPTION_USEC;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf break;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf case 'c': option |= AP_CTIME_OPTION_COMPACT;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf break;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf arg++;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
e302f38fd646764ce1a1e1c578d794aef514a9e5sf ap_recent_ctime_ex(buf, apr_time_now(), option, &time_len);
baf4649272f3dabd48b095a23b3180cc0105dce6rjung
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* ap_recent_ctime_ex includes the trailing \0 in time_len */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return time_len - 1;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
573394373c777e1624a481160f3d02f8fb09f3ffrjung
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic int log_loglevel(const ap_errorlog_info *info, const char *arg,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char *buf, int buflen)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (info->level < 0)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return cpystrn(buf, priorities[info->level].t_name, buflen);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
fcf27b53e98b61c652f3e832561193b21046dd2drjung
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic int log_log_id(const ap_errorlog_info *info, const char *arg,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char *buf, int buflen)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * C: log conn log_id if available,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * c: log conn log id if available and not a once-per-request log line
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * else: log request log id if available
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (arg && !strcasecmp(arg, "c")) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (info->c && (*arg != 'C' || !info->r)) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return cpystrn(buf, info->c->log_id, buflen);
573394373c777e1624a481160f3d02f8fb09f3ffrjung }
2b484455736f4c30447aa852764f53282cbeb5ddrbb }
6c266c0dc27ed2972bfb14a8bd5428065c4b3a8bsf else if (info->rmain) {
6c266c0dc27ed2972bfb14a8bd5428065c4b3a8bsf return cpystrn(buf, info->rmain->log_id, buflen);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic int log_keepalives(const ap_errorlog_info *info, const char *arg,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char *buf, int buflen)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!info->c)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return apr_snprintf(buf, buflen, "%d", info->c->keepalives);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic int log_module_name(const ap_errorlog_info *info, const char *arg,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char *buf, int buflen)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return cpystrn(buf, ap_find_module_short_name(info->module_index), buflen);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic int log_file_line(const ap_errorlog_info *info, const char *arg,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char *buf, int buflen)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (info->file == NULL) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf const char *file = info->file;
0ef41d8e4b94d343e5b093c4dbd6ee61c1279401trawick#if defined(_OSD_POSIX) || defined(WIN32) || defined(__MVS__)
8a3228198adb03e6996f7738c361a612777ecab6aaron char tmp[256];
8a3228198adb03e6996f7738c361a612777ecab6aaron char *e = strrchr(file, '/');
6951b61f50b21aa93c224b8b0f4966377918ac34stoddard#ifdef WIN32
6951b61f50b21aa93c224b8b0f4966377918ac34stoddard if (!e) {
6951b61f50b21aa93c224b8b0f4966377918ac34stoddard e = strrchr(file, '\\');
6951b61f50b21aa93c224b8b0f4966377918ac34stoddard }
6951b61f50b21aa93c224b8b0f4966377918ac34stoddard#endif
8a3228198adb03e6996f7738c361a612777ecab6aaron
8a3228198adb03e6996f7738c361a612777ecab6aaron /* In OSD/POSIX, the compiler returns for __FILE__
8a3228198adb03e6996f7738c361a612777ecab6aaron * a string like: __FILE__="*POSIX(/usr/include/stdio.h)"
8a3228198adb03e6996f7738c361a612777ecab6aaron * (it even returns an absolute path for sources in
8a3228198adb03e6996f7738c361a612777ecab6aaron * the current directory). Here we try to strip this
8a3228198adb03e6996f7738c361a612777ecab6aaron * down to the basename.
8a3228198adb03e6996f7738c361a612777ecab6aaron */
8a3228198adb03e6996f7738c361a612777ecab6aaron if (e != NULL && e[1] != '\0') {
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_snprintf(tmp, sizeof(tmp), "%s", &e[1]);
8a3228198adb03e6996f7738c361a612777ecab6aaron e = &tmp[strlen(tmp)-1];
8a3228198adb03e6996f7738c361a612777ecab6aaron if (*e == ')') {
8a3228198adb03e6996f7738c361a612777ecab6aaron *e = '\0';
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron file = tmp;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
50e421c0e069853bb724f3d816cef543e447c844jorton#else /* _OSD_POSIX || WIN32 */
50e421c0e069853bb724f3d816cef543e447c844jorton const char *p;
50e421c0e069853bb724f3d816cef543e447c844jorton /* On Unix, __FILE__ may be an absolute path in a
50e421c0e069853bb724f3d816cef543e447c844jorton * VPATH build. */
50e421c0e069853bb724f3d816cef543e447c844jorton if (file[0] == '/' && (p = ap_strrchr_c(file, '/')) != NULL) {
50e421c0e069853bb724f3d816cef543e447c844jorton file = p + 1;
50e421c0e069853bb724f3d816cef543e447c844jorton }
50e421c0e069853bb724f3d816cef543e447c844jorton#endif /*_OSD_POSIX || WIN32 */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return apr_snprintf(buf, buflen, "%s(%d)", file, info->line);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic int log_apr_status(const ap_errorlog_info *info, const char *arg,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char *buf, int buflen)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_status_t status = info->status;
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf int len;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!status)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (status < APR_OS_START_EAIERR) {
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf len = apr_snprintf(buf, buflen, "(%d)", status);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else if (status < APR_OS_START_SYSERR) {
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf len = apr_snprintf(buf, buflen, "(EAI %d)",
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf status - APR_OS_START_EAIERR);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else if (status < 100000 + APR_OS_START_SYSERR) {
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf len = apr_snprintf(buf, buflen, "(OS %d)",
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf status - APR_OS_START_SYSERR);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else {
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf len = apr_snprintf(buf, buflen, "(os 0x%08x)",
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf status - APR_OS_START_SYSERR);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_strerror(status, buf + len, buflen - len);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += strlen(buf + len);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return len;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
9228509ac5da8374df4a5d50b7da139e7b31f8a3sfstatic int log_server_name(const ap_errorlog_info *info, const char *arg,
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf char *buf, int buflen)
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf{
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf if (info->r)
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf return cpystrn(buf, ap_get_server_name((request_rec *)info->r), buflen);
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf return 0;
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf}
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf
9228509ac5da8374df4a5d50b7da139e7b31f8a3sfstatic int log_virtual_host(const ap_errorlog_info *info, const char *arg,
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf char *buf, int buflen)
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf{
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf if (info->s)
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf return cpystrn(buf, info->s->server_hostname, buflen);
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf return 0;
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf}
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf
4497075b5e08b0c8ee89425a1758258ae80550fcsfstatic int log_table_entry(const apr_table_t *table, const char *name,
4497075b5e08b0c8ee89425a1758258ae80550fcsf char *buf, int buflen)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf#ifndef AP_UNSAFE_ERROR_LOG_UNESCAPED
4497075b5e08b0c8ee89425a1758258ae80550fcsf const char *value;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char scratch[MAX_STRING_LEN];
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
4497075b5e08b0c8ee89425a1758258ae80550fcsf if ((value = apr_table_get(table, name)) != NULL) {
4497075b5e08b0c8ee89425a1758258ae80550fcsf ap_escape_errorlog_item(scratch, value, MAX_STRING_LEN);
4497075b5e08b0c8ee89425a1758258ae80550fcsf return cpystrn(buf, scratch, buflen);
4497075b5e08b0c8ee89425a1758258ae80550fcsf }
4497075b5e08b0c8ee89425a1758258ae80550fcsf
4497075b5e08b0c8ee89425a1758258ae80550fcsf return 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf#else
4497075b5e08b0c8ee89425a1758258ae80550fcsf return cpystrn(buf, apr_table_get(table, name), buflen);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf#endif
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
4497075b5e08b0c8ee89425a1758258ae80550fcsfstatic int log_header(const ap_errorlog_info *info, const char *arg,
4497075b5e08b0c8ee89425a1758258ae80550fcsf char *buf, int buflen)
4497075b5e08b0c8ee89425a1758258ae80550fcsf{
4497075b5e08b0c8ee89425a1758258ae80550fcsf if (info->r)
4497075b5e08b0c8ee89425a1758258ae80550fcsf return log_table_entry(info->r->headers_in, arg, buf, buflen);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
4497075b5e08b0c8ee89425a1758258ae80550fcsf return 0;
4497075b5e08b0c8ee89425a1758258ae80550fcsf}
4497075b5e08b0c8ee89425a1758258ae80550fcsf
4497075b5e08b0c8ee89425a1758258ae80550fcsfstatic int log_note(const ap_errorlog_info *info, const char *arg,
4497075b5e08b0c8ee89425a1758258ae80550fcsf char *buf, int buflen)
4497075b5e08b0c8ee89425a1758258ae80550fcsf{
4497075b5e08b0c8ee89425a1758258ae80550fcsf /* XXX: maybe escaping the entry is not necessary for notes? */
4497075b5e08b0c8ee89425a1758258ae80550fcsf if (info->r)
4497075b5e08b0c8ee89425a1758258ae80550fcsf return log_table_entry(info->r->notes, arg, buf, buflen);
4497075b5e08b0c8ee89425a1758258ae80550fcsf
4497075b5e08b0c8ee89425a1758258ae80550fcsf return 0;
4497075b5e08b0c8ee89425a1758258ae80550fcsf}
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
4497075b5e08b0c8ee89425a1758258ae80550fcsfstatic int log_env_var(const ap_errorlog_info *info, const char *arg,
4497075b5e08b0c8ee89425a1758258ae80550fcsf char *buf, int buflen)
4497075b5e08b0c8ee89425a1758258ae80550fcsf{
4497075b5e08b0c8ee89425a1758258ae80550fcsf if (info->r)
4497075b5e08b0c8ee89425a1758258ae80550fcsf return log_table_entry(info->r->subprocess_env, arg, buf, buflen);
4497075b5e08b0c8ee89425a1758258ae80550fcsf
4497075b5e08b0c8ee89425a1758258ae80550fcsf return 0;
4497075b5e08b0c8ee89425a1758258ae80550fcsf}
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
ce4dc40a4e87991087488f70d96d3447d7557294sfstatic int core_generate_log_id(const conn_rec *c, const request_rec *r,
ce4dc40a4e87991087488f70d96d3447d7557294sf const char **idstring)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_uint64_t id, tmp;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf pid_t pid;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int len;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char *encoded;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (r && r->request_time) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf id = (apr_uint64_t)r->request_time;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf id = (apr_uint64_t)apr_time_now();
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
e302f38fd646764ce1a1e1c578d794aef514a9e5sf pid = getpid();
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (sizeof(pid_t) > 2) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf tmp = pid;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf tmp = tmp << 40;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf id ^= tmp;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf pid = pid >> 24;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf tmp = pid;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf tmp = tmp << 56;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf id ^= tmp;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf tmp = pid;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf tmp = tmp << 40;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf id ^= tmp;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf#if APR_HAS_THREADS
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_uintptr_t tmp2 = (apr_uintptr_t)c->current_thread;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf tmp = tmp2;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf tmp = tmp << 32;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf id ^= tmp;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf#endif
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
06bc0ed097a567a63ec01ce7b8044221478cb5cdsf len = apr_base64_encode_len(sizeof(id)); /* includes trailing \0 */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf encoded = apr_palloc(r ? r->pool : c->pool, len);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_base64_encode(encoded, (char *)&id, sizeof(id));
b32d756dae79045a9bc90e0d0b85582f6f28eaf3sf
06bc0ed097a567a63ec01ce7b8044221478cb5cdsf /* Skip the last char, it is always '=' */
ce4dc40a4e87991087488f70d96d3447d7557294sf encoded[len - 2] = '\0';
ce4dc40a4e87991087488f70d96d3447d7557294sf
ce4dc40a4e87991087488f70d96d3447d7557294sf *idstring = encoded;
ce4dc40a4e87991087488f70d96d3447d7557294sf
ce4dc40a4e87991087488f70d96d3447d7557294sf return OK;
ce4dc40a4e87991087488f70d96d3447d7557294sf}
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
ce4dc40a4e87991087488f70d96d3447d7557294sfstatic void add_log_id(const conn_rec *c, const request_rec *r)
ce4dc40a4e87991087488f70d96d3447d7557294sf{
ce4dc40a4e87991087488f70d96d3447d7557294sf const char **id;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* need to cast const away */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (r) {
ce4dc40a4e87991087488f70d96d3447d7557294sf id = &((request_rec *)r)->log_id;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else {
ce4dc40a4e87991087488f70d96d3447d7557294sf id = &((conn_rec *)c)->log_id;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
ce4dc40a4e87991087488f70d96d3447d7557294sf
ce4dc40a4e87991087488f70d96d3447d7557294sf ap_run_generate_log_id(c, r, id);
ce4dc40a4e87991087488f70d96d3447d7557294sf}
ce4dc40a4e87991087488f70d96d3447d7557294sf
ce4dc40a4e87991087488f70d96d3447d7557294sfAP_DECLARE(void) ap_register_log_hooks(apr_pool_t *p)
ce4dc40a4e87991087488f70d96d3447d7557294sf{
ce4dc40a4e87991087488f70d96d3447d7557294sf ap_hook_generate_log_id(core_generate_log_id, NULL, NULL,
ce4dc40a4e87991087488f70d96d3447d7557294sf APR_HOOK_REALLY_LAST);
ce4dc40a4e87991087488f70d96d3447d7557294sf
ce4dc40a4e87991087488f70d96d3447d7557294sf ap_register_errorlog_handler(p, "a", log_remote_address, 0);
ce4dc40a4e87991087488f70d96d3447d7557294sf ap_register_errorlog_handler(p, "A", log_local_address, 0);
ce4dc40a4e87991087488f70d96d3447d7557294sf ap_register_errorlog_handler(p, "e", log_env_var, 0);
ce4dc40a4e87991087488f70d96d3447d7557294sf ap_register_errorlog_handler(p, "E", log_apr_status, 0);
ce4dc40a4e87991087488f70d96d3447d7557294sf ap_register_errorlog_handler(p, "F", log_file_line, 0);
ce4dc40a4e87991087488f70d96d3447d7557294sf ap_register_errorlog_handler(p, "i", log_header, 0);
ce4dc40a4e87991087488f70d96d3447d7557294sf ap_register_errorlog_handler(p, "k", log_keepalives, 0);
ce4dc40a4e87991087488f70d96d3447d7557294sf ap_register_errorlog_handler(p, "l", log_loglevel, 0);
ce4dc40a4e87991087488f70d96d3447d7557294sf ap_register_errorlog_handler(p, "L", log_log_id, 0);
ce4dc40a4e87991087488f70d96d3447d7557294sf ap_register_errorlog_handler(p, "m", log_module_name, 0);
ce4dc40a4e87991087488f70d96d3447d7557294sf ap_register_errorlog_handler(p, "n", log_note, 0);
ce4dc40a4e87991087488f70d96d3447d7557294sf ap_register_errorlog_handler(p, "P", log_pid, 0);
ce4dc40a4e87991087488f70d96d3447d7557294sf ap_register_errorlog_handler(p, "t", log_ctime, 0);
ce4dc40a4e87991087488f70d96d3447d7557294sf ap_register_errorlog_handler(p, "T", log_tid, 0);
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf ap_register_errorlog_handler(p, "v", log_virtual_host, 0);
9228509ac5da8374df4a5d50b7da139e7b31f8a3sf ap_register_errorlog_handler(p, "V", log_server_name, 0);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf/*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * This is used if no error log format is defined and during startup.
56589be3d7a3e9343370df240010c6928cc78b39jkaluza * It automatically omits the timestamp if logging using provider.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic int do_errorlog_default(const ap_errorlog_info *info, char *buf,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int buflen, int *errstr_start, int *errstr_end,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf const char *errstr_fmt, va_list args)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int len = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int field_start = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int item_len;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf#ifndef AP_UNSAFE_ERROR_LOG_UNESCAPED
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char scratch[MAX_STRING_LEN];
e302f38fd646764ce1a1e1c578d794aef514a9e5sf#endif
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
56589be3d7a3e9343370df240010c6928cc78b39jkaluza if (!info->using_provider && !info->startup) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf buf[len++] = '[';
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += log_ctime(info, "u", buf + len, buflen - len);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf buf[len++] = ']';
e302f38fd646764ce1a1e1c578d794aef514a9e5sf buf[len++] = ' ';
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!info->startup) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf buf[len++] = '[';
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += log_module_name(info, NULL, buf + len, buflen - len);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf buf[len++] = ':';
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += log_loglevel(info, NULL, buf + len, buflen - len);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += cpystrn(buf + len, "] [pid ", buflen - len);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += log_pid(info, NULL, buf + len, buflen - len);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf#if APR_HAS_THREADS
e302f38fd646764ce1a1e1c578d794aef514a9e5sf field_start = len;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += cpystrn(buf + len, ":tid ", buflen - len);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf item_len = log_tid(info, NULL, buf + len, buflen - len);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!item_len)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len = field_start;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += item_len;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf#endif
e302f38fd646764ce1a1e1c578d794aef514a9e5sf buf[len++] = ']';
e302f38fd646764ce1a1e1c578d794aef514a9e5sf buf[len++] = ' ';
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (info->level >= APLOG_DEBUG) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf item_len = log_file_line(info, NULL, buf + len, buflen - len);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (item_len) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += item_len;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += cpystrn(buf + len, ": ", buflen - len);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (info->status) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf item_len = log_apr_status(info, NULL, buf + len, buflen - len);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (item_len) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += item_len;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += cpystrn(buf + len, ": ", buflen - len);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
49fd87ed00b95bdd7a4cfc874e5c5fe4a04faf5aminfrin /*
c41be3600a58bd39a76d1215abcdbbd8e9b1c356minfrin * useragent_ip/client_ip can be client or backend server. If we have
4240daa133bbeddbc3141553879eda4fccfe93feminfrin * a scoreboard handle, it is likely a client.
49fd87ed00b95bdd7a4cfc874e5c5fe4a04faf5aminfrin */
49fd87ed00b95bdd7a4cfc874e5c5fe4a04faf5aminfrin if (info->r) {
49fd87ed00b95bdd7a4cfc874e5c5fe4a04faf5aminfrin len += apr_snprintf(buf + len, buflen - len,
49fd87ed00b95bdd7a4cfc874e5c5fe4a04faf5aminfrin info->r->connection->sbh ? "[client %s:%d] " : "[remote %s:%d] ",
6d6cd31bddca0b7d9cf9d18e46cd2361530e24f3sf info->r->useragent_ip,
6d6cd31bddca0b7d9cf9d18e46cd2361530e24f3sf info->r->useragent_addr ? info->r->useragent_addr->port : 0);
49fd87ed00b95bdd7a4cfc874e5c5fe4a04faf5aminfrin }
49fd87ed00b95bdd7a4cfc874e5c5fe4a04faf5aminfrin else if (info->c) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += apr_snprintf(buf + len, buflen - len,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf info->c->sbh ? "[client %s:%d] " : "[remote %s:%d] ",
6d6cd31bddca0b7d9cf9d18e46cd2361530e24f3sf info->c->client_ip,
6d6cd31bddca0b7d9cf9d18e46cd2361530e24f3sf info->c->client_addr ? info->c->client_addr->port : 0);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
82acfa3f57607ae78326104c420a317260554a47nd
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* the actual error message */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf *errstr_start = len;
9fe315e66ef597a158db81bcbd230d7a5d65785dnd#ifndef AP_UNSAFE_ERROR_LOG_UNESCAPED
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (apr_vsnprintf(scratch, MAX_STRING_LEN, errstr_fmt, args)) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += ap_escape_errorlog_item(buf + len, scratch,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf buflen - len);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
82acfa3f57607ae78326104c420a317260554a47nd }
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd#else
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += apr_vsnprintf(buf + len, buflen - len, errstr_fmt, args);
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd#endif
e302f38fd646764ce1a1e1c578d794aef514a9e5sf *errstr_end = len;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
e302f38fd646764ce1a1e1c578d794aef514a9e5sf field_start = len;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += cpystrn(buf + len, ", referer: ", buflen - len);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf item_len = log_header(info, "Referer", buf + len, buflen - len);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (item_len)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += item_len;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len = field_start;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return len;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic int do_errorlog_format(apr_array_header_t *fmt, ap_errorlog_info *info,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char *buf, int buflen, int *errstr_start,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int *errstr_end, const char *err_fmt, va_list args)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
9fe315e66ef597a158db81bcbd230d7a5d65785dnd#ifndef AP_UNSAFE_ERROR_LOG_UNESCAPED
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char scratch[MAX_STRING_LEN];
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd#endif
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int i;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int len = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int field_start = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int skipping = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf ap_errorlog_format_item *items = (ap_errorlog_format_item *)fmt->elts;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
1a7f1b3d185e1f02465b9c4cb19ccb57d90dcb31sf AP_DEBUG_ASSERT(fmt->nelts > 0);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf for (i = 0; i < fmt->nelts; ++i) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf ap_errorlog_format_item *item = &items[i];
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (item->flags & AP_ERRORLOG_FLAG_FIELD_SEP) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (skipping) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf skipping = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf field_start = len;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (item->flags & AP_ERRORLOG_FLAG_MESSAGE) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* the actual error message */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf *errstr_start = len;
9fe315e66ef597a158db81bcbd230d7a5d65785dnd#ifndef AP_UNSAFE_ERROR_LOG_UNESCAPED
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (apr_vsnprintf(scratch, MAX_STRING_LEN, err_fmt, args)) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += ap_escape_errorlog_item(buf + len, scratch,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf buflen - len);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd#else
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += apr_vsnprintf(buf + len, buflen - len, err_fmt, args);
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd#endif
e302f38fd646764ce1a1e1c578d794aef514a9e5sf *errstr_end = len;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else if (skipping) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf continue;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
ee2c610570b9e159784e87e72d1c17f459b85768sf else if (info->level != -1 && (int)item->min_loglevel > info->level) {
b5c4b00201fdc3ed11c6cc05cf3f9a7912ac0cfbsf len = field_start;
b5c4b00201fdc3ed11c6cc05cf3f9a7912ac0cfbsf skipping = 1;
b5c4b00201fdc3ed11c6cc05cf3f9a7912ac0cfbsf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int item_len = (*item->func)(info, item->arg, buf + len,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf buflen - len);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (!item_len) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (item->flags & AP_ERRORLOG_FLAG_REQUIRED) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* required item is empty. skip whole line */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf buf[0] = '\0';
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else if (item->flags & AP_ERRORLOG_FLAG_NULL_AS_HYPHEN) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf buf[len++] = '-';
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len = field_start;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf skipping = 1;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += item_len;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
d2e443764d6855a4a06c8eb2b7708ab9b465ddeerbb }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return len;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
d2e443764d6855a4a06c8eb2b7708ab9b465ddeerbb
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic void write_logline(char *errstr, apr_size_t len, apr_file_t *logf,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int level)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
56589be3d7a3e9343370df240010c6928cc78b39jkaluza
56589be3d7a3e9343370df240010c6928cc78b39jkaluza apr_file_puts(errstr, logf);
56589be3d7a3e9343370df240010c6928cc78b39jkaluza apr_file_flush(logf);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf}
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sfstatic void log_error_core(const char *file, int line, int module_index,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int level,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_status_t status, const server_rec *s,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf const conn_rec *c,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf const request_rec *r, apr_pool_t *pool,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf const char *fmt, va_list args)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf{
e302f38fd646764ce1a1e1c578d794aef514a9e5sf char errstr[MAX_STRING_LEN];
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_file_t *logf = NULL;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int level_and_mask = level & APLOG_LEVELMASK;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf const request_rec *rmain = NULL;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf core_server_config *sconf = NULL;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf ap_errorlog_info info;
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza ap_errorlog_provider *errorlog_provider = NULL;
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza void *errorlog_provider_handle = NULL;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* do we need to log once-per-req or once-per-conn info? */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int log_conn_info = 0, log_req_info = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_array_header_t **lines = NULL;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int done = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int line_number = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
1a7f1b3d185e1f02465b9c4cb19ccb57d90dcb31sf if (r) {
1a7f1b3d185e1f02465b9c4cb19ccb57d90dcb31sf AP_DEBUG_ASSERT(r->connection != NULL);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf c = r->connection;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (s == NULL) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * If we are doing stderr logging (startup), don't log messages that are
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * above the default server log level unless it is a startup/shutdown
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * notice
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf#ifndef DEBUG
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if ((level_and_mask != APLOG_NOTICE)
e302f38fd646764ce1a1e1c578d794aef514a9e5sf && (level_and_mask > ap_default_loglevel)) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf return;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf#endif
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf logf = stderr_log;
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza if (!logf && ap_server_conf && ap_server_conf->errorlog_provider) {
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza errorlog_provider = ap_server_conf->errorlog_provider;
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza errorlog_provider_handle = ap_server_conf->errorlog_provider_handle;
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int configured_level = r ? ap_get_request_module_loglevel(r, module_index) :
e302f38fd646764ce1a1e1c578d794aef514a9e5sf c ? ap_get_conn_server_module_loglevel(c, s, module_index) :
e302f38fd646764ce1a1e1c578d794aef514a9e5sf ap_get_server_module_loglevel(s, module_index);
ac7ac5b79da100d59b176914c0d9448fadc03568trawick /*
ac7ac5b79da100d59b176914c0d9448fadc03568trawick * If we are doing normal logging, don't log messages that are
ac7ac5b79da100d59b176914c0d9448fadc03568trawick * above the module's log level unless it is a startup/shutdown notice
ac7ac5b79da100d59b176914c0d9448fadc03568trawick */
ac7ac5b79da100d59b176914c0d9448fadc03568trawick if ((level_and_mask != APLOG_NOTICE)
ac7ac5b79da100d59b176914c0d9448fadc03568trawick && (level_and_mask > configured_level)) {
ac7ac5b79da100d59b176914c0d9448fadc03568trawick return;
ac7ac5b79da100d59b176914c0d9448fadc03568trawick }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
ac7ac5b79da100d59b176914c0d9448fadc03568trawick if (s->error_log) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf logf = s->error_log;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza errorlog_provider = s->errorlog_provider;
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza errorlog_provider_handle = s->errorlog_provider_handle;
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza
a8eeeed944c5d1986ab92649271d29839abd1155sf /* the faked server_rec from mod_cgid does not have s->module_config */
a8eeeed944c5d1986ab92649271d29839abd1155sf if (s->module_config) {
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf sconf = ap_get_core_module_config(s->module_config);
a8eeeed944c5d1986ab92649271d29839abd1155sf if (c && !c->log_id) {
a8eeeed944c5d1986ab92649271d29839abd1155sf add_log_id(c, NULL);
a8eeeed944c5d1986ab92649271d29839abd1155sf if (sconf->error_log_conn && sconf->error_log_conn->nelts > 0)
a8eeeed944c5d1986ab92649271d29839abd1155sf log_conn_info = 1;
a8eeeed944c5d1986ab92649271d29839abd1155sf }
a8eeeed944c5d1986ab92649271d29839abd1155sf if (r) {
a8eeeed944c5d1986ab92649271d29839abd1155sf if (r->main)
a8eeeed944c5d1986ab92649271d29839abd1155sf rmain = r->main;
a8eeeed944c5d1986ab92649271d29839abd1155sf else
a8eeeed944c5d1986ab92649271d29839abd1155sf rmain = r;
a8eeeed944c5d1986ab92649271d29839abd1155sf
a8eeeed944c5d1986ab92649271d29839abd1155sf if (!rmain->log_id) {
a8eeeed944c5d1986ab92649271d29839abd1155sf /* XXX: do we need separate log ids for subrequests? */
a8eeeed944c5d1986ab92649271d29839abd1155sf if (sconf->error_log_req && sconf->error_log_req->nelts > 0)
a8eeeed944c5d1986ab92649271d29839abd1155sf log_req_info = 1;
a8eeeed944c5d1986ab92649271d29839abd1155sf /*
a8eeeed944c5d1986ab92649271d29839abd1155sf * XXX: potential optimization: only create log id if %L is
a8eeeed944c5d1986ab92649271d29839abd1155sf * XXX: actually used
a8eeeed944c5d1986ab92649271d29839abd1155sf */
a8eeeed944c5d1986ab92649271d29839abd1155sf add_log_id(c, rmain);
a8eeeed944c5d1986ab92649271d29839abd1155sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
db8a047604be99acfb4849ae58a476e9b5872d86trawick if (!logf && !(errorlog_provider && errorlog_provider_handle)) {
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza /* There is no file to send the log message to (or it is
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza * redirected to /dev/null and therefore any formating done below
db8a047604be99acfb4849ae58a476e9b5872d86trawick * would be lost anyway) and there is no initialized log provider
db8a047604be99acfb4849ae58a476e9b5872d86trawick * available, so we just return here.
db8a047604be99acfb4849ae58a476e9b5872d86trawick */
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza return;
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza }
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza
e302f38fd646764ce1a1e1c578d794aef514a9e5sf info.s = s;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf info.c = c;
f91e8c44b15a74bedaa027128a695950807e2968sf info.pool = pool;
d0dd61ab83a7627cf62e0486ed3cef7843ce3aa3sf info.file = NULL;
d0dd61ab83a7627cf62e0486ed3cef7843ce3aa3sf info.line = 0;
d0dd61ab83a7627cf62e0486ed3cef7843ce3aa3sf info.status = 0;
56589be3d7a3e9343370df240010c6928cc78b39jkaluza info.using_provider= (logf == NULL);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf info.startup = ((level & APLOG_STARTUP) == APLOG_STARTUP);
7f630e66c9c37e797e1c06bf7b259c0859538978trawick info.format = fmt;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf while (!done) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf apr_array_header_t *log_format;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf int len = 0, errstr_start = 0, errstr_end = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* XXX: potential optimization: format common prefixes only once */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (log_conn_info) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* once-per-connection info */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (line_number == 0) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf lines = (apr_array_header_t **)sconf->error_log_conn->elts;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf info.r = NULL;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf info.rmain = NULL;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf info.level = -1;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf info.module_index = APLOG_NO_MODULE;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
e302f38fd646764ce1a1e1c578d794aef514a9e5sf log_format = lines[line_number++];
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (line_number == sconf->error_log_conn->nelts) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* this is the last line of once-per-connection info */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf line_number = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf log_conn_info = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else if (log_req_info) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* once-per-request info */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (line_number == 0) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf lines = (apr_array_header_t **)sconf->error_log_req->elts;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf info.r = rmain;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf info.rmain = rmain;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf info.level = -1;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf info.module_index = APLOG_NO_MODULE;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf log_format = lines[line_number++];
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf if (line_number == sconf->error_log_req->nelts) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* this is the last line of once-per-request info */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf line_number = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf log_req_info = 0;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /* the actual error message */
d0dd61ab83a7627cf62e0486ed3cef7843ce3aa3sf info.r = r;
d0dd61ab83a7627cf62e0486ed3cef7843ce3aa3sf info.rmain = rmain;
d0dd61ab83a7627cf62e0486ed3cef7843ce3aa3sf info.level = level_and_mask;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf info.module_index = module_index;
d0dd61ab83a7627cf62e0486ed3cef7843ce3aa3sf info.file = file;
d0dd61ab83a7627cf62e0486ed3cef7843ce3aa3sf info.line = line;
d0dd61ab83a7627cf62e0486ed3cef7843ce3aa3sf info.status = status;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf log_format = sconf ? sconf->error_log_format : NULL;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf done = 1;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * prepare and log one line
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
85af5dafbbd8ae9f496e4349ec0d7b0411439a71trawick if (log_format && !info.startup) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += do_errorlog_format(log_format, &info, errstr + len,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf MAX_STRING_LEN - len,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf &errstr_start, &errstr_end, fmt, args);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf else {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf len += do_errorlog_default(&info, errstr + len, MAX_STRING_LEN - len,
e302f38fd646764ce1a1e1c578d794aef514a9e5sf &errstr_start, &errstr_end, fmt, args);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
caf2d4d30912e0b4c354cb0f038d82fdba56307ctrawick if (!*errstr) {
e302f38fd646764ce1a1e1c578d794aef514a9e5sf /*
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * Don't log empty lines. This can happen with once-per-conn/req
e302f38fd646764ce1a1e1c578d794aef514a9e5sf * info if an item with AP_ERRORLOG_FLAG_REQUIRED is NULL.
e302f38fd646764ce1a1e1c578d794aef514a9e5sf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf continue;
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
56589be3d7a3e9343370df240010c6928cc78b39jkaluza
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza if (logf || (errorlog_provider->flags &
7cac5c72d80c4dc740e6ae7bae29d41ffdbd4b05jkaluza AP_ERRORLOG_PROVIDER_ADD_EOL_STR)) {
7cac5c72d80c4dc740e6ae7bae29d41ffdbd4b05jkaluza /* Truncate for the terminator (as apr_snprintf does) */
7cac5c72d80c4dc740e6ae7bae29d41ffdbd4b05jkaluza if (len > MAX_STRING_LEN - sizeof(APR_EOL_STR)) {
7cac5c72d80c4dc740e6ae7bae29d41ffdbd4b05jkaluza len = MAX_STRING_LEN - sizeof(APR_EOL_STR);
7cac5c72d80c4dc740e6ae7bae29d41ffdbd4b05jkaluza }
7cac5c72d80c4dc740e6ae7bae29d41ffdbd4b05jkaluza strcpy(errstr + len, APR_EOL_STR);
d02f97c349f0992041f5ea3cad92885ed4c484f6trawick len += strlen(APR_EOL_STR);
7cac5c72d80c4dc740e6ae7bae29d41ffdbd4b05jkaluza }
7cac5c72d80c4dc740e6ae7bae29d41ffdbd4b05jkaluza
56589be3d7a3e9343370df240010c6928cc78b39jkaluza if (logf) {
56589be3d7a3e9343370df240010c6928cc78b39jkaluza write_logline(errstr, len, logf, level_and_mask);
56589be3d7a3e9343370df240010c6928cc78b39jkaluza }
56589be3d7a3e9343370df240010c6928cc78b39jkaluza else {
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza errorlog_provider->writer(&info, errorlog_provider_handle,
5cf689302f66ca316fc1108ad4c1d096760ab482jkaluza errstr, len);
56589be3d7a3e9343370df240010c6928cc78b39jkaluza }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e11c9fa326e7bfa48bd9be5bae7037ae76b2612dsf if (done) {
e11c9fa326e7bfa48bd9be5bae7037ae76b2612dsf /*
e11c9fa326e7bfa48bd9be5bae7037ae76b2612dsf * We don't call the error_log hook for per-request/per-conn
e11c9fa326e7bfa48bd9be5bae7037ae76b2612dsf * lines, and we only pass the actual log message, not the
e11c9fa326e7bfa48bd9be5bae7037ae76b2612dsf * prefix and suffix.
e11c9fa326e7bfa48bd9be5bae7037ae76b2612dsf */
e302f38fd646764ce1a1e1c578d794aef514a9e5sf errstr[errstr_end] = '\0';
f91e8c44b15a74bedaa027128a695950807e2968sf ap_run_error_log(&info, errstr + errstr_start);
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
e302f38fd646764ce1a1e1c578d794aef514a9e5sf
e302f38fd646764ce1a1e1c578d794aef514a9e5sf *errstr = '\0';
e302f38fd646764ce1a1e1c578d794aef514a9e5sf }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick/* For internal calls to log_error_core with self-composed arg lists */
f87299dab99bc04b51a6b8cad51b6795db862c0atrawickstatic void log_error_va_glue(const char *file, int line, int module_index,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick int level, apr_status_t status,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick const server_rec *s, const conn_rec *c,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick const request_rec *r, apr_pool_t *pool,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick const char *fmt, ...)
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick{
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick va_list args;
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick va_start(args, fmt);
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick log_error_core(file, line, module_index, level, status, s, c, r, pool,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick fmt, args);
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick va_end(args);
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick}
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sfAP_DECLARE(void) ap_log_error_(const char *file, int line, int module_index,
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf int level, apr_status_t status,
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf const server_rec *s, const char *fmt, ...)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding va_list args;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding va_start(args, fmt);
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf log_error_core(file, line, module_index, level, status, s, NULL, NULL,
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf NULL, fmt, args);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb va_end(args);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb}
3597d6b10c88c252f156fe8061b659a38dea38c2rbb
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sfAP_DECLARE(void) ap_log_perror_(const char *file, int line, int module_index,
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf int level, apr_status_t status, apr_pool_t *p,
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf const char *fmt, ...)
3597d6b10c88c252f156fe8061b659a38dea38c2rbb{
3597d6b10c88c252f156fe8061b659a38dea38c2rbb va_list args;
3597d6b10c88c252f156fe8061b659a38dea38c2rbb
3597d6b10c88c252f156fe8061b659a38dea38c2rbb va_start(args, fmt);
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf log_error_core(file, line, module_index, level, status, NULL, NULL, NULL,
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf p, fmt, args);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding va_end(args);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sfAP_DECLARE(void) ap_log_rerror_(const char *file, int line, int module_index,
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf int level, apr_status_t status,
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf const request_rec *r, const char *fmt, ...)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding va_list args;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding va_start(args, fmt);
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf log_error_core(file, line, module_index, level, status, r->server, NULL, r,
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf NULL, fmt, args);
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
2b13bc45632d72cdf50ac42149e4fc8bc0d05bf2stoddard * IF APLOG_TOCLIENT is set,
2b13bc45632d72cdf50ac42149e4fc8bc0d05bf2stoddard * AND the error level is 'warning' or more severe,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * AND there isn't already error text associated with this request,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * THEN make the message text available to ErrorDocument and
2b13bc45632d72cdf50ac42149e4fc8bc0d05bf2stoddard * other error processors.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding va_end(args);
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh va_start(args,fmt);
2b13bc45632d72cdf50ac42149e4fc8bc0d05bf2stoddard if ((level & APLOG_TOCLIENT)
2b13bc45632d72cdf50ac42149e4fc8bc0d05bf2stoddard && ((level & APLOG_LEVELMASK) <= APLOG_WARNING)
8a3228198adb03e6996f7738c361a612777ecab6aaron && (apr_table_get(r->notes, "error-notes") == NULL)) {
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_table_setn(r->notes, "error-notes",
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh ap_escape_html(r->pool, apr_pvsprintf(r->pool, fmt,
8a3228198adb03e6996f7738c361a612777ecab6aaron args)));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding va_end(args);
e34223f72e630187c4d8ac7c22da5096c833eb20trawick}
e34223f72e630187c4d8ac7c22da5096c833eb20trawick
7538cfc9bcb1132e87011484b826c0d8bff9cc73sfAP_DECLARE(void) ap_log_cserror_(const char *file, int line, int module_index,
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf int level, apr_status_t status,
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf const conn_rec *c, const server_rec *s,
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf const char *fmt, ...)
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf{
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf va_list args;
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf va_start(args, fmt);
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf log_error_core(file, line, module_index, level, status, s, c,
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf NULL, NULL, fmt, args);
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf va_end(args);
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf}
7538cfc9bcb1132e87011484b826c0d8bff9cc73sf
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sfAP_DECLARE(void) ap_log_cerror_(const char *file, int line, int module_index,
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf int level, apr_status_t status,
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf const conn_rec *c, const char *fmt, ...)
e34223f72e630187c4d8ac7c22da5096c833eb20trawick{
e34223f72e630187c4d8ac7c22da5096c833eb20trawick va_list args;
e34223f72e630187c4d8ac7c22da5096c833eb20trawick
e34223f72e630187c4d8ac7c22da5096c833eb20trawick va_start(args, fmt);
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf log_error_core(file, line, module_index, level, status, c->base_server, c,
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf NULL, NULL, fmt, args);
e34223f72e630187c4d8ac7c22da5096c833eb20trawick va_end(args);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick#define BYTES_LOGGED_PER_LINE 16
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick#define LOG_BYTES_BUFFER_SIZE (BYTES_LOGGED_PER_LINE * 3 + 2)
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick
f87299dab99bc04b51a6b8cad51b6795db862c0atrawickstatic void fmt_data(unsigned char *buf, const void *vdata, apr_size_t len, apr_size_t *off)
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick{
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick const unsigned char *data = (const unsigned char *)vdata;
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick unsigned char *chars;
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick unsigned char *hex;
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick apr_size_t this_time = 0;
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick memset(buf, ' ', LOG_BYTES_BUFFER_SIZE - 1);
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick buf[LOG_BYTES_BUFFER_SIZE - 1] = '\0';
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick chars = buf; /* start character dump here */
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick hex = buf + BYTES_LOGGED_PER_LINE + 1; /* start hex dump here */
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick while (*off < len && this_time < BYTES_LOGGED_PER_LINE) {
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick unsigned char c = data[*off];
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick
a79a6e9f0db6b6327053b0357f1d155b71db8182trawick if (apr_isprint(c)
8e5d0fabc3ffbdfc8cfd9f61891f505e5204d72djailletc && c != '\\') { /* backslash will be escaped later, which throws
a79a6e9f0db6b6327053b0357f1d155b71db8182trawick * off the formatting
a79a6e9f0db6b6327053b0357f1d155b71db8182trawick */
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick *chars = c;
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick }
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick else {
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick *chars = '.';
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick }
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick if ((c >> 4) >= 10) {
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick *hex = 'a' + ((c >> 4) - 10);
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick }
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick else {
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick *hex = '0' + (c >> 4);
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick }
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick if ((c & 0x0F) >= 10) {
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick *(hex + 1) = 'a' + ((c & 0x0F) - 10);
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick }
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick else {
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick *(hex + 1) = '0' + (c & 0x0F);
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick }
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick chars += 1;
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick hex += 2;
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick *off += 1;
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick ++this_time;
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick }
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick}
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick
f87299dab99bc04b51a6b8cad51b6795db862c0atrawickstatic void log_data_core(const char *file, int line, int module_index,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick int level, const server_rec *s,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick const conn_rec *c, const request_rec *r,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick const char *label, const void *data, apr_size_t len,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick unsigned int flags)
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick{
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick unsigned char buf[LOG_BYTES_BUFFER_SIZE];
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick apr_size_t off;
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick char prefix[20];
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick if (!(flags & AP_LOG_DATA_SHOW_OFFSET)) {
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick prefix[0] = '\0';
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick }
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick if (len > 0xffff) { /* bug in caller? */
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick len = 0xffff;
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick }
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick if (label) {
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick log_error_va_glue(file, line, module_index, level, APR_SUCCESS, s,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick c, r, NULL, "%s (%" APR_SIZE_T_FMT " bytes)",
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick label, len);
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick }
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick off = 0;
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick while (off < len) {
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick if (flags & AP_LOG_DATA_SHOW_OFFSET) {
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick apr_snprintf(prefix, sizeof prefix, "%04x: ", (unsigned int)off);
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick }
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick fmt_data(buf, data, len, &off);
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick log_error_va_glue(file, line, module_index, level, APR_SUCCESS, s,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick c, r, NULL, "%s%s", prefix, buf);
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick }
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick}
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick
f87299dab99bc04b51a6b8cad51b6795db862c0atrawickAP_DECLARE(void) ap_log_data_(const char *file, int line,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick int module_index, int level,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick const server_rec *s, const char *label,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick const void *data, apr_size_t len,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick unsigned int flags)
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick{
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick log_data_core(file, line, module_index, level, s, NULL, NULL, label,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick data, len, flags);
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick}
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick
f87299dab99bc04b51a6b8cad51b6795db862c0atrawickAP_DECLARE(void) ap_log_rdata_(const char *file, int line,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick int module_index, int level,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick const request_rec *r, const char *label,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick const void *data, apr_size_t len,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick unsigned int flags)
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick{
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick log_data_core(file, line, module_index, level, r->server, NULL, r, label,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick data, len, flags);
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick}
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick
f87299dab99bc04b51a6b8cad51b6795db862c0atrawickAP_DECLARE(void) ap_log_cdata_(const char *file, int line,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick int module_index, int level,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick const conn_rec *c, const char *label,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick const void *data, apr_size_t len,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick unsigned int flags)
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick{
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick log_data_core(file, line, module_index, level, c->base_server, c, NULL,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick label, data, len, flags);
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick}
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick
f87299dab99bc04b51a6b8cad51b6795db862c0atrawickAP_DECLARE(void) ap_log_csdata_(const char *file, int line, int module_index,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick int level, const conn_rec *c, const server_rec *s,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick const char *label, const void *data,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick apr_size_t len, unsigned int flags)
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick{
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick log_data_core(file, line, module_index, level, s, c, NULL, label, data,
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick len, flags);
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick}
f87299dab99bc04b51a6b8cad51b6795db862c0atrawick
bd27541a0c96caa881f17a490e23cdd220d480c8poirierAP_DECLARE(void) ap_log_command_line(apr_pool_t *plog, server_rec *s)
bd27541a0c96caa881f17a490e23cdd220d480c8poirier{
bd27541a0c96caa881f17a490e23cdd220d480c8poirier int i;
bd27541a0c96caa881f17a490e23cdd220d480c8poirier process_rec *process = s->process;
bd27541a0c96caa881f17a490e23cdd220d480c8poirier char *result;
bd27541a0c96caa881f17a490e23cdd220d480c8poirier int len_needed = 0;
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim
bd27541a0c96caa881f17a490e23cdd220d480c8poirier /* Piece together the command line from the pieces
bd27541a0c96caa881f17a490e23cdd220d480c8poirier * in process->argv, with spaces in between.
bd27541a0c96caa881f17a490e23cdd220d480c8poirier */
bd27541a0c96caa881f17a490e23cdd220d480c8poirier for (i = 0; i < process->argc; i++) {
bd27541a0c96caa881f17a490e23cdd220d480c8poirier len_needed += strlen(process->argv[i]) + 1;
bd27541a0c96caa881f17a490e23cdd220d480c8poirier }
bd27541a0c96caa881f17a490e23cdd220d480c8poirier
bd27541a0c96caa881f17a490e23cdd220d480c8poirier result = (char *) apr_palloc(plog, len_needed);
bd27541a0c96caa881f17a490e23cdd220d480c8poirier *result = '\0';
bd27541a0c96caa881f17a490e23cdd220d480c8poirier
bd27541a0c96caa881f17a490e23cdd220d480c8poirier for (i = 0; i < process->argc; i++) {
bd27541a0c96caa881f17a490e23cdd220d480c8poirier strcat(result, process->argv[i]);
bd27541a0c96caa881f17a490e23cdd220d480c8poirier if ((i+1)< process->argc) {
bd27541a0c96caa881f17a490e23cdd220d480c8poirier strcat(result, " ");
bd27541a0c96caa881f17a490e23cdd220d480c8poirier }
bd27541a0c96caa881f17a490e23cdd220d480c8poirier }
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s, APLOGNO(00094)
bd27541a0c96caa881f17a490e23cdd220d480c8poirier "Command line: '%s'", result);
bd27541a0c96caa881f17a490e23cdd220d480c8poirier}
bd27541a0c96caa881f17a490e23cdd220d480c8poirier
d981a6ecf6f7d394f1f017b19c52383e177a125ejim/* grab bag function to log commonly logged and shared info */
d981a6ecf6f7d394f1f017b19c52383e177a125ejimAP_DECLARE(void) ap_log_common(server_rec *s)
d981a6ecf6f7d394f1f017b19c52383e177a125ejim{
d981a6ecf6f7d394f1f017b19c52383e177a125ejim ap_log_error(APLOG_MARK, APLOG_DEBUG , 0, s, APLOGNO(02639)
d981a6ecf6f7d394f1f017b19c52383e177a125ejim "Using SO_REUSEPORT: %s (%d)",
a742cbb3e85669473b3233f30e3978bb6a20083cylavic ap_have_so_reuseport ? "yes" : "no",
a742cbb3e85669473b3233f30e3978bb6a20083cylavic ap_num_listen_buckets);
d981a6ecf6f7d394f1f017b19c52383e177a125ejim}
d981a6ecf6f7d394f1f017b19c52383e177a125ejim
20e0c71be778348516719e1e58a9f55c8e78c570trawickAP_DECLARE(void) ap_remove_pid(apr_pool_t *p, const char *rel_fname)
20e0c71be778348516719e1e58a9f55c8e78c570trawick{
20e0c71be778348516719e1e58a9f55c8e78c570trawick apr_status_t rv;
1ec73fc12d4912ea9f4841c301458454589b32d9trawick const char *fname = ap_runtime_dir_relative(p, rel_fname);
20e0c71be778348516719e1e58a9f55c8e78c570trawick
20e0c71be778348516719e1e58a9f55c8e78c570trawick if (fname != NULL) {
20e0c71be778348516719e1e58a9f55c8e78c570trawick rv = apr_file_remove(fname, p);
20e0c71be778348516719e1e58a9f55c8e78c570trawick if (rv != APR_SUCCESS) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, APLOGNO(00095)
20e0c71be778348516719e1e58a9f55c8e78c570trawick "failed to remove PID file %s", fname);
20e0c71be778348516719e1e58a9f55c8e78c570trawick }
20e0c71be778348516719e1e58a9f55c8e78c570trawick else {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_error(APLOG_MARK, APLOG_INFO, 0, ap_server_conf, APLOGNO(00096)
20e0c71be778348516719e1e58a9f55c8e78c570trawick "removed PID file %s (pid=%" APR_PID_T_FMT ")",
20e0c71be778348516719e1e58a9f55c8e78c570trawick fname, getpid());
20e0c71be778348516719e1e58a9f55c8e78c570trawick }
20e0c71be778348516719e1e58a9f55c8e78c570trawick }
20e0c71be778348516719e1e58a9f55c8e78c570trawick}
20e0c71be778348516719e1e58a9f55c8e78c570trawick
32c4bc04f89b16521718145dc731f750144d7b38wroweAP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *filename)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_file_t *pid_file = NULL;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_finfo_t finfo;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding static pid_t saved_pid = -1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding pid_t mypid;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_status_t rv;
32c4bc04f89b16521718145dc731f750144d7b38wrowe const char *fname;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
32c4bc04f89b16521718145dc731f750144d7b38wrowe if (!filename) {
32c4bc04f89b16521718145dc731f750144d7b38wrowe return;
32c4bc04f89b16521718145dc731f750144d7b38wrowe }
32c4bc04f89b16521718145dc731f750144d7b38wrowe
1ec73fc12d4912ea9f4841c301458454589b32d9trawick fname = ap_runtime_dir_relative(p, filename);
32c4bc04f89b16521718145dc731f750144d7b38wrowe if (!fname) {
e8f95a682820a599fe41b22977010636be5c2717jim ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, APR_EBADPATH,
185aa71728867671e105178b4c66fbc22b65ae26sf NULL, APLOGNO(00097) "Invalid PID file path %s, ignoring.", filename);
32c4bc04f89b16521718145dc731f750144d7b38wrowe return;
32c4bc04f89b16521718145dc731f750144d7b38wrowe }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding mypid = getpid();
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh if (mypid != saved_pid
8a3228198adb03e6996f7738c361a612777ecab6aaron && apr_stat(&finfo, fname, APR_FINFO_MTIME, p) == APR_SUCCESS) {
8a3228198adb03e6996f7738c361a612777ecab6aaron /* AP_SIG_GRACEFUL and HUP call this on each restart.
8a3228198adb03e6996f7738c361a612777ecab6aaron * Only warn on first time through for this pid.
8a3228198adb03e6996f7738c361a612777ecab6aaron *
8a3228198adb03e6996f7738c361a612777ecab6aaron * XXX: Could just write first time through too, although
8a3228198adb03e6996f7738c361a612777ecab6aaron * that may screw up scripts written to do something
8a3228198adb03e6996f7738c361a612777ecab6aaron * based on the last modification time of the pid file.
8a3228198adb03e6996f7738c361a612777ecab6aaron */
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, p, APLOGNO(00098)
4bb7ba7c1f9972b443562faf99151ccec854446fjorton "pid file %s overwritten -- Unclean "
4bb7ba7c1f9972b443562faf99151ccec854446fjorton "shutdown of previous Apache run?",
4bb7ba7c1f9972b443562faf99151ccec854446fjorton fname);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
8a3228198adb03e6996f7738c361a612777ecab6aaron if ((rv = apr_file_open(&pid_file, fname,
8a3228198adb03e6996f7738c361a612777ecab6aaron APR_WRITE | APR_CREATE | APR_TRUNCATE,
8a3228198adb03e6996f7738c361a612777ecab6aaron APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD, p))
8a3228198adb03e6996f7738c361a612777ecab6aaron != APR_SUCCESS) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL, APLOGNO(00099)
cf5ace98ead10d803fda70674cb4dda30fddb832trawick "could not create %s", fname);
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL, APLOGNO(00100)
2b484455736f4c30447aa852764f53282cbeb5ddrbb "%s: could not log pid to file %s",
8a3228198adb03e6996f7738c361a612777ecab6aaron ap_server_argv0, fname);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding exit(1);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
95dc871e605e3b1b347adbbbdd9a9caede71c38eminfrin apr_file_printf(pid_file, "%" APR_PID_T_FMT APR_EOL_STR, mypid);
066877f1a045103acfdd376d48cdd473c33f409bdougm apr_file_close(pid_file);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding saved_pid = mypid;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawickAP_DECLARE(apr_status_t) ap_read_pid(apr_pool_t *p, const char *filename,
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick pid_t *mypid)
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick{
dc64949d88a97fef0bfcb2eed2115dddafc41666wrowe const apr_size_t BUFFER_SIZE = sizeof(long) * 3 + 2; /* see apr_ltoa */
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick apr_file_t *pid_file = NULL;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick apr_status_t rv;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick const char *fname;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick char *buf, *endptr;
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz apr_size_t bytes_read;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick if (!filename) {
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick return APR_EGENERAL;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick }
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick
1ec73fc12d4912ea9f4841c301458454589b32d9trawick fname = ap_runtime_dir_relative(p, filename);
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick if (!fname) {
e8f95a682820a599fe41b22977010636be5c2717jim ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, APR_EBADPATH,
185aa71728867671e105178b4c66fbc22b65ae26sf NULL, APLOGNO(00101) "Invalid PID file path %s, ignoring.", filename);
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick return APR_EGENERAL;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick }
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick rv = apr_file_open(&pid_file, fname, APR_READ, APR_OS_DEFAULT, p);
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick if (rv != APR_SUCCESS) {
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick return rv;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick }
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz buf = apr_palloc(p, BUFFER_SIZE);
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz rv = apr_file_read_full(pid_file, buf, BUFFER_SIZE - 1, &bytes_read);
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz if (rv != APR_SUCCESS && rv != APR_EOF) {
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz return rv;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick }
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz /* If we fill the buffer, we're probably reading a corrupt pid file.
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz * To be nice, let's also ensure the first char is a digit. */
f2b43354f9ac8496ab7003ae01211af739efba1atrawick if (bytes_read == 0 || bytes_read == BUFFER_SIZE - 1 || !apr_isdigit(*buf)) {
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick return APR_EGENERAL;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick }
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick
f2b43354f9ac8496ab7003ae01211af739efba1atrawick buf[bytes_read] = '\0';
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz *mypid = strtol(buf, &endptr, 10);
2de7ee14d4925c754a2d3a52d91350b895257df9jerenkrantz
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick apr_file_close(pid_file);
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick return APR_SUCCESS;
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick}
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick
8a3228198adb03e6996f7738c361a612777ecab6aaronAP_DECLARE(void) ap_log_assert(const char *szExp, const char *szFile,
8a3228198adb03e6996f7738c361a612777ecab6aaron int nLine)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe char time_str[APR_CTIME_LEN];
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet
066877f1a045103acfdd376d48cdd473c33f409bdougm apr_ctime(time_str, apr_time_now());
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_error(APLOG_MARK, APLOG_CRIT, 0, NULL, APLOGNO(00102)
2b484455736f4c30447aa852764f53282cbeb5ddrbb "[%s] file %s, line %d, assertion \"%s\" failed",
8a3228198adb03e6996f7738c361a612777ecab6aaron time_str, szFile, nLine, szExp);
8f0d7adca1c0719b3b1863fb2b9d333d7822567awrowe#if defined(WIN32)
8f0d7adca1c0719b3b1863fb2b9d333d7822567awrowe DebugBreak();
8f0d7adca1c0719b3b1863fb2b9d333d7822567awrowe#else
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* unix assert does an abort leading to a core dump */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding abort();
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* piped log support */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
7646be5b9ab5b098bc81d3a08a47e1931dc87597rbb#ifdef AP_HAVE_RELIABLE_PIPED_LOGS
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* forward declaration */
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowestatic void piped_log_maintenance(int reason, void *data, apr_wait_t status);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
f5308a6d396448120986bed14412954788af3e5cjorton/* Spawn the piped logger process pl->program. */
053847fad1e0bfc79d75dd6aec040b78c4d9189erjungstatic apr_status_t piped_log_spawn(piped_log *pl)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_procattr_t *procattr;
db2ef76dc744b13b9a9929ebb9e6f94712a81717rbb apr_proc_t *procnew = NULL;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_status_t status;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb
066877f1a045103acfdd376d48cdd473c33f409bdougm if (((status = apr_procattr_create(&procattr, pl->p)) != APR_SUCCESS) ||
5a6a87d8920e385b1ed14177d74ab9786f3acddfwrowe ((status = apr_procattr_dir_set(procattr, ap_server_root))
5a6a87d8920e385b1ed14177d74ab9786f3acddfwrowe != APR_SUCCESS) ||
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe ((status = apr_procattr_cmdtype_set(procattr, pl->cmdtype))
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe != APR_SUCCESS) ||
8a3228198adb03e6996f7738c361a612777ecab6aaron ((status = apr_procattr_child_in_set(procattr,
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton pl->read_fd,
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton pl->write_fd))
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe != APR_SUCCESS) ||
76185d819b745e953dd2cd636fbdd515c333e4a4trawick ((status = apr_procattr_child_errfn_set(procattr, log_child_errfn))
76185d819b745e953dd2cd636fbdd515c333e4a4trawick != APR_SUCCESS) ||
76185d819b745e953dd2cd636fbdd515c333e4a4trawick ((status = apr_procattr_error_check_set(procattr, 1)) != APR_SUCCESS)) {
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb /* Something bad happened, give up and go away. */
31ffc4bd929e3c5dca2e329a52651c418b995fc1sf ap_log_error(APLOG_MARK, APLOG_STARTUP, status, NULL, APLOGNO(00103)
31ffc4bd929e3c5dca2e329a52651c418b995fc1sf "piped_log_spawn: unable to setup child process '%s'",
31ffc4bd929e3c5dca2e329a52651c418b995fc1sf pl->program);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb else {
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb char **args;
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_tokenize_to_argv(pl->program, &args, pl->p);
db2ef76dc744b13b9a9929ebb9e6f94712a81717rbb procnew = apr_pcalloc(pl->p, sizeof(apr_proc_t));
9aae81f4b0afaaaa6571e6f995dc0c5d5b5435e8trawick status = apr_proc_create(procnew, args[0], (const char * const *) args,
76185d819b745e953dd2cd636fbdd515c333e4a4trawick NULL, procattr, pl->p);
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
76185d819b745e953dd2cd636fbdd515c333e4a4trawick if (status == APR_SUCCESS) {
20c85ca0d404e29972fb94c3d6236a264d1c77abstoddard pl->pid = procnew;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton /* procnew->in was dup2'd from pl->write_fd;
38cf7a307a8067b5b476403b9fec0bc6d7849cd2jorton * since the original fd is still valid, close the copy to
38cf7a307a8067b5b476403b9fec0bc6d7849cd2jorton * avoid a leak. */
38cf7a307a8067b5b476403b9fec0bc6d7849cd2jorton apr_file_close(procnew->in);
38cf7a307a8067b5b476403b9fec0bc6d7849cd2jorton procnew->in = NULL;
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung apr_proc_other_child_register(procnew, piped_log_maintenance, pl,
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton pl->write_fd, pl->p);
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton close_handle_in_child(pl->p, pl->read_fd);
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb }
76185d819b745e953dd2cd636fbdd515c333e4a4trawick else {
76185d819b745e953dd2cd636fbdd515c333e4a4trawick /* Something bad happened, give up and go away. */
31ffc4bd929e3c5dca2e329a52651c418b995fc1sf ap_log_error(APLOG_MARK, APLOG_STARTUP, status, NULL, APLOGNO(00104)
31ffc4bd929e3c5dca2e329a52651c418b995fc1sf "unable to start piped log program '%s'",
31ffc4bd929e3c5dca2e329a52651c418b995fc1sf pl->program);
76185d819b745e953dd2cd636fbdd515c333e4a4trawick }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
f5308a6d396448120986bed14412954788af3e5cjorton return status;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowestatic void piped_log_maintenance(int reason, void *data, apr_wait_t status)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung piped_log *pl = data;
31ffc4bd929e3c5dca2e329a52651c418b995fc1sf apr_status_t rv;
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick int mpm_state;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding switch (reason) {
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb case APR_OC_REASON_DEATH:
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb case APR_OC_REASON_LOST:
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick pl->pid = NULL; /* in case we don't get it going again, this
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * tells other logic not to try to kill it
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick */
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung apr_proc_other_child_unregister(pl);
31ffc4bd929e3c5dca2e329a52651c418b995fc1sf rv = ap_mpm_query(AP_MPMQ_MPM_STATE, &mpm_state);
31ffc4bd929e3c5dca2e329a52651c418b995fc1sf if (rv != APR_SUCCESS) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00105)
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick "can't query MPM state; not restarting "
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick "piped log program '%s'",
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick pl->program);
8a3228198adb03e6996f7738c361a612777ecab6aaron }
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick else if (mpm_state != AP_MPMQ_STOPPING) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00106)
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick "piped log program '%s' failed unexpectedly",
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick pl->program);
31ffc4bd929e3c5dca2e329a52651c418b995fc1sf if ((rv = piped_log_spawn(pl)) != APR_SUCCESS) {
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick /* what can we do? This could be the error log we're having
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * problems opening up... */
31ffc4bd929e3c5dca2e329a52651c418b995fc1sf ap_log_error(APLOG_MARK, APLOG_STARTUP, rv, NULL, APLOGNO(00107)
31ffc4bd929e3c5dca2e329a52651c418b995fc1sf "piped_log_maintenance: unable to respawn '%s'",
31ffc4bd929e3c5dca2e329a52651c418b995fc1sf pl->program);
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick }
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron break;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb case APR_OC_REASON_UNWRITABLE:
ffb048955d9939c0ab6ff99c2efc412d8e7a191dwrowe /* We should not kill off the pipe here, since it may only be full.
ffb048955d9939c0ab6ff99c2efc412d8e7a191dwrowe * If it really is locked, we should kill it off manually. */
8a3228198adb03e6996f7738c361a612777ecab6aaron break;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb case APR_OC_REASON_RESTART:
8a3228198adb03e6996f7738c361a612777ecab6aaron if (pl->pid != NULL) {
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_proc_kill(pl->pid, SIGTERM);
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick pl->pid = NULL;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron break;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb case APR_OC_REASON_UNREGISTER:
8a3228198adb03e6996f7738c361a612777ecab6aaron break;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
c54189c4d2d06d8b374940b32acf20287effff07wrowestatic apr_status_t piped_log_cleanup_for_exec(void *data)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding piped_log *pl = data;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton apr_file_close(pl->read_fd);
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton apr_file_close(pl->write_fd);
2a7d0035b5594ddc0907a9cc545e14ae5140c541manoj return APR_SUCCESS;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
c54189c4d2d06d8b374940b32acf20287effff07wrowestatic apr_status_t piped_log_cleanup(void *data)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding piped_log *pl = data;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
c54189c4d2d06d8b374940b32acf20287effff07wrowe if (pl->pid != NULL) {
c54189c4d2d06d8b374940b32acf20287effff07wrowe apr_proc_kill(pl->pid, SIGTERM);
c54189c4d2d06d8b374940b32acf20287effff07wrowe }
c54189c4d2d06d8b374940b32acf20287effff07wrowe return piped_log_cleanup_for_exec(data);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
c54189c4d2d06d8b374940b32acf20287effff07wrowe
7117ace448072813fa6eb7180ef206fc2e8fcfc7wroweAP_DECLARE(piped_log *) ap_open_piped_log_ex(apr_pool_t *p,
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe const char *program,
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe apr_cmdtype_e cmdtype)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding piped_log *pl;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm pl = apr_palloc(p, sizeof (*pl));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding pl->p = p;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm pl->program = apr_pstrdup(p, program);
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb pl->pid = NULL;
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe pl->cmdtype = cmdtype;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton if (apr_file_pipe_create_ex(&pl->read_fd,
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton &pl->write_fd,
52bdaf788c70b03fe6f68a5a489cdbe11fb184efwrowe APR_FULL_BLOCK, p) != APR_SUCCESS) {
8a3228198adb03e6996f7738c361a612777ecab6aaron return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_pool_cleanup_register(p, pl, piped_log_cleanup,
8a3228198adb03e6996f7738c361a612777ecab6aaron piped_log_cleanup_for_exec);
053847fad1e0bfc79d75dd6aec040b78c4d9189erjung if (piped_log_spawn(pl) != APR_SUCCESS) {
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_pool_cleanup_kill(p, pl, piped_log_cleanup);
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton apr_file_close(pl->read_fd);
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton apr_file_close(pl->write_fd);
8a3228198adb03e6996f7738c361a612777ecab6aaron return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return pl;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
cddad5fd27fd3b9f4375d76d04bbbeaebec00548wrowe#else /* !AP_HAVE_RELIABLE_PIPED_LOGS */
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic apr_status_t piped_log_cleanup(void *data)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb piped_log *pl = data;
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton apr_file_close(pl->write_fd);
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb return APR_SUCCESS;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
7117ace448072813fa6eb7180ef206fc2e8fcfc7wroweAP_DECLARE(piped_log *) ap_open_piped_log_ex(apr_pool_t *p,
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe const char *program,
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe apr_cmdtype_e cmdtype)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding piped_log *pl;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_file_t *dummy = NULL;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb int rc;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe rc = log_child(p, program, &dummy, cmdtype, 0);
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb if (rc != APR_SUCCESS) {
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL, APLOGNO(00108)
19702a9985f3b2f794d22be9102d9d4fbf6bebe7rjung "Couldn't start piped log process '%s'.",
19702a9985f3b2f794d22be9102d9d4fbf6bebe7rjung (program == NULL) ? "NULL" : program);
85c435ceda98eab940615e4466d9c5955252e745wrowe return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm pl = apr_palloc(p, sizeof (*pl));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding pl->p = p;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton pl->read_fd = NULL;
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton pl->write_fd = dummy;
066877f1a045103acfdd376d48cdd473c33f409bdougm apr_pool_cleanup_register(p, pl, piped_log_cleanup, piped_log_cleanup);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return pl;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
7117ace448072813fa6eb7180ef206fc2e8fcfc7wroweAP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p,
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe const char *program)
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe{
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe apr_cmdtype_e cmdtype = APR_PROGRAM_ENV;
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe /* In 2.4 favor PROGRAM_ENV, accept "||prog" syntax for compatibility
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe * and "|$cmd" to override the default.
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * Any 2.2 backport would continue to favor SHELLCMD_ENV so there
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe * accept "||prog" to override, and "|$cmd" to ease conversion.
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe */
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe if (*program == '|')
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe ++program;
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe if (*program == '$') {
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe cmdtype = APR_SHELLCMD_ENV;
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe ++program;
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe }
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe
44c44a736f11c7785e87b8c4744b3867ad7d8f0bwrowe return ap_open_piped_log_ex(p, program, cmdtype);
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe}
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe
3d96ee83babeec32482c9082c9426340cee8c44dwroweAP_DECLARE(void) ap_close_piped_log(piped_log *pl)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
066877f1a045103acfdd376d48cdd473c33f409bdougm apr_pool_cleanup_run(pl->p, pl, piped_log_cleanup);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sfAP_DECLARE(const char *) ap_parse_log_level(const char *str, int *val)
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf{
1119f286db67c139106e274e0814430cd600b901sf char *err = "Log level keyword must be one of emerg/alert/crit/error/warn/"
d37a236a4b64d0aeb4a8bbfd3978503af8c82765sf "notice/info/debug/trace1/.../trace8";
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf int i = 0;
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf if (str == NULL)
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf return err;
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf while (priorities[i].t_name != NULL) {
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf if (!strcasecmp(str, priorities[i].t_name)) {
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf *val = priorities[i].t_val;
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf return NULL;
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf }
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf i++;
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf }
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf return err;
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf}
aa51f4b9e1f954f9c04d2728a0d7be01719fe0a1sf
a7318397b355119d990d1f311b951dea2aafc53arbbAP_IMPLEMENT_HOOK_VOID(error_log,
f91e8c44b15a74bedaa027128a695950807e2968sf (const ap_errorlog_info *info, const char *errstr),
f91e8c44b15a74bedaa027128a695950807e2968sf (info, errstr))
ce4dc40a4e87991087488f70d96d3447d7557294sf
ce4dc40a4e87991087488f70d96d3447d7557294sfAP_IMPLEMENT_HOOK_RUN_FIRST(int, generate_log_id,
ce4dc40a4e87991087488f70d96d3447d7557294sf (const conn_rec *c, const request_rec *r,
ce4dc40a4e87991087488f70d96d3447d7557294sf const char **id),
ce4dc40a4e87991087488f70d96d3447d7557294sf (c, r, id), DECLINED)