log.c revision 52bdaf788c70b03fe6f68a5a489cdbe11fb184ef
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"
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
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define CORE_PRIVATE
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein
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"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingtypedef struct {
8a3228198adb03e6996f7738c361a612777ecab6aaron char *t_name;
8a3228198adb03e6996f7738c361a612777ecab6aaron int t_val;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding} TRANS;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
a7318397b355119d990d1f311b951dea2aafc53arbbAPR_HOOK_STRUCT(
a7318397b355119d990d1f311b951dea2aafc53arbb APR_HOOK_LINK(error_log)
a7318397b355119d990d1f311b951dea2aafc53arbb)
a7318397b355119d990d1f311b951dea2aafc53arbb
cb9e6e5c78f5a1690214e9548250fc6af1fc73b5wroweint AP_DECLARE_DATA ap_default_loglevel = DEFAULT_LOGLEVEL;
cb9e6e5c78f5a1690214e9548250fc6af1fc73b5wrowe
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef HAVE_SYSLOG
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const TRANS facilities[] = {
8a3228198adb03e6996f7738c361a612777ecab6aaron {"auth", LOG_AUTH},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_AUTHPRIV
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"authpriv",LOG_AUTHPRIV},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_CRON
8a3228198adb03e6996f7738c361a612777ecab6aaron {"cron", LOG_CRON},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_DAEMON
8a3228198adb03e6996f7738c361a612777ecab6aaron {"daemon", LOG_DAEMON},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_FTP
8a3228198adb03e6996f7738c361a612777ecab6aaron {"ftp", LOG_FTP},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_KERN
8a3228198adb03e6996f7738c361a612777ecab6aaron {"kern", LOG_KERN},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_LPR
8a3228198adb03e6996f7738c361a612777ecab6aaron {"lpr", LOG_LPR},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_MAIL
8a3228198adb03e6996f7738c361a612777ecab6aaron {"mail", LOG_MAIL},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_NEWS
8a3228198adb03e6996f7738c361a612777ecab6aaron {"news", LOG_NEWS},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_SYSLOG
8a3228198adb03e6996f7738c361a612777ecab6aaron {"syslog", LOG_SYSLOG},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_USER
8a3228198adb03e6996f7738c361a612777ecab6aaron {"user", LOG_USER},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_UUCP
8a3228198adb03e6996f7738c361a612777ecab6aaron {"uucp", LOG_UUCP},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_LOCAL0
8a3228198adb03e6996f7738c361a612777ecab6aaron {"local0", LOG_LOCAL0},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_LOCAL1
8a3228198adb03e6996f7738c361a612777ecab6aaron {"local1", LOG_LOCAL1},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_LOCAL2
8a3228198adb03e6996f7738c361a612777ecab6aaron {"local2", LOG_LOCAL2},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_LOCAL3
8a3228198adb03e6996f7738c361a612777ecab6aaron {"local3", LOG_LOCAL3},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_LOCAL4
8a3228198adb03e6996f7738c361a612777ecab6aaron {"local4", LOG_LOCAL4},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_LOCAL5
8a3228198adb03e6996f7738c361a612777ecab6aaron {"local5", LOG_LOCAL5},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_LOCAL6
8a3228198adb03e6996f7738c361a612777ecab6aaron {"local6", LOG_LOCAL6},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_LOCAL7
8a3228198adb03e6996f7738c361a612777ecab6aaron {"local7", LOG_LOCAL7},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
8a3228198adb03e6996f7738c361a612777ecab6aaron {NULL, -1},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding};
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
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},
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
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick/* clear_handle_list() is called when plog is cleared; at that
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick * point we need to forget about our old list of pipe read
649c9dd342a580016d29c2866de88a4609eb6457wrowe * handles. We let the plog cleanups close the actual pipes.
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick */
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickstatic apr_status_t clear_handle_list(void *v)
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick{
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick read_handles = NULL;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick return APR_SUCCESS;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick}
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick/* remember to close this handle in the child process */
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawickstatic void close_handle_in_child(apr_pool_t *p, apr_file_t *f)
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick{
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;
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,
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe APR_EBADPATH, NULL, "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) {
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL,
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 }
649c9dd342a580016d29c2866de88a4609eb6457wrowe if ((rc = apr_file_open_stderr(&stderr_log, stderr_pool))
649c9dd342a580016d29c2866de88a4609eb6457wrowe == APR_SUCCESS) {
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe apr_file_flush(stderr_log);
649c9dd342a580016d29c2866de88a4609eb6457wrowe 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
649c9dd342a580016d29c2866de88a4609eb6457wrowe * the next recycle. There's also an apparent bug which
649c9dd342a580016d29c2866de88a4609eb6457wrowe * 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) {
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe ap_log_error(APLOG_MARK, APLOG_CRIT, rc, NULL,
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{
76185d819b745e953dd2cd636fbdd515c333e4a4trawick ap_log_error(APLOG_MARK, APLOG_ERR, err, NULL,
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,
399cf0e5e061b49593817421b94305889fa6bc1fjorton apr_file_t **fpin, 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)
7d77917ef4b13a5d97e9cd85898630c0f106d7c8trawick && ((rc = apr_procattr_cmdtype_set(procattr,
d406be0d6a4f9e61bbdfa6c8cde2e09338dd650atrawick APR_SHELLCMD_ENV)) == 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)
ff0436077dc959b17a6f87825e4a106d211224c1wrowe && ((rc = apr_procattr_child_errfn_set(procattr, log_child_errfn))
ff0436077dc959b17a6f87825e4a106d211224c1wrowe == APR_SUCCESS)) {
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb char **args;
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb const char *pname;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_tokenize_to_argv(progname, &args, p);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm pname = apr_pstrdup(p, args[0]);
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
066877f1a045103acfdd376d48cdd473c33f409bdougm rc = apr_proc_create(procnew, pname, (const char * const *)args,
8a3228198adb03e6996f7738c361a612777ecab6aaron NULL, procattr, p);
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 == '|') {
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_file_t *dummy = NULL;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb
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. */
399cf0e5e061b49593817421b94305889fa6bc1fjorton rc = log_child(p, s->error_fname + 1, &dummy, is_main);
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb if (rc != APR_SUCCESS) {
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL,
f5fccb8eae1f1a5f212a5bda878479c281f36512trawick "Couldn't start ErrorLog process");
85c435ceda98eab940615e4466d9c5955252e745wrowe return DONE;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb s->error_log = dummy;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef HAVE_SYSLOG
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strncasecmp(s->error_fname, "syslog", 6)) {
8a3228198adb03e6996f7738c361a612777ecab6aaron if ((fname = strchr(s->error_fname, ':'))) {
8a3228198adb03e6996f7738c361a612777ecab6aaron const TRANS *fac;
8a3228198adb03e6996f7738c361a612777ecab6aaron
8a3228198adb03e6996f7738c361a612777ecab6aaron fname++;
8a3228198adb03e6996f7738c361a612777ecab6aaron for (fac = facilities; fac->t_name; fac++) {
8a3228198adb03e6996f7738c361a612777ecab6aaron if (!strcasecmp(fname, fac->t_name)) {
8a3228198adb03e6996f7738c361a612777ecab6aaron openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID,
8a3228198adb03e6996f7738c361a612777ecab6aaron fac->t_val);
8a3228198adb03e6996f7738c361a612777ecab6aaron s->error_log = NULL;
85c435ceda98eab940615e4466d9c5955252e745wrowe return OK;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron else {
8a3228198adb03e6996f7738c361a612777ecab6aaron openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID, LOG_LOCAL7);
8a3228198adb03e6996f7738c361a612777ecab6aaron }
8a3228198adb03e6996f7738c361a612777ecab6aaron
8a3228198adb03e6996f7738c361a612777ecab6aaron s->error_log = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
8a3228198adb03e6996f7738c361a612777ecab6aaron fname = ap_server_root_relative(p, s->error_fname);
32c4bc04f89b16521718145dc731f750144d7b38wrowe if (!fname) {
32c4bc04f89b16521718145dc731f750144d7b38wrowe ap_log_error(APLOG_MARK, APLOG_STARTUP, APR_EBADPATH, NULL,
32c4bc04f89b16521718145dc731f750144d7b38wrowe "%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) {
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL,
2b484455736f4c30447aa852764f53282cbeb5ddrbb "%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
649c9dd342a580016d29c2866de88a4609eb6457wrowe * can relaunch a lost log child. These read handles
649c9dd342a580016d29c2866de88a4609eb6457wrowe * are always closed on exec.
649c9dd342a580016d29c2866de88a4609eb6457wrowe * We won't care what happens to our stderr log child
649c9dd342a580016d29c2866de88a4609eb6457wrowe * between log phases, so we don't mind losing stderr's
649c9dd342a580016d29c2866de88a4609eb6457wrowe * read_handle a little bit early.
649c9dd342a580016d29c2866de88a4609eb6457wrowe */
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick apr_pool_cleanup_register(p, NULL, clear_handle_list,
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick apr_pool_cleanup_null);
649c9dd342a580016d29c2866de88a4609eb6457wrowe
649c9dd342a580016d29c2866de88a4609eb6457wrowe /* HERE we need a stdout log that outlives plog.
649c9dd342a580016d29c2866de88a4609eb6457wrowe * 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");
649c9dd342a580016d29c2866de88a4609eb6457wrowe
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;
ab43b4a17b2ac31ccb1cf280be8c42a8a314cecbjorton
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) {
ab43b4a17b2ac31ccb1cf280be8c42a8a314cecbjorton ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s_main,
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
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (replace_stderr && freopen("/dev/null", "w", stderr) == NULL) {
8a3228198adb03e6996f7738c361a612777ecab6aaron ap_log_error(APLOG_MARK, APLOG_CRIT, errno, s_main,
8a3228198adb03e6996f7738c361a612777ecab6aaron "unable to replace stderr with /dev/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 }
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
2261031aa94be82d7e6b1b8c367afc1b282317f5ianhstatic void log_error_core(const char *file, int line, int level,
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh apr_status_t status, const server_rec *s,
e34223f72e630187c4d8ac7c22da5096c833eb20trawick const conn_rec *c,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm const request_rec *r, apr_pool_t *pool,
3597d6b10c88c252f156fe8061b659a38dea38c2rbb const char *fmt, va_list args)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd char errstr[MAX_STRING_LEN];
9fe315e66ef597a158db81bcbd230d7a5d65785dnd#ifndef AP_UNSAFE_ERROR_LOG_UNESCAPED
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd char scratch[MAX_STRING_LEN];
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd#endif
58fd79b56eb624bf011772994e9761d3c2e228c1orlikowski apr_size_t len, errstrlen;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_file_t *logf = NULL;
d2e443764d6855a4a06c8eb2b7708ab9b465ddeerbb const char *referer;
39b67927abc1c24834e165444655939ea52c908aorlikowski int level_and_mask = level & APLOG_LEVELMASK;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
e34223f72e630187c4d8ac7c22da5096c833eb20trawick if (r && r->connection) {
e34223f72e630187c4d8ac7c22da5096c833eb20trawick c = r->connection;
e34223f72e630187c4d8ac7c22da5096c833eb20trawick }
e34223f72e630187c4d8ac7c22da5096c833eb20trawick
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (s == NULL) {
8a3228198adb03e6996f7738c361a612777ecab6aaron /*
8a3228198adb03e6996f7738c361a612777ecab6aaron * If we are doing stderr logging (startup), don't log messages that are
8a3228198adb03e6996f7738c361a612777ecab6aaron * above the default server log level unless it is a startup/shutdown
8a3228198adb03e6996f7738c361a612777ecab6aaron * notice
8a3228198adb03e6996f7738c361a612777ecab6aaron */
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh if ((level_and_mask != APLOG_NOTICE)
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh && (level_and_mask > ap_default_loglevel)) {
8a3228198adb03e6996f7738c361a612777ecab6aaron return;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick logf = stderr_log;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (s->error_log) {
8a3228198adb03e6996f7738c361a612777ecab6aaron /*
8a3228198adb03e6996f7738c361a612777ecab6aaron * If we are doing normal logging, don't log messages that are
8a3228198adb03e6996f7738c361a612777ecab6aaron * above the server log level unless it is a startup/shutdown notice
8a3228198adb03e6996f7738c361a612777ecab6aaron */
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh if ((level_and_mask != APLOG_NOTICE)
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh && (level_and_mask > s->loglevel)) {
8a3228198adb03e6996f7738c361a612777ecab6aaron return;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
8a3228198adb03e6996f7738c361a612777ecab6aaron logf = s->error_log;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef TPF
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (tpf_child) {
8a3228198adb03e6996f7738c361a612777ecab6aaron /*
8a3228198adb03e6996f7738c361a612777ecab6aaron * If we are doing normal logging, don't log messages that are
8a3228198adb03e6996f7738c361a612777ecab6aaron * above the server log level unless it is a startup/shutdown notice
8a3228198adb03e6996f7738c361a612777ecab6aaron */
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh if ((level_and_mask != APLOG_NOTICE)
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh && (level_and_mask > s->loglevel)) {
8a3228198adb03e6996f7738c361a612777ecab6aaron return;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
8a3228198adb03e6996f7738c361a612777ecab6aaron logf = stderr;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif /* TPF */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
8a3228198adb03e6996f7738c361a612777ecab6aaron /*
8a3228198adb03e6996f7738c361a612777ecab6aaron * If we are doing syslog logging, don't log messages that are
8a3228198adb03e6996f7738c361a612777ecab6aaron * above the server log level (including a startup/shutdown notice)
8a3228198adb03e6996f7738c361a612777ecab6aaron */
8a3228198adb03e6996f7738c361a612777ecab6aaron if (level_and_mask > s->loglevel) {
8a3228198adb03e6996f7738c361a612777ecab6aaron return;
8a3228198adb03e6996f7738c361a612777ecab6aaron }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
2b484455736f4c30447aa852764f53282cbeb5ddrbb if (logf && ((level & APLOG_STARTUP) != APLOG_STARTUP)) {
8a3228198adb03e6996f7738c361a612777ecab6aaron errstr[0] = '[';
b5033962c73a470b6f36a3ac796c542a6ab4ddf6brianp ap_recent_ctime(errstr + 1, apr_time_now());
8a3228198adb03e6996f7738c361a612777ecab6aaron errstr[1 + APR_CTIME_LEN - 1] = ']';
8a3228198adb03e6996f7738c361a612777ecab6aaron errstr[1 + APR_CTIME_LEN ] = ' ';
8a3228198adb03e6996f7738c361a612777ecab6aaron len = 1 + APR_CTIME_LEN + 1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding } else {
8a3228198adb03e6996f7738c361a612777ecab6aaron len = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
2b484455736f4c30447aa852764f53282cbeb5ddrbb if ((level & APLOG_STARTUP) != APLOG_STARTUP) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
8a3228198adb03e6996f7738c361a612777ecab6aaron "[%s] ", priorities[level_and_mask].t_name);
2b484455736f4c30447aa852764f53282cbeb5ddrbb }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifndef TPF
39b67927abc1c24834e165444655939ea52c908aorlikowski if (file && level_and_mask == APLOG_DEBUG) {
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 */
8a3228198adb03e6996f7738c361a612777ecab6aaron len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
8a3228198adb03e6996f7738c361a612777ecab6aaron "%s(%d): ", file, line);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif /* TPF */
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
e34223f72e630187c4d8ac7c22da5096c833eb20trawick if (c) {
8a3228198adb03e6996f7738c361a612777ecab6aaron /* XXX: TODO: add a method of selecting whether logged client
8a3228198adb03e6996f7738c361a612777ecab6aaron * addresses are in dotted quad or resolved form... dotted
8a3228198adb03e6996f7738c361a612777ecab6aaron * quad is the most secure, which is why I'm implementing it
8a3228198adb03e6996f7738c361a612777ecab6aaron * first. -djg
8a3228198adb03e6996f7738c361a612777ecab6aaron */
8a3228198adb03e6996f7738c361a612777ecab6aaron len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
e34223f72e630187c4d8ac7c22da5096c833eb20trawick "[client %s] ", c->remote_ip);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
127c81d6b2c9ba8932273c2e1b13e3ea3d673b07trawick if (status != 0) {
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe if (status < APR_OS_START_EAIERR) {
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe "(%d)", status);
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe }
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe else if (status < APR_OS_START_SYSERR) {
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe "(EAI %d)", status - APR_OS_START_EAIERR);
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe }
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe else if (status < 100000 + APR_OS_START_SYSERR) {
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe "(OS %d)", status - APR_OS_START_SYSERR);
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe }
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe else {
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe "(os 0x%08x)", status - APR_OS_START_SYSERR);
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe }
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe apr_strerror(status, errstr + len, MAX_STRING_LEN - len);
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe len += strlen(errstr + len);
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe if (MAX_STRING_LEN - len > 2) {
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe errstr[len++] = ':';
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe errstr[len++] = ' ';
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe errstr[len] = '\0';
9486be2b079a0a11eaf4b17f025228f5313b03bcwrowe }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
82acfa3f57607ae78326104c420a317260554a47nd
3c09db9ce04e444548e386a4b822e76ea0dabbebrbb errstrlen = len;
9fe315e66ef597a158db81bcbd230d7a5d65785dnd#ifndef AP_UNSAFE_ERROR_LOG_UNESCAPED
82acfa3f57607ae78326104c420a317260554a47nd if (apr_vsnprintf(scratch, MAX_STRING_LEN - len, fmt, args)) {
82acfa3f57607ae78326104c420a317260554a47nd len += ap_escape_errorlog_item(errstr + len, scratch,
82acfa3f57607ae78326104c420a317260554a47nd MAX_STRING_LEN - len);
82acfa3f57607ae78326104c420a317260554a47nd }
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd#else
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd len += apr_vsnprintf(errstr + len, MAX_STRING_LEN - len, fmt, args);
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
82acfa3f57607ae78326104c420a317260554a47nd if ( r && (referer = apr_table_get(r->headers_in, "Referer"))
9fe315e66ef597a158db81bcbd230d7a5d65785dnd#ifndef AP_UNSAFE_ERROR_LOG_UNESCAPED
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd && ap_escape_errorlog_item(scratch, referer, MAX_STRING_LEN - len)
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd#endif
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd ) {
d2e443764d6855a4a06c8eb2b7708ab9b465ddeerbb len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd ", referer: %s",
9fe315e66ef597a158db81bcbd230d7a5d65785dnd#ifndef AP_UNSAFE_ERROR_LOG_UNESCAPED
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd scratch
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd#else
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd referer
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd#endif
e698258fd17a7f9d51cb2b35e96f8f0b48ec23c8nd );
d2e443764d6855a4a06c8eb2b7708ab9b465ddeerbb }
d2e443764d6855a4a06c8eb2b7708ab9b465ddeerbb
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* NULL if we are logging to syslog */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (logf) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* Truncate for the terminator (as apr_snprintf does) */
8a3228198adb03e6996f7738c361a612777ecab6aaron if (len > MAX_STRING_LEN - sizeof(APR_EOL_STR)) {
e7daae8d2ef0165e83627188bf33655c0b8266e8wrowe len = MAX_STRING_LEN - sizeof(APR_EOL_STR);
8a3228198adb03e6996f7738c361a612777ecab6aaron }
a1de70bda57b72d8cc6b47ea744e0973ed424f56wrowe strcpy(errstr + len, APR_EOL_STR);
066877f1a045103acfdd376d48cdd473c33f409bdougm apr_file_puts(errstr, logf);
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_file_flush(logf);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef HAVE_SYSLOG
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
8a3228198adb03e6996f7738c361a612777ecab6aaron syslog(level_and_mask, "%s", errstr);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
3c09db9ce04e444548e386a4b822e76ea0dabbebrbb ap_run_error_log(file, line, level, status, s, r, pool, errstr + errstrlen);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
3d96ee83babeec32482c9082c9426340cee8c44dwroweAP_DECLARE(void) ap_log_error(const char *file, int line, int level,
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh apr_status_t status, const server_rec *s,
0942697a9b5de44865676345a3828741c827efe6rbb const char *fmt, ...)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding va_list args;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding va_start(args, fmt);
e34223f72e630187c4d8ac7c22da5096c833eb20trawick log_error_core(file, line, level, status, s, NULL, NULL, NULL, fmt, args);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb va_end(args);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb}
3597d6b10c88c252f156fe8061b659a38dea38c2rbb
3d96ee83babeec32482c9082c9426340cee8c44dwroweAP_DECLARE(void) ap_log_perror(const char *file, int line, int level,
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh apr_status_t status, apr_pool_t *p,
8a3228198adb03e6996f7738c361a612777ecab6aaron const char *fmt, ...)
3597d6b10c88c252f156fe8061b659a38dea38c2rbb{
3597d6b10c88c252f156fe8061b659a38dea38c2rbb va_list args;
3597d6b10c88c252f156fe8061b659a38dea38c2rbb
3597d6b10c88c252f156fe8061b659a38dea38c2rbb va_start(args, fmt);
e34223f72e630187c4d8ac7c22da5096c833eb20trawick log_error_core(file, line, level, status, NULL, NULL, NULL, p, fmt, args);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding va_end(args);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
3d96ee83babeec32482c9082c9426340cee8c44dwroweAP_DECLARE(void) ap_log_rerror(const char *file, int line, int level,
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh apr_status_t status, const request_rec *r,
0942697a9b5de44865676345a3828741c827efe6rbb const char *fmt, ...)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding va_list args;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding va_start(args, fmt);
e34223f72e630187c4d8ac7c22da5096c833eb20trawick log_error_core(file, line, level, status, r->server, NULL, r, NULL, fmt,
e34223f72e630187c4d8ac7c22da5096c833eb20trawick 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
e34223f72e630187c4d8ac7c22da5096c833eb20trawickAP_DECLARE(void) ap_log_cerror(const char *file, int line, int level,
e34223f72e630187c4d8ac7c22da5096c833eb20trawick apr_status_t status, const conn_rec *c,
e34223f72e630187c4d8ac7c22da5096c833eb20trawick const char *fmt, ...)
e34223f72e630187c4d8ac7c22da5096c833eb20trawick{
e34223f72e630187c4d8ac7c22da5096c833eb20trawick va_list args;
e34223f72e630187c4d8ac7c22da5096c833eb20trawick
e34223f72e630187c4d8ac7c22da5096c833eb20trawick va_start(args, fmt);
e34223f72e630187c4d8ac7c22da5096c833eb20trawick log_error_core(file, line, level, status, c->base_server, c, NULL, NULL,
e34223f72e630187c4d8ac7c22da5096c833eb20trawick fmt, args);
e34223f72e630187c4d8ac7c22da5096c833eb20trawick va_end(args);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
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
32c4bc04f89b16521718145dc731f750144d7b38wrowe fname = ap_server_root_relative(p, filename);
32c4bc04f89b16521718145dc731f750144d7b38wrowe if (!fname) {
e8f95a682820a599fe41b22977010636be5c2717jim ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, APR_EBADPATH,
32c4bc04f89b16521718145dc731f750144d7b38wrowe NULL, "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 */
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawick ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, p,
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) {
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
cf5ace98ead10d803fda70674cb4dda30fddb832trawick "could not create %s", fname);
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawick ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
2b484455736f4c30447aa852764f53282cbeb5ddrbb "%s: could not log pid to file %s",
8a3228198adb03e6996f7738c361a612777ecab6aaron ap_server_argv0, fname);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding exit(1);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
066877f1a045103acfdd376d48cdd473c33f409bdougm apr_file_printf(pid_file, "%ld" APR_EOL_STR, (long)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
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick fname = ap_server_root_relative(p, filename);
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick if (!fname) {
e8f95a682820a599fe41b22977010636be5c2717jim ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, APR_EBADPATH,
e3754dae9df2783c2cd88fa8d46bd0a0765e9820trawick NULL, "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());
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawick ap_log_error(APLOG_MARK, APLOG_CRIT, 0, NULL,
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. */
f5308a6d396448120986bed14412954788af3e5cjortonstatic 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) ||
269e0a31aa0f6aafe7292e932a182ccb535e55a9trawick ((status = apr_procattr_cmdtype_set(procattr,
e8f95a682820a599fe41b22977010636be5c2717jim APR_SHELLCMD_ENV)) != APR_SUCCESS) ||
8a3228198adb03e6996f7738c361a612777ecab6aaron ((status = apr_procattr_child_in_set(procattr,
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh ap_piped_log_read_fd(pl),
8a3228198adb03e6996f7738c361a612777ecab6aaron ap_piped_log_write_fd(pl)))
76185d819b745e953dd2cd636fbdd515c333e4a4trawick != 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)) {
e4c4fcc82268e0192db234c74a6db784b879fffdrbb char buf[120];
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb /* Something bad happened, give up and go away. */
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
8a3228198adb03e6996f7738c361a612777ecab6aaron "piped_log_spawn: unable to setup child process '%s': %s",
8a3228198adb03e6996f7738c361a612777ecab6aaron pl->program, apr_strerror(status, buf, sizeof(buf)));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb else {
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb char **args;
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb const char *pname;
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_tokenize_to_argv(pl->program, &args, pl->p);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm pname = apr_pstrdup(pl->p, args[0]);
db2ef76dc744b13b9a9929ebb9e6f94712a81717rbb procnew = apr_pcalloc(pl->p, sizeof(apr_proc_t));
76185d819b745e953dd2cd636fbdd515c333e4a4trawick status = apr_proc_create(procnew, pname, (const char * const *) args,
76185d819b745e953dd2cd636fbdd515c333e4a4trawick NULL, procattr, pl->p);
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
76185d819b745e953dd2cd636fbdd515c333e4a4trawick if (status == APR_SUCCESS) {
20c85ca0d404e29972fb94c3d6236a264d1c77abstoddard pl->pid = procnew;
38cf7a307a8067b5b476403b9fec0bc6d7849cd2jorton /* procnew->in was dup2'd from ap_piped_log_write_fd(pl);
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;
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh apr_proc_other_child_register(procnew, piped_log_maintenance, pl,
8a3228198adb03e6996f7738c361a612777ecab6aaron ap_piped_log_write_fd(pl), pl->p);
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick close_handle_in_child(pl->p, ap_piped_log_read_fd(pl));
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb }
76185d819b745e953dd2cd636fbdd515c333e4a4trawick else {
76185d819b745e953dd2cd636fbdd515c333e4a4trawick char buf[120];
76185d819b745e953dd2cd636fbdd515c333e4a4trawick /* Something bad happened, give up and go away. */
76185d819b745e953dd2cd636fbdd515c333e4a4trawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
76185d819b745e953dd2cd636fbdd515c333e4a4trawick "unable to start piped log program '%s': %s",
76185d819b745e953dd2cd636fbdd515c333e4a4trawick pl->program, apr_strerror(status, buf, sizeof(buf)));
76185d819b745e953dd2cd636fbdd515c333e4a4trawick }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh
f5308a6d396448120986bed14412954788af3e5cjorton return status;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowestatic void piped_log_maintenance(int reason, void *data, apr_wait_t status)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding piped_log *pl = data;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_status_t stats;
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 */
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_proc_other_child_unregister(pl);
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick stats = ap_mpm_query(AP_MPMQ_MPM_STATE, &mpm_state);
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick if (stats != APR_SUCCESS) {
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
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) {
2d399cd7535887fceaa9f8f116eb98ce68ddd602trawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick "piped log program '%s' failed unexpectedly",
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick pl->program);
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick if ((stats = piped_log_spawn(pl)) != APR_SUCCESS) {
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick /* what can we do? This could be the error log we're having
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick * problems opening up... */
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick char buf[120];
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick "piped_log_maintenance: unable to respawn '%s': %s",
874fa3c6bbef1b4ab4bed0a2ff9852b21ea1b187trawick pl->program, apr_strerror(stats, buf, sizeof(buf)));
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
066877f1a045103acfdd376d48cdd473c33f409bdougm apr_file_close(ap_piped_log_read_fd(pl));
066877f1a045103acfdd376d48cdd473c33f409bdougm apr_file_close(ap_piped_log_write_fd(pl));
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
3d96ee83babeec32482c9082c9426340cee8c44dwroweAP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program)
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;
52bdaf788c70b03fe6f68a5a489cdbe11fb184efwrowe if (apr_file_pipe_create_ex(&ap_piped_log_read_fd(pl),
52bdaf788c70b03fe6f68a5a489cdbe11fb184efwrowe &ap_piped_log_write_fd(pl),
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);
f5308a6d396448120986bed14412954788af3e5cjorton if (piped_log_spawn(pl) != APR_SUCCESS) {
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_pool_cleanup_kill(p, pl, piped_log_cleanup);
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_file_close(ap_piped_log_read_fd(pl));
8a3228198adb03e6996f7738c361a612777ecab6aaron apr_file_close(ap_piped_log_write_fd(pl));
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
066877f1a045103acfdd376d48cdd473c33f409bdougm apr_file_close(ap_piped_log_write_fd(pl));
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb return APR_SUCCESS;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
3d96ee83babeec32482c9082c9426340cee8c44dwroweAP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding piped_log *pl;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_file_t *dummy = NULL;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb int rc;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
399cf0e5e061b49593817421b94305889fa6bc1fjorton rc = log_child(p, program, &dummy, 0);
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb if (rc != APR_SUCCESS) {
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL,
f5fccb8eae1f1a5f212a5bda878479c281f36512trawick "Couldn't start piped log process");
85c435ceda98eab940615e4466d9c5955252e745wrowe return NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm pl = apr_palloc(p, sizeof (*pl));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding pl->p = p;
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb ap_piped_log_read_fd(pl) = NULL;
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb ap_piped_log_write_fd(pl) = dummy;
066877f1a045103acfdd376d48cdd473c33f409bdougm apr_pool_cleanup_register(p, pl, piped_log_cleanup, piped_log_cleanup);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return pl;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
3d96ee83babeec32482c9082c9426340cee8c44dwroweAP_DECLARE(void) ap_close_piped_log(piped_log *pl)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
066877f1a045103acfdd376d48cdd473c33f409bdougm apr_pool_cleanup_run(pl->p, pl, piped_log_cleanup);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb
a7318397b355119d990d1f311b951dea2aafc53arbbAP_IMPLEMENT_HOOK_VOID(error_log,
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh (const char *file, int line, int level,
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh apr_status_t status, const server_rec *s,
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh const request_rec *r, apr_pool_t *pool,
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh const char *errstr), (file, line, level,
2261031aa94be82d7e6b1b8c367afc1b282317f5ianh status, s, r, pool, errstr))
a7318397b355119d990d1f311b951dea2aafc53arbb