log.c revision cb9e6e5c78f5a1690214e9548250fc6af1fc73b5
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny/* ====================================================================
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * The Apache Software License, Version 1.1
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny *
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * reserved.
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny *
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * Redistribution and use in source and binary forms, with or without
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * modification, are permitted provided that the following conditions
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * are met:
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny *
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * 1. Redistributions of source code must retain the above copyright
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * notice, this list of conditions and the following disclaimer.
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny *
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * 2. Redistributions in binary form must reproduce the above copyright
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * notice, this list of conditions and the following disclaimer in
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * the documentation and/or other materials provided with the
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * distribution.
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny *
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * 3. The end-user documentation included with the redistribution,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * if any, must include the following acknowledgment:
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * "This product includes software developed by the
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * Apache Software Foundation (http://www.apache.org/)."
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * Alternately, this acknowledgment may appear in the software itself,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * if and wherever such third-party acknowledgments normally appear.
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny *
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * 4. The names "Apache" and "Apache Software Foundation" must
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny * not be used to endorse or promote products derived from this
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * software without prior written permission. For written
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * permission, please contact apache@apache.org.
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny *
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * 5. Products derived from this software may not be called "Apache",
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * nor may "Apache" appear in their name, without prior written
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * permission of the Apache Software Foundation.
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny *
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * SUCH DAMAGE.
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * ====================================================================
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny *
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * This software consists of voluntary contributions made by many
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * individuals on behalf of the Apache Software Foundation. For more
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * information on the Apache Software Foundation, please see
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny * <http://www.apache.org/>.
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny *
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * Portions of this software are based upon public domain software
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * originally written at the National Center for Supercomputing Applications,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * University of Illinois, Urbana-Champaign.
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny/*
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * http_log.c: Dealing with the logs and errors
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny *
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * Rob McCool
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny *
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#include "apr.h"
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#include "apr_general.h" /* for signal stuff */
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny#include "apr_strings.h"
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny#include "apr_errno.h"
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny#include "apr_thread_proc.h"
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny#include "apr_lib.h"
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny#include "apr_signal.h"
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#define APR_WANT_STDIO
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#define APR_WANT_STRFUNC
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#include "apr_want.h"
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#if APR_HAVE_STDARG_H
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#include <stdarg.h>
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny#if APR_HAVE_UNISTD_H
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny#include <unistd.h>
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#define CORE_PRIVATE
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#include "ap_config.h"
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#include "httpd.h"
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#include "http_config.h"
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#include "http_core.h"
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#include "http_log.h"
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#include "http_main.h"
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenytypedef struct {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny char *t_name;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny int t_val;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny} TRANS;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan ZelenyAPR_HOOK_STRUCT(
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny APR_HOOK_LINK(error_log)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny)
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zelenyint AP_DECLARE_DATA ap_default_loglevel = DEFAULT_LOGLEVEL;
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny
ca4b7b92738f3dd463914e3de5757cd98d37a983Stephen Gallagher#ifdef HAVE_SYSLOG
ca4b7b92738f3dd463914e3de5757cd98d37a983Stephen Gallagher
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zelenystatic const TRANS facilities[] = {
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny {"auth", LOG_AUTH},
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny#ifdef LOG_AUTHPRIV
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"authpriv",LOG_AUTHPRIV},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifdef LOG_CRON
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny {"cron", LOG_CRON},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifdef LOG_DAEMON
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny {"daemon", LOG_DAEMON},
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny#endif
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny#ifdef LOG_FTP
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"ftp", LOG_FTP},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifdef LOG_KERN
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"kern", LOG_KERN},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifdef LOG_LPR
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"lpr", LOG_LPR},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifdef LOG_MAIL
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"mail", LOG_MAIL},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifdef LOG_NEWS
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"news", LOG_NEWS},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifdef LOG_SYSLOG
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"syslog", LOG_SYSLOG},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifdef LOG_USER
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"user", LOG_USER},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifdef LOG_UUCP
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"uucp", LOG_UUCP},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifdef LOG_LOCAL0
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"local0", LOG_LOCAL0},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifdef LOG_LOCAL1
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"local1", LOG_LOCAL1},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifdef LOG_LOCAL2
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"local2", LOG_LOCAL2},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifdef LOG_LOCAL3
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"local3", LOG_LOCAL3},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifdef LOG_LOCAL4
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"local4", LOG_LOCAL4},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifdef LOG_LOCAL5
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"local5", LOG_LOCAL5},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifdef LOG_LOCAL6
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"local6", LOG_LOCAL6},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifdef LOG_LOCAL7
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"local7", LOG_LOCAL7},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {NULL, -1},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny};
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny#endif
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic const TRANS priorities[] = {
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher {"emerg", APLOG_EMERG},
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher {"alert", APLOG_ALERT},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"crit", APLOG_CRIT},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"error", APLOG_ERR},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"warn", APLOG_WARNING},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"notice", APLOG_NOTICE},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"info", APLOG_INFO},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {"debug", APLOG_DEBUG},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny {NULL, -1},
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny};
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic apr_file_t *stderr_log;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan ZelenyAP_DECLARE(void) ap_open_stderr_log(apr_pool_t *p)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny{
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny apr_file_open_stderr(&stderr_log, p);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny}
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic int log_child(apr_pool_t *p, const char *progname,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny apr_file_t **fpin)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny{
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* Child process code for 'ErrorLog "|..."';
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * may want a common framework for this, since I expect it will
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * be common for other foo-loggers to want this sort of thing...
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny apr_status_t rc;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny apr_procattr_t *procattr;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny apr_proc_t *procnew;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifdef SIGHUP
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* No concept of a child process on Win32 */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny apr_signal(SIGHUP, SIG_IGN);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif /* ndef SIGHUP */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (((rc = apr_procattr_create(&procattr, p)) == APR_SUCCESS) &&
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ((rc = apr_procattr_io_set(procattr,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny APR_FULL_BLOCK,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny APR_NO_PIPE,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny APR_NO_PIPE)) == APR_SUCCESS)) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny char **args;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny const char *pname;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny apr_tokenize_to_argv(progname, &args, p);
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny pname = apr_pstrdup(p, args[0]);
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny procnew = (apr_proc_t *)apr_pcalloc(p, sizeof(*procnew));
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny rc = apr_proc_create(procnew, pname, (const char * const *)args,
ca4b7b92738f3dd463914e3de5757cd98d37a983Stephen Gallagher NULL, procattr, p);
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (rc == APR_SUCCESS) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny apr_pool_note_subprocess(p, procnew, kill_after_timeout);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny (*fpin) = procnew->in;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return rc;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny}
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic void open_error_log(server_rec *s, apr_pool_t *p)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny{
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny const char *fname;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny int rc;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (*s->error_fname == '|') {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny apr_file_t *dummy = NULL;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* This starts a new process... */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny rc = log_child (p, s->error_fname + 1, &dummy);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (rc != APR_SUCCESS) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny "Couldn't start ErrorLog process");
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny exit(1);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny s->error_log = dummy;
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifdef HAVE_SYSLOG
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny else if (!strncasecmp(s->error_fname, "syslog", 6)) {
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny if ((fname = strchr(s->error_fname, ':'))) {
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny const TRANS *fac;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny fname++;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny for (fac = facilities; fac->t_name; fac++) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (!strcasecmp(fname, fac->t_name)) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny fac->t_val);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny s->error_log = NULL;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return;
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny }
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny }
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny }
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny else {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID, LOG_LOCAL7);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny s->error_log = NULL;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny else {
74f857536411b46712f9b3dc0f1c53924b36dc02Stephen Gallagher fname = ap_server_root_relative(p, s->error_fname);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny rc = apr_file_open(&s->error_log, fname,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny APR_APPEND | APR_READ | APR_WRITE | APR_CREATE,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny APR_OS_DEFAULT, p);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (rc != APR_SUCCESS) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny "%s: could not open error log file %s.",
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ap_server_argv0, fname);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny exit(1);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny apr_file_set_inherit(s->error_log);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny}
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenyvoid ap_open_logs(server_rec *s_main, apr_pool_t *p)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny{
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny apr_status_t rc = APR_SUCCESS;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny server_rec *virt, *q;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny int replace_stderr;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny apr_file_t *errfile = NULL;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny open_error_log(s_main, p);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny replace_stderr = 1;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (s_main->error_log) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* replace stderr with this new log */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny apr_file_flush(s_main->error_log);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny apr_file_open_stderr(&errfile, p);
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny rc = apr_file_dup2(&errfile, s_main->error_log, p);
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny if (rc != APR_SUCCESS) {
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny ap_log_error(APLOG_MARK, APLOG_CRIT, rc, s_main,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny "unable to replace stderr with error_log");
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher } else {
2f3ee3f49019f5b60adbe073070f31e6e2d7c7abStephen Gallagher replace_stderr = 0;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* note that stderr may still need to be replaced with something
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * because it points to the old error log, or back to the tty
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * of the submitter.
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (replace_stderr && freopen("/dev/null", "w", stderr) == NULL) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny ap_log_error(APLOG_MARK, APLOG_CRIT, errno, s_main,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny "unable to replace stderr with /dev/null");
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny for (virt = s_main->next; virt; virt = virt->next) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (virt->error_fname) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny for (q=s_main; q != virt; q = q->next) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (q->error_fname != NULL &&
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny strcmp(q->error_fname, virt->error_fname) == 0) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny break;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (q == virt) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny open_error_log(virt, p);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny else {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny virt->error_log = q->error_log;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny else {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny virt->error_log = s_main->error_log;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny}
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
07002c911aa643000856f78707f1fee72b5eea29Jakub HrozekAP_DECLARE(void) ap_error_log2stderr(server_rec *s) {
07002c911aa643000856f78707f1fee72b5eea29Jakub Hrozek apr_file_t *errfile = NULL;
07002c911aa643000856f78707f1fee72b5eea29Jakub Hrozek
07002c911aa643000856f78707f1fee72b5eea29Jakub Hrozek apr_file_open_stderr(&errfile, s->process->pool);
07002c911aa643000856f78707f1fee72b5eea29Jakub Hrozek if (s->error_log != NULL) {
07002c911aa643000856f78707f1fee72b5eea29Jakub Hrozek apr_file_dup2(&(s->error_log), errfile, s->process->pool);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny}
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zelenystatic void log_error_core(const char *file, int line, int level,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny apr_status_t status, const server_rec *s,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny const request_rec *r, apr_pool_t *pool,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny const char *fmt, va_list args)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny{
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny char errstr[MAX_STRING_LEN];
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny size_t len, errstrlen;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny apr_file_t *logf = NULL;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny const char *referer;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny int level_and_mask = level & APLOG_LEVELMASK;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (s == NULL) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /*
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * If we are doing stderr logging (startup), don't log messages that are
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * above the default server log level unless it is a startup/shutdown
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * notice
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if ((level_and_mask != APLOG_NOTICE) &&
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny (level_and_mask > ap_default_loglevel)) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny logf = stderr_log;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny else if (s->error_log) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /*
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * If we are doing normal logging, don't log messages that are
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * above the server log level unless it is a startup/shutdown notice
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if ((level_and_mask != APLOG_NOTICE) &&
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny (level_and_mask > s->loglevel)) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny logf = s->error_log;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifdef TPF
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny else if (tpf_child) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /*
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * If we are doing normal logging, don't log messages that are
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * above the server log level unless it is a startup/shutdown notice
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if ((level_and_mask != APLOG_NOTICE) &&
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny (level_and_mask > s->loglevel)) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny logf = stderr;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif /* TPF */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny else {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /*
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * If we are doing syslog logging, don't log messages that are
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * above the server log level (including a startup/shutdown notice)
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (level_and_mask > s->loglevel) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny return;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (logf && ((level & APLOG_STARTUP) != APLOG_STARTUP)) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny errstr[0] = '[';
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny apr_ctime(errstr + 1, apr_time_now());
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny errstr[1 + APR_CTIME_LEN - 1] = ']';
fdab7bbf8933351f6254438c30ff361cd748b15aJan Zeleny errstr[1 + APR_CTIME_LEN ] = ' ';
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny len = 1 + APR_CTIME_LEN + 1;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny } else {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny len = 0;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if ((level & APLOG_STARTUP) != APLOG_STARTUP) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny "[%s] ", priorities[level_and_mask].t_name);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifndef TPF
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (file && level_and_mask == APLOG_DEBUG) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#ifdef _OSD_POSIX
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny char tmp[256];
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny char *e = strrchr(file, '/');
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* In OSD/POSIX, the compiler returns for __FILE__
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * a string like: __FILE__="*POSIX(/usr/include/stdio.h)"
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * (it even returns an absolute path for sources in
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * the current directory). Here we try to strip this
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * down to the basename.
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (e != NULL && e[1] != '\0') {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny apr_snprintf(tmp, sizeof(tmp), "%s", &e[1]);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny e = &tmp[strlen(tmp)-1];
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (*e == ')') {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny *e = '\0';
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny file = tmp;
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif /*_OSD_POSIX*/
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny "%s(%d): ", file, line);
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny#endif /* TPF */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (r && r->connection) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny /* XXX: TODO: add a method of selecting whether logged client
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * addresses are in dotted quad or resolved form... dotted
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * quad is the most secure, which is why I'm implementing it
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny * first. -djg
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny */
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
1a7d1977037864e52858058777af8ff8401547ddJan Cholasta "[client %s] ", r->connection->remote_ip);
1a7d1977037864e52858058777af8ff8401547ddJan Cholasta }
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny if (!(level & APLOG_NOERRNO) && (status != 0)) {
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny char buf[120];
ad07ed37b6b51ef134d4524edaf2259e19ac984fJan Zeleny len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
"(%d)%s: ", status,
apr_strerror(status, buf, sizeof(buf)));
}
errstrlen = len;
len += apr_vsnprintf(errstr + len, MAX_STRING_LEN - len, fmt, args);
if (r && (referer = apr_table_get(r->headers_in, "Referer"))) {
len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
", referer: %s", referer);
}
/* NULL if we are logging to syslog */
if (logf) {
/* Truncate for the terminator (as apr_snprintf does) */
if (len > MAX_STRING_LEN - sizeof(APR_EOL_STR)) {
len = MAX_STRING_LEN - sizeof(APR_EOL_STR);
}
strcpy(errstr + len, APR_EOL_STR);
apr_file_puts(errstr, logf);
apr_file_flush(logf);
}
#ifdef HAVE_SYSLOG
else {
syslog(level_and_mask, "%s", errstr);
}
#endif
ap_run_error_log(file, line, level, status, s, r, pool, errstr + errstrlen);
}
AP_DECLARE(void) ap_log_error(const char *file, int line, int level,
apr_status_t status, const server_rec *s,
const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
log_error_core(file, line, level, status, s, NULL, NULL, fmt, args);
va_end(args);
}
AP_DECLARE(void) ap_log_perror(const char *file, int line, int level,
apr_status_t status, apr_pool_t *p,
const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
log_error_core(file, line, level, status, NULL, NULL, p, fmt, args);
va_end(args);
}
AP_DECLARE(void) ap_log_rerror(const char *file, int line, int level,
apr_status_t status, const request_rec *r,
const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
log_error_core(file, line, level, status, r->server, r, NULL, fmt, args);
/*
* IF the error level is 'warning' or more severe,
* AND there isn't already error text associated with this request,
* THEN make the message text available to ErrorDocument and
* other error processors. This can be disabled by stuffing
* something, even an empty string, into the "error-notes" cell
* before calling this routine.
*/
va_end(args);
va_start(args,fmt);
if (((level & APLOG_LEVELMASK) <= APLOG_WARNING)
&& (apr_table_get(r->notes, "error-notes") == NULL)) {
apr_table_setn(r->notes, "error-notes",
ap_escape_html(r->pool, apr_pvsprintf(r->pool, fmt,
args)));
}
va_end(args);
}
AP_DECLARE(void) ap_log_pid(apr_pool_t *p, const char *fname)
{
apr_file_t *pid_file = NULL;
apr_finfo_t finfo;
static pid_t saved_pid = -1;
pid_t mypid;
apr_status_t rv;
if (!fname)
return;
fname = ap_server_root_relative(p, fname);
mypid = getpid();
if (mypid != saved_pid
&& apr_stat(&finfo, fname, APR_FINFO_MTIME, p) == APR_SUCCESS) {
/* AP_SIG_GRACEFUL and HUP call this on each restart.
* Only warn on first time through for this pid.
*
* XXX: Could just write first time through too, although
* that may screw up scripts written to do something
* based on the last modification time of the pid file.
*/
ap_log_perror(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, p,
apr_psprintf(p, "pid file %s overwritten -- Unclean "
"shutdown of previous Apache run?",
fname));
}
if ((rv = apr_file_open(&pid_file, fname,
APR_WRITE | APR_CREATE | APR_TRUNCATE,
APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD, p))
!= APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
"could not create %s", fname);
ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, NULL,
"%s: could not log pid to file %s",
ap_server_argv0, fname);
exit(1);
}
apr_file_printf(pid_file, "%ld" APR_EOL_STR, (long)mypid);
apr_file_close(pid_file);
saved_pid = mypid;
}
AP_DECLARE(void) ap_log_assert(const char *szExp, const char *szFile,
int nLine)
{
char time_str[APR_CTIME_LEN];
apr_ctime(time_str, apr_time_now());
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
"[%s] file %s, line %d, assertion \"%s\" failed",
time_str, szFile, nLine, szExp);
#if !defined(WIN32) && !defined(NETWARE)
/* unix assert does an abort leading to a core dump */
abort();
#else
exit(1);
#endif
}
/* piped log support */
#ifdef AP_HAVE_RELIABLE_PIPED_LOGS
/* forward declaration */
static void piped_log_maintenance(int reason, void *data, apr_wait_t status);
static int piped_log_spawn(piped_log *pl)
{
int rc;
apr_procattr_t *procattr;
apr_proc_t *procnew = NULL;
apr_status_t status;
#ifdef SIGHUP
apr_signal(SIGHUP, SIG_IGN);
#endif
if (((status = apr_procattr_create(&procattr, pl->p)) != APR_SUCCESS) ||
((status = apr_procattr_child_in_set(procattr,
ap_piped_log_read_fd(pl),
ap_piped_log_write_fd(pl)))
!= APR_SUCCESS)) {
char buf[120];
/* Something bad happened, give up and go away. */
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
"piped_log_spawn: unable to setup child process '%s': %s",
pl->program, apr_strerror(status, buf, sizeof(buf)));
rc = -1;
}
else {
char **args;
const char *pname;
apr_tokenize_to_argv(pl->program, &args, pl->p);
pname = apr_pstrdup(pl->p, args[0]);
procnew = apr_pcalloc(pl->p, sizeof(apr_proc_t));
rc = apr_proc_create(procnew, pname, (const char * const *) args,
NULL, procattr, pl->p);
if (rc == APR_SUCCESS) {
/* pjr - This no longer happens inside the child, */
/* I am assuming that if apr_proc_create was */
/* successful that the child is running. */
RAISE_SIGSTOP(PIPED_LOG_SPAWN);
pl->pid = procnew;
ap_piped_log_write_fd(pl) = procnew->in;
apr_proc_other_child_register(procnew, piped_log_maintenance, pl,
ap_piped_log_write_fd(pl), pl->p);
}
}
return 0;
}
static void piped_log_maintenance(int reason, void *data, apr_wait_t status)
{
piped_log *pl = data;
apr_status_t stats;
switch (reason) {
case APR_OC_REASON_DEATH:
pl->pid = NULL;
apr_proc_other_child_unregister(pl);
if (pl->program == NULL) {
/* during a restart */
break;
}
break;
case APR_OC_REASON_LOST:
pl->pid = NULL;
apr_proc_other_child_unregister(pl);
if (pl->program == NULL) {
/* during a restart */
break;
}
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 | APLOG_NOERRNO, 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))