log.c revision dc64949d88a97fef0bfcb2eed2115dddafc41666
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* ====================================================================
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * The Apache Software License, Version 1.1
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding *
b99dbaab171d91e1b664397cc40e039d0c087c65fielding * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * reserved.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Redistribution and use in source and binary forms, with or without
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * modification, are permitted provided that the following conditions
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * are met:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * 1. Redistributions of source code must retain the above copyright
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * notice, this list of conditions and the following disclaimer.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * 2. Redistributions in binary form must reproduce the above copyright
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * notice, this list of conditions and the following disclaimer in
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the documentation and/or other materials provided with the
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * distribution.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * 3. The end-user documentation included with the redistribution,
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * if any, must include the following acknowledgment:
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * "This product includes software developed by the
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * Apache Software Foundation (http://www.apache.org/)."
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * Alternately, this acknowledgment may appear in the software itself,
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * if and wherever such third-party acknowledgments normally appear.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * 4. The names "Apache" and "Apache Software Foundation" must
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * not be used to endorse or promote products derived from this
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * software without prior written permission. For written
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * permission, please contact apache@apache.org.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * 5. Products derived from this software may not be called "Apache",
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * nor may "Apache" appear in their name, without prior written
64185f9824e42f21ca7b9ae6c004484215c031a7rbb * permission of the Apache Software Foundation.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * SUCH DAMAGE.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * ====================================================================
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * This software consists of voluntary contributions made by many
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * individuals on behalf of the Apache Software Foundation. For more
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * information on the Apache Software Foundation, please see
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * <http://www.apache.org/>.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * Portions of this software are based upon public domain software
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * originally written at the National Center for Supercomputing Applications,
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding * University of Illinois, Urbana-Champaign.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * http_log.c: Dealing with the logs and errors
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * Rob McCool
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *
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"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "util_time.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingtypedef struct {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *t_name;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int t_val;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding} TRANS;
a7318397b355119d990d1f311b951dea2aafc53arbb
a7318397b355119d990d1f311b951dea2aafc53arbbAPR_HOOK_STRUCT(
a7318397b355119d990d1f311b951dea2aafc53arbb APR_HOOK_LINK(error_log)
a7318397b355119d990d1f311b951dea2aafc53arbb)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingint AP_DECLARE_DATA ap_default_loglevel = DEFAULT_LOGLEVEL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef HAVE_SYSLOG
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const TRANS facilities[] = {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"auth", LOG_AUTH},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_AUTHPRIV
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"authpriv",LOG_AUTHPRIV},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_CRON
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"cron", LOG_CRON},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_DAEMON
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"daemon", LOG_DAEMON},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_FTP
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"ftp", LOG_FTP},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_KERN
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"kern", LOG_KERN},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_LPR
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"lpr", LOG_LPR},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_MAIL
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"mail", LOG_MAIL},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_NEWS
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"news", LOG_NEWS},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_SYSLOG
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"syslog", LOG_SYSLOG},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_USER
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"user", LOG_USER},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_UUCP
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"uucp", LOG_UUCP},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_LOCAL0
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"local0", LOG_LOCAL0},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_LOCAL1
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"local1", LOG_LOCAL1},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_LOCAL2
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"local2", LOG_LOCAL2},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_LOCAL3
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"local3", LOG_LOCAL3},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_LOCAL4
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"local4", LOG_LOCAL4},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_LOCAL5
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"local5", LOG_LOCAL5},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_LOCAL6
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"local6", LOG_LOCAL6},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef LOG_LOCAL7
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"local7", LOG_LOCAL7},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {NULL, -1},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding};
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic const TRANS priorities[] = {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"emerg", APLOG_EMERG},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"alert", APLOG_ALERT},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"crit", APLOG_CRIT},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"error", APLOG_ERR},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"warn", APLOG_WARNING},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"notice", APLOG_NOTICE},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"info", APLOG_INFO},
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding {"debug", APLOG_DEBUG},
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick {NULL, -1},
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick};
ebc18d48bea83ee5ed7a1b4e30007e5192539829wrowe
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawickstatic apr_file_t *stderr_log = NULL;
066877f1a045103acfdd376d48cdd473c33f409bdougm
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawickAP_DECLARE(void) ap_open_stderr_log(apr_pool_t *p)
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick{
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_file_open_stderr(&stderr_log, p);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingAP_DECLARE(apr_status_t) ap_replace_stderr_log(apr_pool_t *p,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *fname)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_file_t *stderr_file;
f5fccb8eae1f1a5f212a5bda878479c281f36512trawick apr_status_t rc;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm char *filename = ap_server_root_relative(p, fname);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm if (!filename) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding APR_EBADPATH, NULL, "Invalid -E error log file %s",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding fname);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm exit(1);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb if ((rc = apr_file_open(&stderr_file, filename,
066877f1a045103acfdd376d48cdd473c33f409bdougm APR_APPEND | APR_READ | APR_WRITE | APR_CREATE,
066877f1a045103acfdd376d48cdd473c33f409bdougm APR_OS_DEFAULT, p)) != APR_SUCCESS) {
f5fccb8eae1f1a5f212a5bda878479c281f36512trawick ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL,
f5fccb8eae1f1a5f212a5bda878479c281f36512trawick "%s: could not open error log file %s.",
f5fccb8eae1f1a5f212a5bda878479c281f36512trawick ap_server_argv0, fname);
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb return rc;
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb }
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb if ((rc = apr_file_open_stderr(&stderr_log, p)) == APR_SUCCESS) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_file_flush(stderr_log);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm if ((rc = apr_file_dup2(stderr_log, stderr_file, p)) == APR_SUCCESS) {
db2ef76dc744b13b9a9929ebb9e6f94712a81717rbb apr_file_close(stderr_file);
066877f1a045103acfdd376d48cdd473c33f409bdougm }
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein }
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb if (rc != APR_SUCCESS) {
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb ap_log_error(APLOG_MARK, APLOG_CRIT, rc, NULL,
066877f1a045103acfdd376d48cdd473c33f409bdougm "unable to replace stderr with error_log");
20c85ca0d404e29972fb94c3d6236a264d1c77abstoddard }
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb return rc;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb}
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbbstatic int log_child(apr_pool_t *p, const char *progname,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_file_t **fpin)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* Child process code for 'ErrorLog "|..."';
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * may want a common framework for this, since I expect it will
061c3874622b67beff724876b9bd1b1f291f2eaafielding * be common for other foo-loggers to want this sort of thing...
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_status_t rc;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_procattr_t *procattr;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_proc_t *procnew;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb if (((rc = apr_procattr_create(&procattr, p)) == APR_SUCCESS)
a952e0c6ece342d88f2bc04e20dcfc563398eed3rbb && ((rc = apr_procattr_io_set(procattr,
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb APR_FULL_BLOCK,
f5fccb8eae1f1a5f212a5bda878479c281f36512trawick APR_NO_PIPE,
f5fccb8eae1f1a5f212a5bda878479c281f36512trawick APR_NO_PIPE)) == APR_SUCCESS)) {
f5fccb8eae1f1a5f212a5bda878479c281f36512trawick char **args;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *pname;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb apr_tokenize_to_argv(progname, &args, p);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding pname = apr_pstrdup(p, args[0]);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding procnew = (apr_proc_t *)apr_pcalloc(p, sizeof(*procnew));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding rc = apr_proc_create(procnew, pname, (const char * const *)args,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding NULL, procattr, p);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (rc == APR_SUCCESS) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_pool_note_subprocess(p, procnew, APR_KILL_AFTER_TIMEOUT);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (*fpin) = procnew->in;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return rc;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void open_error_log(server_rec *s, apr_pool_t *p)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *fname;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int rc;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (*s->error_fname == '|') {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_file_t *dummy = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* This starts a new process... */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding rc = log_child (p, s->error_fname + 1, &dummy);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (rc != APR_SUCCESS) {
066877f1a045103acfdd376d48cdd473c33f409bdougm ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL,
0ef1b940b4850f644082d2d33f94a1db15686d40bjh "Couldn't start ErrorLog process");
0ef1b940b4850f644082d2d33f94a1db15686d40bjh exit(1);
0ef1b940b4850f644082d2d33f94a1db15686d40bjh }
0ef1b940b4850f644082d2d33f94a1db15686d40bjh
2b484455736f4c30447aa852764f53282cbeb5ddrbb s->error_log = dummy;
2b484455736f4c30447aa852764f53282cbeb5ddrbb }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef HAVE_SYSLOG
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (!strncasecmp(s->error_fname, "syslog", 6)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((fname = strchr(s->error_fname, ':'))) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const TRANS *fac;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding fname++;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm for (fac = facilities; fac->t_name; fac++) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!strcasecmp(fname, fac->t_name)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm fac->t_val);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding s->error_log = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
c57161db43fe4cf5a62758d7d0834675e59cad0astoddard else {
066877f1a045103acfdd376d48cdd473c33f409bdougm openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID, LOG_LOCAL7);
066877f1a045103acfdd376d48cdd473c33f409bdougm }
066877f1a045103acfdd376d48cdd473c33f409bdougm
4e1e8abb2a6e588366a4680b039b460fc5fe1ccdstoddard s->error_log = NULL;
ec727afb817df0e5202135278c0d2902923cc980stoddard }
ec727afb817df0e5202135278c0d2902923cc980stoddard#endif
ec727afb817df0e5202135278c0d2902923cc980stoddard else {
ec727afb817df0e5202135278c0d2902923cc980stoddard fname = ap_server_root_relative(p, s->error_fname);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!fname) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_log_error(APLOG_MARK, APLOG_STARTUP, APR_EBADPATH, NULL,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "%s: Invalid error log path %s.",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_server_argv0, s->error_fname);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding exit(1);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
0942697a9b5de44865676345a3828741c827efe6rbb if ((rc = apr_file_open(&s->error_log, fname,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding APR_APPEND | APR_READ | APR_WRITE | APR_CREATE,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding APR_OS_DEFAULT, p)) != APR_SUCCESS) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "%s: could not open error log file %s.",
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb ap_server_argv0, fname);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding exit(1);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_file_set_inherit(s->error_log);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingvoid ap_open_logs(server_rec *s_main, apr_pool_t *p)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_status_t rc = APR_SUCCESS;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding server_rec *virt, *q;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int replace_stderr;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_file_t *errfile = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
3d96ee83babeec32482c9082c9426340cee8c44dwrowe open_error_log(s_main, p);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb replace_stderr = 1;
066877f1a045103acfdd376d48cdd473c33f409bdougm if (s_main->error_log) {
4e1e8abb2a6e588366a4680b039b460fc5fe1ccdstoddard /* replace stderr with this new log */
066877f1a045103acfdd376d48cdd473c33f409bdougm apr_file_flush(s_main->error_log);
40303323ae9960bd38a0f03d2c10e897a7badd88rbb if ((rc = apr_file_open_stderr(&errfile, p)) == APR_SUCCESS) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding rc = apr_file_dup2(errfile, s_main->error_log, p);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
0942697a9b5de44865676345a3828741c827efe6rbb if (rc != APR_SUCCESS) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ap_log_error(APLOG_MARK, APLOG_CRIT, rc, s_main,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm "unable to replace stderr with error_log");
3597d6b10c88c252f156fe8061b659a38dea38c2rbb }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
a1de70bda57b72d8cc6b47ea744e0973ed424f56wrowe replace_stderr = 0;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
d2e443764d6855a4a06c8eb2b7708ab9b465ddeerbb /* note that stderr may still need to be replaced with something
39b67927abc1c24834e165444655939ea52c908aorlikowski * because it points to the old error log, or back to the tty
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * of the submitter.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * XXX: This is BS - /dev/null is non-portable
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (replace_stderr && freopen("/dev/null", "w", stderr) == NULL) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_log_error(APLOG_MARK, APLOG_CRIT, errno, s_main,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "unable to replace stderr with /dev/null");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
39b67927abc1c24834e165444655939ea52c908aorlikowski
39b67927abc1c24834e165444655939ea52c908aorlikowski for (virt = s_main->next; virt; virt = virt->next) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (virt->error_fname) {
18b197c6ba1d5b8bb5b2fb372ef752f87e56912atrawick for (q=s_main; q != virt; q = q->next) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (q->error_fname != NULL
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && strcmp(q->error_fname, virt->error_fname) == 0) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding break;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
39b67927abc1c24834e165444655939ea52c908aorlikowski if (q == virt) {
39b67927abc1c24834e165444655939ea52c908aorlikowski open_error_log(virt, p);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding virt->error_log = q->error_log;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding virt->error_log = s_main->error_log;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
39b67927abc1c24834e165444655939ea52c908aorlikowski}
39b67927abc1c24834e165444655939ea52c908aorlikowski
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingAP_DECLARE(void) ap_error_log2stderr(server_rec *s) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_file_t *errfile = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_file_open_stderr(&errfile, s->process->pool);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (s->error_log != NULL) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_file_dup2(s->error_log, errfile, s->process->pool);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
39b67927abc1c24834e165444655939ea52c908aorlikowskistatic void log_error_core(const char *file, int line, int level,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_status_t status, const server_rec *s,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const request_rec *r, apr_pool_t *pool,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *fmt, va_list args)
2b484455736f4c30447aa852764f53282cbeb5ddrbb{
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet char errstr[MAX_STRING_LEN];
066877f1a045103acfdd376d48cdd473c33f409bdougm size_t len, errstrlen;
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe apr_file_t *logf = NULL;
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe const char *referer;
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe int level_and_mask = level & APLOG_LEVELMASK;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (s == NULL) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * If we are doing stderr logging (startup), don't log messages that are
2b484455736f4c30447aa852764f53282cbeb5ddrbb * above the default server log level unless it is a startup/shutdown
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * notice
74552bd6b9e2cc8bbc8e3cbb37e7a9b03d8d85e5orlikowski */
2b484455736f4c30447aa852764f53282cbeb5ddrbb if ((level_and_mask != APLOG_NOTICE)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && (level_and_mask > ap_default_loglevel)) {
39b67927abc1c24834e165444655939ea52c908aorlikowski return;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding logf = stderr_log;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (s->error_log) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * If we are doing normal logging, don't log messages that are
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * above the server log level unless it is a startup/shutdown notice
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((level_and_mask != APLOG_NOTICE)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && (level_and_mask > s->loglevel)) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding logf = s->error_log;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef TPF
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else if (tpf_child) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /*
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * If we are doing normal logging, don't log messages that are
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * above the server log level unless it is a startup/shutdown notice
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
fd47393e4c08a1515601cb1f1e8deddf4163e858martin if ((level_and_mask != APLOG_NOTICE)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && (level_and_mask > s->loglevel)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding logf = stderr;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif /* TPF */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb * If we are doing syslog logging, don't log messages that are
7041bead13293c6a2e47ae1babc35f2da1d6a749trawick * above the server log level (including a startup/shutdown notice)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm if (level_and_mask > s->loglevel) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
d2e443764d6855a4a06c8eb2b7708ab9b465ddeerbb
d2e443764d6855a4a06c8eb2b7708ab9b465ddeerbb if (logf && ((level & APLOG_STARTUP) != APLOG_STARTUP)) {
d2e443764d6855a4a06c8eb2b7708ab9b465ddeerbb errstr[0] = '[';
d2e443764d6855a4a06c8eb2b7708ab9b465ddeerbb ap_recent_ctime(errstr + 1, apr_time_now());
d2e443764d6855a4a06c8eb2b7708ab9b465ddeerbb errstr[1 + APR_CTIME_LEN - 1] = ']';
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding errstr[1 + APR_CTIME_LEN ] = ' ';
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding len = 1 + APR_CTIME_LEN + 1;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm } else {
e7daae8d2ef0165e83627188bf33655c0b8266e8wrowe len = 0;
e7daae8d2ef0165e83627188bf33655c0b8266e8wrowe }
a1de70bda57b72d8cc6b47ea744e0973ed424f56wrowe
066877f1a045103acfdd376d48cdd473c33f409bdougm if ((level & APLOG_STARTUP) != APLOG_STARTUP) {
066877f1a045103acfdd376d48cdd473c33f409bdougm len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "[%s] ", priorities[level_and_mask].t_name);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
39b67927abc1c24834e165444655939ea52c908aorlikowski#ifndef TPF
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (file && level_and_mask == APLOG_DEBUG) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef _OSD_POSIX
a7318397b355119d990d1f311b951dea2aafc53arbb char tmp[256];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *e = strrchr(file, '/');
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
3d96ee83babeec32482c9082c9426340cee8c44dwrowe /* In OSD/POSIX, the compiler returns for __FILE__
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * a string like: __FILE__="*POSIX(/usr/include/stdio.h)"
0942697a9b5de44865676345a3828741c827efe6rbb * (it even returns an absolute path for sources in
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * the current directory). Here we try to strip this
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * down to the basename.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (e != NULL && e[1] != '\0') {
3597d6b10c88c252f156fe8061b659a38dea38c2rbb apr_snprintf(tmp, sizeof(tmp), "%s", &e[1]);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb e = &tmp[strlen(tmp)-1];
3597d6b10c88c252f156fe8061b659a38dea38c2rbb if (*e == ')') {
3597d6b10c88c252f156fe8061b659a38dea38c2rbb *e = '\0';
3d96ee83babeec32482c9082c9426340cee8c44dwrowe }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm file = tmp;
3597d6b10c88c252f156fe8061b659a38dea38c2rbb }
3597d6b10c88c252f156fe8061b659a38dea38c2rbb#endif /*_OSD_POSIX*/
3597d6b10c88c252f156fe8061b659a38dea38c2rbb len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
3597d6b10c88c252f156fe8061b659a38dea38c2rbb "%s(%d): ", file, line);
3597d6b10c88c252f156fe8061b659a38dea38c2rbb }
3597d6b10c88c252f156fe8061b659a38dea38c2rbb#endif /* TPF */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (r && r->connection) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* XXX: TODO: add a method of selecting whether logged client
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * addresses are in dotted quad or resolved form... dotted
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * quad is the most secure, which is why I'm implementing it
0942697a9b5de44865676345a3828741c827efe6rbb * first. -djg
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "[client %s] ", r->connection->remote_ip);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
3597d6b10c88c252f156fe8061b659a38dea38c2rbb if (status != 0) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char buf[120];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "(%d)%s: ", status,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_strerror(status, buf, sizeof(buf)));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding errstrlen = len;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding len += apr_vsnprintf(errstr + len, MAX_STRING_LEN - len, fmt, args);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (r && (referer = apr_table_get(r->headers_in, "Referer"))) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ", referer: %s", referer);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm /* NULL if we are logging to syslog */
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim if (logf) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Truncate for the terminator (as apr_snprintf does) */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (len > MAX_STRING_LEN - sizeof(APR_EOL_STR)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding len = MAX_STRING_LEN - sizeof(APR_EOL_STR);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm strcpy(errstr + len, APR_EOL_STR);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_file_puts(errstr, logf);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_file_flush(logf);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef HAVE_SYSLOG
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm syslog(level_and_mask, "%s", errstr);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_run_error_log(file, line, level, status, s, r, pool, errstr + errstrlen);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
6f984345bbfa9342dde1f2b7b8c35b7987d078afwroweAP_DECLARE(void) ap_log_error(const char *file, int line, int level,
b31025f6f2c0392dc76eecca7f27faad0b902be0wrowe apr_status_t status, const server_rec *s,
061c3874622b67beff724876b9bd1b1f291f2eaafielding const char *fmt, ...)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding va_list args;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding va_start(args, fmt);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding log_error_core(file, line, level, status, s, NULL, NULL, fmt, args);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding va_end(args);
ff2a2c90fcf0370ae2550d710f057ea1ef333d8drbb}
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
ab5581cc78e9d865b0a6ab1404c53347b3276968rbbAP_DECLARE(void) ap_log_perror(const char *file, int line, int level,
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb apr_status_t status, apr_pool_t *p,
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb const char *fmt, ...)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding va_list args;
066877f1a045103acfdd376d48cdd473c33f409bdougm
cf5ace98ead10d803fda70674cb4dda30fddb832trawick va_start(args, fmt);
cf5ace98ead10d803fda70674cb4dda30fddb832trawick log_error_core(file, line, level, status, NULL, NULL, p, fmt, args);
cf5ace98ead10d803fda70674cb4dda30fddb832trawick va_end(args);
cf5ace98ead10d803fda70674cb4dda30fddb832trawick}
2b484455736f4c30447aa852764f53282cbeb5ddrbb
2b484455736f4c30447aa852764f53282cbeb5ddrbbAP_DECLARE(void) ap_log_rerror(const char *file, int line, int level,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_status_t status, const request_rec *r,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *fmt, ...)
066877f1a045103acfdd376d48cdd473c33f409bdougm{
066877f1a045103acfdd376d48cdd473c33f409bdougm va_list args;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding va_start(args, fmt);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding log_error_core(file, line, level, status, r->server, r, NULL, fmt, args);
3d96ee83babeec32482c9082c9426340cee8c44dwrowe
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /*
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe * IF APLOG_TOCLIENT is set,
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet * AND the error level is 'warning' or more severe,
066877f1a045103acfdd376d48cdd473c33f409bdougm * AND there isn't already error text associated with this request,
2b484455736f4c30447aa852764f53282cbeb5ddrbb * THEN make the message text available to ErrorDocument and
2b484455736f4c30447aa852764f53282cbeb5ddrbb * other error processors.
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding va_end(args);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding va_start(args,fmt);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if ((level & APLOG_TOCLIENT)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && ((level & APLOG_LEVELMASK) <= APLOG_WARNING)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding && (apr_table_get(r->notes, "error-notes") == NULL)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_table_setn(r->notes, "error-notes",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_escape_html(r->pool, apr_pvsprintf(r->pool, fmt,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding args)));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding va_end(args);
7646be5b9ab5b098bc81d3a08a47e1931dc87597rbb}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwroweAP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *filename)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_file_t *pid_file = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_finfo_t finfo;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb static pid_t saved_pid = -1;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm pid_t mypid;
db2ef76dc744b13b9a9929ebb9e6f94712a81717rbb apr_status_t rv;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm const char *fname;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb if (!filename) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb }
066877f1a045103acfdd376d48cdd473c33f409bdougm
066877f1a045103acfdd376d48cdd473c33f409bdougm fname = ap_server_root_relative(p, filename);
e4c4fcc82268e0192db234c74a6db784b879fffdrbb if (!fname) {
e4c4fcc82268e0192db234c74a6db784b879fffdrbb ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, APR_EBADPATH,
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb NULL, "Invalid PID file path %s, ignoring.", filename);
2b484455736f4c30447aa852764f53282cbeb5ddrbb return;
e4c4fcc82268e0192db234c74a6db784b879fffdrbb }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb mypid = getpid();
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (mypid != saved_pid
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb && apr_stat(&finfo, fname, APR_FINFO_MTIME, p) == APR_SUCCESS) {
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb /* AP_SIG_GRACEFUL and HUP call this on each restart.
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb * Only warn on first time through for this pid.
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb *
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * XXX: Could just write first time through too, although
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * that may screw up scripts written to do something
db2ef76dc744b13b9a9929ebb9e6f94712a81717rbb * based on the last modification time of the pid file.
066877f1a045103acfdd376d48cdd473c33f409bdougm */
cccd31fa4a72fe23cc3249c06db181b274a55a69gstein ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, p,
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb apr_psprintf(p, "pid file %s overwritten -- Unclean "
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb "shutdown of previous Apache run?",
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb fname));
066877f1a045103acfdd376d48cdd473c33f409bdougm }
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb
fa4e5ac791dd1c84df616b28d4ee9751efe9c64frbb if ((rv = apr_file_open(&pid_file, fname,
20c85ca0d404e29972fb94c3d6236a264d1c77abstoddard APR_WRITE | APR_CREATE | APR_TRUNCATE,
f17e3ffa43ed4f41d984925d22eb9f8139fcbf1dstoddard APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD, p))
066877f1a045103acfdd376d48cdd473c33f409bdougm != APR_SUCCESS) {
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb "could not create %s", fname);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb "%s: could not log pid to file %s",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_server_argv0, fname);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding exit(1);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_file_printf(pid_file, "%ld" APR_EOL_STR, (long)mypid);
10a4cdd68ef1ca0e54af296fe1d08ac00150c90bwrowe apr_file_close(pid_file);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding saved_pid = mypid;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingAP_DECLARE(apr_status_t) ap_read_pid(apr_pool_t *p, const char *filename,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding pid_t *mypid)
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb{
d7150b84735ff36eeb3cde9c79ab2e69ee7ffd67rbb const apr_size_t BUFFER_SIZE = sizeof(long) * 3 + 2; /* see apr_ltoa */
066877f1a045103acfdd376d48cdd473c33f409bdougm apr_file_t *pid_file = NULL;
d7150b84735ff36eeb3cde9c79ab2e69ee7ffd67rbb apr_status_t rv;
d7150b84735ff36eeb3cde9c79ab2e69ee7ffd67rbb const char *fname;
d7150b84735ff36eeb3cde9c79ab2e69ee7ffd67rbb char *buf, *endptr;
d7150b84735ff36eeb3cde9c79ab2e69ee7ffd67rbb apr_size_t bytes_read;
d7150b84735ff36eeb3cde9c79ab2e69ee7ffd67rbb
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb if (!filename) {
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb return APR_EGENERAL;
066877f1a045103acfdd376d48cdd473c33f409bdougm }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding fname = ap_server_root_relative(p, filename);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!fname) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_CRIT, APR_EBADPATH,
e4c4fcc82268e0192db234c74a6db784b879fffdrbb NULL, "Invalid PID file path %s, ignoring.", filename);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return APR_EGENERAL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
e4c4fcc82268e0192db234c74a6db784b879fffdrbb
2b484455736f4c30447aa852764f53282cbeb5ddrbb rv = apr_file_open(&pid_file, fname, APR_READ, APR_OS_DEFAULT, p);
2b484455736f4c30447aa852764f53282cbeb5ddrbb if (rv != APR_SUCCESS) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return rv;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Ensure null-termination, so that strtol doesn't go crazy. */
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb buf = apr_palloc(p, BUFFER_SIZE);
ffb048955d9939c0ab6ff99c2efc412d8e7a191dwrowe buf[BUFFER_SIZE - 1] = '\0';
ffb048955d9939c0ab6ff99c2efc412d8e7a191dwrowe
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding rv = apr_file_read_full(pid_file, buf, BUFFER_SIZE - 1, &bytes_read);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (rv != APR_SUCCESS && rv != APR_EOF) {
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb return rv;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb
066877f1a045103acfdd376d48cdd473c33f409bdougm /* If we fill the buffer, we're probably reading a corrupt pid file.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * To be nice, let's also ensure the first char is a digit. */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (bytes_read == BUFFER_SIZE - 1 || !apr_isdigit(*buf)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return APR_EGENERAL;
7f1290cbf118bf3d34aecc68cff2e5bd0a23e126rbb }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *mypid = strtol(buf, &endptr, 10);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_file_close(pid_file);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return APR_SUCCESS;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingAP_DECLARE(void) ap_log_assert(const char *szExp, const char *szFile,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int nLine)
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb{
066877f1a045103acfdd376d48cdd473c33f409bdougm char time_str[APR_CTIME_LEN];
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
066877f1a045103acfdd376d48cdd473c33f409bdougm apr_ctime(time_str, apr_time_now());
066877f1a045103acfdd376d48cdd473c33f409bdougm ap_log_error(APLOG_MARK, APLOG_CRIT, 0, NULL,
2a7d0035b5594ddc0907a9cc545e14ae5140c541manoj "[%s] file %s, line %d, assertion \"%s\" failed",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding time_str, szFile, nLine, szExp);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#if defined(WIN32)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding DebugBreak();
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm#else
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* unix assert does an abort leading to a core dump */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding abort();
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#endif
066877f1a045103acfdd376d48cdd473c33f409bdougm}
066877f1a045103acfdd376d48cdd473c33f409bdougm
2a7d0035b5594ddc0907a9cc545e14ae5140c541manoj/* piped log support */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#ifdef AP_HAVE_RELIABLE_PIPED_LOGS
3d96ee83babeec32482c9082c9426340cee8c44dwrowe/* forward declaration */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void piped_log_maintenance(int reason, void *data, apr_wait_t status);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic int piped_log_spawn(piped_log *pl)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding int rc;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_procattr_t *procattr;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb apr_proc_t *procnew = NULL;
066877f1a045103acfdd376d48cdd473c33f409bdougm apr_status_t status;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (((status = apr_procattr_create(&procattr, pl->p)) != APR_SUCCESS) ||
066877f1a045103acfdd376d48cdd473c33f409bdougm ((status = apr_procattr_child_in_set(procattr,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_piped_log_read_fd(pl),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_piped_log_write_fd(pl)))
066877f1a045103acfdd376d48cdd473c33f409bdougm != APR_SUCCESS)) {
066877f1a045103acfdd376d48cdd473c33f409bdougm char buf[120];
066877f1a045103acfdd376d48cdd473c33f409bdougm /* Something bad happened, give up and go away. */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding "piped_log_spawn: unable to setup child process '%s': %s",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding pl->program, apr_strerror(status, buf, sizeof(buf)));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding rc = -1;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding else {
cddad5fd27fd3b9f4375d76d04bbbeaebec00548wrowe char **args;
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb const char *pname;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_tokenize_to_argv(pl->program, &args, pl->p);
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb pname = apr_pstrdup(pl->p, args[0]);
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb procnew = apr_pcalloc(pl->p, sizeof(apr_proc_t));
066877f1a045103acfdd376d48cdd473c33f409bdougm rc = apr_proc_create(procnew, pname, (const char * const *) args,
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb NULL, procattr, pl->p);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (rc == APR_SUCCESS) {
3d96ee83babeec32482c9082c9426340cee8c44dwrowe /* pjr - This no longer happens inside the child, */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* I am assuming that if apr_proc_create was */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* successful that the child is running. */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm RAISE_SIGSTOP(PIPED_LOG_SPAWN);
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb pl->pid = procnew;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ap_piped_log_write_fd(pl) = procnew->in;
a952e0c6ece342d88f2bc04e20dcfc563398eed3rbb apr_proc_other_child_register(procnew, piped_log_maintenance, pl,
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb ap_piped_log_write_fd(pl), pl->p);
f5fccb8eae1f1a5f212a5bda878479c281f36512trawick }
f5fccb8eae1f1a5f212a5bda878479c281f36512trawick }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return 0;
2cfdca5be0c69f65b43a888d6d3da846489b8fa5rbb}
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbbstatic void piped_log_maintenance(int reason, void *data, apr_wait_t status)
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb{
066877f1a045103acfdd376d48cdd473c33f409bdougm piped_log *pl = data;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_status_t stats;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding switch (reason) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding case APR_OC_REASON_DEATH:
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb pl->pid = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding apr_proc_other_child_unregister(pl);
3d96ee83babeec32482c9082c9426340cee8c44dwrowe if (pl->program == NULL) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* during a restart */
066877f1a045103acfdd376d48cdd473c33f409bdougm break;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
b0f20a4a26bcfa85724b1c2e5ec6a077f12ef44crbb break;
a7318397b355119d990d1f311b951dea2aafc53arbb case APR_OC_REASON_LOST:
a7318397b355119d990d1f311b951dea2aafc53arbb pl->pid = NULL;
a7318397b355119d990d1f311b951dea2aafc53arbb apr_proc_other_child_unregister(pl);
a7318397b355119d990d1f311b951dea2aafc53arbb if (pl->program == NULL) {
a7318397b355119d990d1f311b951dea2aafc53arbb /* during a restart */
a7318397b355119d990d1f311b951dea2aafc53arbb break;
a7318397b355119d990d1f311b951dea2aafc53arbb }
if ((stats = piped_log_spawn(pl)) != APR_SUCCESS) {
/* what can we do? This could be the error log we're having
* problems opening up... */
char buf[120];
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
"piped_log_maintenance: unable to respawn '%s': %s",
pl->program, apr_strerror(stats, buf, sizeof(buf)));
}
break;
case APR_OC_REASON_UNWRITABLE:
/* We should not kill off the pipe here, since it may only be full.
* If it really is locked, we should kill it off manually. */
break;
case APR_OC_REASON_RESTART:
pl->program = NULL;
if (pl->pid != NULL) {
apr_proc_kill(pl->pid, SIGTERM);
}
break;
case APR_OC_REASON_UNREGISTER:
break;
}
}
static apr_status_t piped_log_cleanup_for_exec(void *data)
{
piped_log *pl = data;
apr_file_close(ap_piped_log_read_fd(pl));
apr_file_close(ap_piped_log_write_fd(pl));
return APR_SUCCESS;
}
static apr_status_t piped_log_cleanup(void *data)
{
piped_log *pl = data;
if (pl->pid != NULL) {
apr_proc_kill(pl->pid, SIGTERM);
}
return piped_log_cleanup_for_exec(data);
}
AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program)
{
piped_log *pl;
pl = apr_palloc(p, sizeof (*pl));
pl->p = p;
pl->program = apr_pstrdup(p, program);
pl->pid = NULL;
if (apr_file_pipe_create(&ap_piped_log_read_fd(pl),
&ap_piped_log_write_fd(pl), p) != APR_SUCCESS) {
return NULL;
}
apr_pool_cleanup_register(p, pl, piped_log_cleanup,
piped_log_cleanup_for_exec);
if (piped_log_spawn(pl) == -1) {
int save_errno = errno;
apr_pool_cleanup_kill(p, pl, piped_log_cleanup);
apr_file_close(ap_piped_log_read_fd(pl));
apr_file_close(ap_piped_log_write_fd(pl));
errno = save_errno;
return NULL;
}
return pl;
}
#else /* !AP_HAVE_RELIABLE_PIPED_LOGS */
static apr_status_t piped_log_cleanup(void *data)
{
piped_log *pl = data;
apr_file_close(ap_piped_log_write_fd(pl));
return APR_SUCCESS;
}
AP_DECLARE(piped_log *) ap_open_piped_log(apr_pool_t *p, const char *program)
{
piped_log *pl;
apr_file_t *dummy = NULL;
int rc;
rc = log_child(p, program, &dummy);
if (rc != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL,
"Couldn't start piped log process");
exit (1);
}
pl = apr_palloc(p, sizeof (*pl));
pl->p = p;
ap_piped_log_read_fd(pl) = NULL;
ap_piped_log_write_fd(pl) = dummy;
apr_pool_cleanup_register(p, pl, piped_log_cleanup, piped_log_cleanup);
return pl;
}
#endif
AP_DECLARE(void) ap_close_piped_log(piped_log *pl)
{
apr_pool_cleanup_run(pl->p, pl, piped_log_cleanup);
}
AP_IMPLEMENT_HOOK_VOID(error_log,
(const char *file, int line, int level,
apr_status_t status, const server_rec *s,
const request_rec *r, apr_pool_t *pool,
const char *errstr), (file, line, level,
status, s, r, pool, errstr))