log.c revision ebc18d48bea83ee5ed7a1b4e30007e5192539829
842ae4bd224140319ae7feec1872b93dfd491143fielding/* ====================================================================
842ae4bd224140319ae7feec1872b93dfd491143fielding * The Apache Software License, Version 1.1
842ae4bd224140319ae7feec1872b93dfd491143fielding *
842ae4bd224140319ae7feec1872b93dfd491143fielding * Copyright (c) 2000 The Apache Software Foundation. All rights
842ae4bd224140319ae7feec1872b93dfd491143fielding * reserved.
842ae4bd224140319ae7feec1872b93dfd491143fielding *
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 *
e8f95a682820a599fe41b22977010636be5c2717jim * 3. The end-user documentation included with the redistribution,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * if any, must include the following acknowledgment:
e8f95a682820a599fe41b22977010636be5c2717jim * "This product includes software developed by the
1747d30b98aa1bdbc43994c02cd46ab4cb9319e4fielding * 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 * ====================================================================
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes *
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes * This software consists of voluntary contributions made by many
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes * individuals on behalf of the Apache Software Foundation. For more
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes * information on the Apache Software Foundation, please see
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes * <http://www.apache.org/>.
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes *
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes * Portions of this software are based upon public domain software
cd3bbd6d2df78d6c75e5d159a81ef8bdd5f70df9trawick * originally written at the National Center for Supercomputing Applications,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * University of Illinois, Urbana-Champaign.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
0568280364eb026393be492ebc732795c4934643jorton/*
0568280364eb026393be492ebc732795c4934643jorton * http_log.c: Dealing with the logs and errors
0568280364eb026393be492ebc732795c4934643jorton *
0568280364eb026393be492ebc732795c4934643jorton * Rob McCool
0568280364eb026393be492ebc732795c4934643jorton *
0568280364eb026393be492ebc732795c4934643jorton */
0568280364eb026393be492ebc732795c4934643jorton
0568280364eb026393be492ebc732795c4934643jorton#include "apr.h"
0568280364eb026393be492ebc732795c4934643jorton#include "apr_general.h" /* for signal stuff */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "apr_strings.h"
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener#include "apr_errno.h"
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener#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
796e4a7141265d8ed7036e4628161c6eafb2a789jorton#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
8113dac419143273351446c3ad653f3fe5ba5cfdwrowetypedef struct {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes char *t_name;
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe int t_val;
e8f95a682820a599fe41b22977010636be5c2717jim} TRANS;
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe
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},
a1790fb35c4b352dab721370985c623a9f8f5062rpluem#endif
713a2b68bac4aeb1e9c48785006c0732451039depquerna#ifdef LOG_DAEMON
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes {"daemon", LOG_DAEMON},
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#ifdef LOG_FTP
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes {"ftp", LOG_FTP},
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe#ifdef LOG_KERN
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe {"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
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener {"news", LOG_NEWS},
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#ifdef LOG_SYSLOG
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes {"syslog", LOG_SYSLOG},
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#ifdef LOG_USER
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe {"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
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener#ifdef LOG_LOCAL3
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener {"local3", LOG_LOCAL3},
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener#endif
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener#ifdef LOG_LOCAL4
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener {"local4", LOG_LOCAL4},
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener#ifdef LOG_LOCAL5
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes {"local5", LOG_LOCAL5},
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#ifdef LOG_LOCAL6
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes {"local6", LOG_LOCAL6},
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#ifdef LOG_LOCAL7
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes {"local7", LOG_LOCAL7},
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener {NULL, -1},
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes};
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe#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)
1f299703465bd9975d94e9f229f76af807442de2covener{
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener apr_open_stderr(&stderr_log, p);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener}
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic int log_child(apr_pool_t *p, const char *progname,
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe apr_file_t **fpin)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* 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...
9ad7b260be233be7d7b5576979825cac72e15498rederpj */
9ad7b260be233be7d7b5576979825cac72e15498rederpj apr_status_t rc;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_procattr_t *procattr;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_proc_t *procnew;
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes
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,
3e6d7277b90d3011db832139afc20efb5f17e203rederpj APR_NO_PIPE,
3e6d7277b90d3011db832139afc20efb5f17e203rederpj APR_NO_PIPE)) == APR_SUCCESS)) {
3e6d7277b90d3011db832139afc20efb5f17e203rederpj char **args;
3e6d7277b90d3011db832139afc20efb5f17e203rederpj const char *pname;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes apr_tokenize_to_argv(progname, &args, p);
e8f95a682820a599fe41b22977010636be5c2717jim pname = apr_pstrdup(p, args[0]);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener procnew = (apr_proc_t *) apr_pcalloc(p, sizeof(*procnew));
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener rc = apr_create_process(procnew, pname, (const char * const *)args,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener NULL, procattr, p);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener if (rc == APR_SUCCESS) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener apr_note_subprocess(p, procnew, kill_after_timeout);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener (*fpin) = procnew->in;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return(rc);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener}
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic void open_error_log(server_rec *s, apr_pool_t *p)
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener{
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener const char *fname;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener int rc;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener if (*s->error_fname == '|') {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener apr_file_t *dummy = NULL;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener /* This starts a new process... */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener rc = log_child (p, s->error_fname+1, &dummy);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener if (rc != APR_SUCCESS) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener "Couldn't start ErrorLog process");
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener exit(1);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener s->error_log = dummy;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener#ifdef HAVE_SYSLOG
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener else if (!strncasecmp(s->error_fname, "syslog", 6)) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener if ((fname = strchr(s->error_fname, ':'))) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener const TRANS *fac;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes fname++;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener for (fac = facilities; fac->t_name; fac++) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener if (!strcasecmp(fname, fac->t_name)) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener fac->t_val);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener s->error_log = NULL;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener else
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID, LOG_LOCAL7);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener s->error_log = NULL;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener#endif
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener else {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener fname = ap_server_root_relative(p, s->error_fname);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener rc = apr_open(&s->error_log, fname,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener APR_APPEND | APR_READ | APR_WRITE | APR_CREATE,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes APR_OS_DEFAULT, p);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (rc != APR_SUCCESS) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_STARTUP, rc, NULL,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "%s: could not open error log file %s.",
0e05808dc59a321566303084c84b9826a4353cefrederpj ap_server_argv0, fname);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes exit(1);
b08925593f214f621161742925dcf074a8047e0acovener }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
54d22ed1c429b903b029bbd62621f11a9e286137minfrin}
465bb68501690d7a47bfd2a6129580047d76d8f1rederpj
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholesvoid ap_open_logs(server_rec *s_main, apr_pool_t *p)
465bb68501690d7a47bfd2a6129580047d76d8f1rederpj{
e8f95a682820a599fe41b22977010636be5c2717jim apr_status_t rc = APR_SUCCESS;
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes server_rec *virt, *q;
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes int replace_stderr;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin apr_file_t *errfile = NULL;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes open_error_log(s_main, p);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes replace_stderr = 1;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (s_main->error_log) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* replace stderr with this new log */
ebe5305f8b22507374358f32b74d12fb50c05a25covener apr_flush(s_main->error_log);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_open_stderr(&errfile, p);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if ((rc = apr_dupfile(&errfile, s_main->error_log, p)) != APR_SUCCESS) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_log_error(APLOG_MARK, APLOG_CRIT, rc, s_main,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "unable to replace stderr with error_log");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes } else {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes replace_stderr = 0;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* note that stderr may still need to be replaced with something
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * because it points to the old error log, or back to the tty
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * of the submitter.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (replace_stderr && freopen("/dev/null", "w", stderr) == NULL) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_log_error(APLOG_MARK, APLOG_CRIT, errno, s_main,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "unable to replace stderr with /dev/null");
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes for (virt = s_main->next; virt; virt = virt->next) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (virt->error_fname) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes for (q=s_main; q != virt; q = q->next)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (q->error_fname != NULL &&
9ad7b260be233be7d7b5576979825cac72e15498rederpj strcmp(q->error_fname, virt->error_fname) == 0)
9ad7b260be233be7d7b5576979825cac72e15498rederpj break;
9ad7b260be233be7d7b5576979825cac72e15498rederpj if (q == virt)
9ad7b260be233be7d7b5576979825cac72e15498rederpj open_error_log(virt, p);
9ad7b260be233be7d7b5576979825cac72e15498rederpj else
9ad7b260be233be7d7b5576979825cac72e15498rederpj virt->error_log = q->error_log;
9ad7b260be233be7d7b5576979825cac72e15498rederpj }
9ad7b260be233be7d7b5576979825cac72e15498rederpj else
9ad7b260be233be7d7b5576979825cac72e15498rederpj virt->error_log = s_main->error_log;
9ad7b260be233be7d7b5576979825cac72e15498rederpj }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes}
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
54d22ed1c429b903b029bbd62621f11a9e286137minfrinAP_DECLARE(void) ap_error_log2stderr(server_rec *s) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_file_t *errfile = NULL;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
ebe5305f8b22507374358f32b74d12fb50c05a25covener apr_open_stderr(&errfile, s->process->pool);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (s->error_log != NULL) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_dupfile(&(s->error_log), errfile, s->process->pool);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes}
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
54d22ed1c429b903b029bbd62621f11a9e286137minfrinstatic void log_error_core(const char *file, int line, int level,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_status_t status, const server_rec *s,
54d22ed1c429b903b029bbd62621f11a9e286137minfrin const request_rec *r, apr_pool_t *pool,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes const char *fmt, va_list args)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes{
ebe5305f8b22507374358f32b74d12fb50c05a25covener char errstr[MAX_STRING_LEN];
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes size_t len;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_file_t *logf = NULL;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes const char *referer;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (s == NULL) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /*
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * 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
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * notice
b08925593f214f621161742925dcf074a8047e0acovener */
b08925593f214f621161742925dcf074a8047e0acovener if (((level & APLOG_LEVELMASK) != APLOG_NOTICE) &&
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ((level & APLOG_LEVELMASK) > DEFAULT_LOGLEVEL))
9ad7b260be233be7d7b5576979825cac72e15498rederpj return;
9ad7b260be233be7d7b5576979825cac72e15498rederpj logf = stderr_log;
9ad7b260be233be7d7b5576979825cac72e15498rederpj }
128a5d93141a86e3afa151e921035a07297c9833rederpj else if (s->error_log) {
9ad7b260be233be7d7b5576979825cac72e15498rederpj /*
9ad7b260be233be7d7b5576979825cac72e15498rederpj * If we are doing normal logging, don't log messages that are
128a5d93141a86e3afa151e921035a07297c9833rederpj * above the server log level unless it is a startup/shutdown notice
128a5d93141a86e3afa151e921035a07297c9833rederpj */
9ad7b260be233be7d7b5576979825cac72e15498rederpj if (((level & APLOG_LEVELMASK) != APLOG_NOTICE) &&
9ad7b260be233be7d7b5576979825cac72e15498rederpj ((level & APLOG_LEVELMASK) > s->loglevel))
9ad7b260be233be7d7b5576979825cac72e15498rederpj return;
9ad7b260be233be7d7b5576979825cac72e15498rederpj logf = s->error_log;
128a5d93141a86e3afa151e921035a07297c9833rederpj }
9ad7b260be233be7d7b5576979825cac72e15498rederpj#ifdef TPF
9ad7b260be233be7d7b5576979825cac72e15498rederpj else if (tpf_child) {
9ad7b260be233be7d7b5576979825cac72e15498rederpj /*
9ad7b260be233be7d7b5576979825cac72e15498rederpj * If we are doing normal logging, don't log messages that are
9ad7b260be233be7d7b5576979825cac72e15498rederpj * above the server log level unless it is a startup/shutdown notice
9ad7b260be233be7d7b5576979825cac72e15498rederpj */
128a5d93141a86e3afa151e921035a07297c9833rederpj if (((level & APLOG_LEVELMASK) != APLOG_NOTICE) &&
9ad7b260be233be7d7b5576979825cac72e15498rederpj ((level & APLOG_LEVELMASK) > s->loglevel))
9ad7b260be233be7d7b5576979825cac72e15498rederpj return;
9ad7b260be233be7d7b5576979825cac72e15498rederpj logf = stderr;
9ad7b260be233be7d7b5576979825cac72e15498rederpj }
9ad7b260be233be7d7b5576979825cac72e15498rederpj#endif /* TPF */
9ad7b260be233be7d7b5576979825cac72e15498rederpj else {
9ad7b260be233be7d7b5576979825cac72e15498rederpj /*
9ad7b260be233be7d7b5576979825cac72e15498rederpj * If we are doing syslog logging, don't log messages that are
9ad7b260be233be7d7b5576979825cac72e15498rederpj * above the server log level (including a startup/shutdown notice)
9ad7b260be233be7d7b5576979825cac72e15498rederpj */
9ad7b260be233be7d7b5576979825cac72e15498rederpj if ((level & APLOG_LEVELMASK) > s->loglevel)
9ad7b260be233be7d7b5576979825cac72e15498rederpj return;
9ad7b260be233be7d7b5576979825cac72e15498rederpj logf = NULL;
9ad7b260be233be7d7b5576979825cac72e15498rederpj }
9ad7b260be233be7d7b5576979825cac72e15498rederpj
9ad7b260be233be7d7b5576979825cac72e15498rederpj if (logf && ((level & APLOG_STARTUP) != APLOG_STARTUP)) {
9ad7b260be233be7d7b5576979825cac72e15498rederpj errstr[0] = '[';
9ad7b260be233be7d7b5576979825cac72e15498rederpj apr_ctime(errstr + 1, apr_now());
9ad7b260be233be7d7b5576979825cac72e15498rederpj errstr[1 + APR_CTIME_LEN - 1] = ']';
7add8f7fb048534390571801b7794f71cd9e127abnicholes errstr[1 + APR_CTIME_LEN ] = ' ';
7add8f7fb048534390571801b7794f71cd9e127abnicholes len = 1 + APR_CTIME_LEN + 1;
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem } else {
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem len = 0;
7add8f7fb048534390571801b7794f71cd9e127abnicholes }
7add8f7fb048534390571801b7794f71cd9e127abnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if ((level & APLOG_STARTUP) != APLOG_STARTUP) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "[%s] ", priorities[level & APLOG_LEVELMASK].t_name);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes#ifndef TPF
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (file && (level & APLOG_LEVELMASK) == APLOG_DEBUG) {
7add8f7fb048534390571801b7794f71cd9e127abnicholes#ifdef _OSD_POSIX
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes char tmp[256];
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes char *e = strrchr(file, '/');
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* In OSD/POSIX, the compiler returns for __FILE__
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * a string like: __FILE__="*POSIX(/usr/include/stdio.h)"
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * (it even returns an absolute path for sources in
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * the current directory). Here we try to strip this
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * down to the basename.
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (e != NULL && e[1] != '\0') {
7add8f7fb048534390571801b7794f71cd9e127abnicholes apr_snprintf(tmp, sizeof(tmp), "%s", &e[1]);
7add8f7fb048534390571801b7794f71cd9e127abnicholes e = &tmp[strlen(tmp)-1];
141e1368614dc7564e1627671361b01b4869b491bnicholes if (*e == ')')
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes *e = '\0';
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes file = tmp;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes#endif /*_OSD_POSIX*/
e8f95a682820a599fe41b22977010636be5c2717jim len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "%s(%d): ", file, line);
ebe5305f8b22507374358f32b74d12fb50c05a25covener }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes#endif /* TPF */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (r && r->connection) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* XXX: TODO: add a method of selecting whether logged client
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * addresses are in dotted quad or resolved form... dotted
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes * quad is the most secure, which is why I'm implementing it
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * first. -djg
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes */
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "[client %s] ", r->connection->remote_ip);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
e8f95a682820a599fe41b22977010636be5c2717jim if (!(level & APLOG_NOERRNO)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes && (status != 0)) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes char buf[120];
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "(%d)%s: ", status, apr_strerror(status, buf, sizeof(buf)));
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes len += apr_vsnprintf(errstr + len, MAX_STRING_LEN - len, fmt, args);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (r && (referer = apr_table_get(r->headers_in, "Referer"))) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes len += apr_snprintf(errstr + len, MAX_STRING_LEN - len,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ", referer: %s", referer);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* NULL if we are logging to syslog */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (logf) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* Truncate for the terminator (as apr_snprintf does) */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (len > MAX_STRING_LEN - sizeof(APR_EOL_STR))
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes len = MAX_STRING_LEN - sizeof(APR_EOL_STR);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes strcpy(errstr + len, APR_EOL_STR);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_puts(errstr, logf);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_flush(logf);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes#ifdef HAVE_SYSLOG
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes else {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes syslog(level & APLOG_LEVELMASK, "%s", errstr);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes#endif
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes}
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesAP_DECLARE(void) ap_log_error(const char *file, int line, int level,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_status_t status, const server_rec *s,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes const char *fmt, ...)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes{
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes va_list args;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes va_start(args, fmt);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes log_error_core(file, line, level, status, s, NULL, NULL, fmt, args);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes va_end(args);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAP_DECLARE(void) ap_log_perror(const char *file, int line, int level,
e8f95a682820a599fe41b22977010636be5c2717jim 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);
54d22ed1c429b903b029bbd62621f11a9e286137minfrin va_end(args);
54d22ed1c429b903b029bbd62621f11a9e286137minfrin}
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
6733d943c9e8d0f27dd077a04037e8c49eb090ffcovenerAP_DECLARE(void) ap_log_rerror(const char *file, int line, int level,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_status_t status, const request_rec *r,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes const char *fmt, ...)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes{
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes va_list args;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes va_start(args, fmt);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes log_error_core(file, line, level, status, r->server, r, NULL, fmt, args);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /*
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * IF the error level is 'warning' or more severe,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * 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.
54d22ed1c429b903b029bbd62621f11a9e286137minfrin */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes va_end(args);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes 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);
54d22ed1c429b903b029bbd62621f11a9e286137minfrin}
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
54d22ed1c429b903b029bbd62621f11a9e286137minfrinvoid ap_log_pid(apr_pool_t *p, const char *fname)
54d22ed1c429b903b029bbd62621f11a9e286137minfrin{
54d22ed1c429b903b029bbd62621f11a9e286137minfrin apr_file_t *pid_file = NULL;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin apr_finfo_t finfo;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin static pid_t saved_pid = -1;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin pid_t mypid;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin apr_status_t rv;
e8f95a682820a599fe41b22977010636be5c2717jim
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe if (!fname)
8a03cd420b800a2428f49f4617293de9b2387b20jorton return;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
54d22ed1c429b903b029bbd62621f11a9e286137minfrin fname = ap_server_root_relative(p, fname);
54d22ed1c429b903b029bbd62621f11a9e286137minfrin mypid = getpid();
54d22ed1c429b903b029bbd62621f11a9e286137minfrin if (mypid != saved_pid && apr_stat(&finfo, fname, p) == APR_SUCCESS) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* WINCH and HUP call this on each restart.
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * Only warn on first time through for this pid.
54d22ed1c429b903b029bbd62621f11a9e286137minfrin *
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * XXX: Could just write first time through too, although
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * that may screw up scripts written to do something
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * based on the last modification time of the pid file.
54d22ed1c429b903b029bbd62621f11a9e286137minfrin */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin ap_log_perror(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, p,
54d22ed1c429b903b029bbd62621f11a9e286137minfrin apr_psprintf(p,
54d22ed1c429b903b029bbd62621f11a9e286137minfrin "pid file %s overwritten -- Unclean shutdown of previous Apache run?",
54d22ed1c429b903b029bbd62621f11a9e286137minfrin fname)
54d22ed1c429b903b029bbd62621f11a9e286137minfrin );
54d22ed1c429b903b029bbd62621f11a9e286137minfrin }
edc346c3223efd41e6a2057c37cea69744b73dccwrowe
edc346c3223efd41e6a2057c37cea69744b73dccwrowe if ((rv = apr_open(&pid_file, fname, APR_WRITE | APR_CREATE | APR_TRUNCATE,
54d22ed1c429b903b029bbd62621f11a9e286137minfrin APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD, p)) != APR_SUCCESS) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
54d22ed1c429b903b029bbd62621f11a9e286137minfrin "could not create %s", fname);
54d22ed1c429b903b029bbd62621f11a9e286137minfrin ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, NULL,
54d22ed1c429b903b029bbd62621f11a9e286137minfrin "%s: could not log pid to file %s",
54d22ed1c429b903b029bbd62621f11a9e286137minfrin ap_server_argv0, fname);
54d22ed1c429b903b029bbd62621f11a9e286137minfrin exit(1);
54d22ed1c429b903b029bbd62621f11a9e286137minfrin }
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{
e8f95a682820a599fe41b22977010636be5c2717jim char time_str[APR_CTIME_LEN];
e8f95a682820a599fe41b22977010636be5c2717jim
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe apr_ctime(time_str, apr_now());
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
e8f95a682820a599fe41b22977010636be5c2717jim "[%s] file %s, line %d, assertion \"%s\" failed",
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe time_str, szFile, nLine, szExp);
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe#ifndef WIN32
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe /* unix assert does an abort leading to a core dump */
f0f6f1b90ab582896f8a7d56d85bd62a55e57d90covener abort();
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe#else
54d22ed1c429b903b029bbd62621f11a9e286137minfrin exit(1);
560fd0658902ab57754616c172d8953e69fc4722bnicholes#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
e8f95a682820a599fe41b22977010636be5c2717jim
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* piped log support */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
9ad7b260be233be7d7b5576979825cac72e15498rederpj#ifdef AP_HAVE_RELIABLE_PIPED_LOGS
9ad7b260be233be7d7b5576979825cac72e15498rederpj/* 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;
560fd0658902ab57754616c172d8953e69fc4722bnicholes apr_proc_t *procnew = NULL;
560fd0658902ab57754616c172d8953e69fc4722bnicholes apr_status_t status;
560fd0658902ab57754616c172d8953e69fc4722bnicholes
560fd0658902ab57754616c172d8953e69fc4722bnicholes#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. */
e8f95a682820a599fe41b22977010636be5c2717jim ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
e8f95a682820a599fe41b22977010636be5c2717jim "piped_log_spawn: unable to setup child process '%s': %s",
e8f95a682820a599fe41b22977010636be5c2717jim pl->program, apr_strerror(status, buf, sizeof(buf)));
e8f95a682820a599fe41b22977010636be5c2717jim rc = -1;
e8f95a682820a599fe41b22977010636be5c2717jim }
e8f95a682820a599fe41b22977010636be5c2717jim else {
e8f95a682820a599fe41b22977010636be5c2717jim char **args;
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe 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}
e8f95a682820a599fe41b22977010636be5c2717jim
560fd0658902ab57754616c172d8953e69fc4722bnicholes
e8f95a682820a599fe41b22977010636be5c2717jimstatic void piped_log_maintenance(int reason, void *data, apr_wait_t status)
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes piped_log *pl = data;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_status_t stats;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes switch (reason) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes case APR_OC_REASON_DEATH:
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pl->pid = NULL;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_unregister_other_child(pl);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (pl->program == NULL) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* during a restart */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes 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) {
0e05808dc59a321566303084c84b9826a4353cefrederpj /* 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,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener "piped_log_maintenance: unable to respawn '%s': %s",
0e05808dc59a321566303084c84b9826a4353cefrederpj pl->program, apr_strerror(stats, buf, sizeof(buf)));
ebe5305f8b22507374358f32b74d12fb50c05a25covener }
ebe5305f8b22507374358f32b74d12fb50c05a25covener break;
ebe5305f8b22507374358f32b74d12fb50c05a25covener
ebe5305f8b22507374358f32b74d12fb50c05a25covener case APR_OC_REASON_UNWRITABLE:
ebe5305f8b22507374358f32b74d12fb50c05a25covener /* We should not kill off the pipe here, since it may only be full.
ebe5305f8b22507374358f32b74d12fb50c05a25covener * If it really is locked, we should kill it off manually. */
ebe5305f8b22507374358f32b74d12fb50c05a25covener break;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener case APR_OC_REASON_RESTART:
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener pl->program = NULL;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener if (pl->pid != NULL) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener apr_kill(pl->pid, SIGTERM);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener break;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener case APR_OC_REASON_UNREGISTER:
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener break;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener }
0e05808dc59a321566303084c84b9826a4353cefrederpj}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic apr_status_t piped_log_cleanup(void *data)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes piped_log *pl = data;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (pl->pid != NULL) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_kill(pl->pid, SIGTERM);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_unregister_other_child(pl);
9ad7b260be233be7d7b5576979825cac72e15498rederpj apr_close(ap_piped_log_read_fd(pl));
9ad7b260be233be7d7b5576979825cac72e15498rederpj apr_close(ap_piped_log_write_fd(pl));
54d22ed1c429b903b029bbd62621f11a9e286137minfrin return APR_SUCCESS;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin}
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
54d22ed1c429b903b029bbd62621f11a9e286137minfrinstatic apr_status_t piped_log_cleanup_for_exec(void *data)
54d22ed1c429b903b029bbd62621f11a9e286137minfrin{
560fd0658902ab57754616c172d8953e69fc4722bnicholes piped_log *pl = data;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
54d22ed1c429b903b029bbd62621f11a9e286137minfrin apr_close(ap_piped_log_read_fd(pl));
54d22ed1c429b903b029bbd62621f11a9e286137minfrin apr_close(ap_piped_log_write_fd(pl));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return APR_SUCCESS;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener}
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
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));
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe errno = save_errno;
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe return NULL;
e8f95a682820a599fe41b22977010636be5c2717jim }
e8f95a682820a599fe41b22977010636be5c2717jim return pl;
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#else
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
e8f95a682820a599fe41b22977010636be5c2717jimstatic apr_status_t piped_log_cleanup(void *data)
e8f95a682820a599fe41b22977010636be5c2717jim{
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe piped_log *pl = data;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_close(ap_piped_log_write_fd(pl));
e8f95a682820a599fe41b22977010636be5c2717jim 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;
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe
e8f95a682820a599fe41b22977010636be5c2717jim rc = log_child(p, program, &dummy);
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe 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
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes