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