log.c revision 48d7c43629323c8d5ee9f7bd0d194de0a376b391
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 *
11f2c481e1d57bedb3f758565307501e9a2730ddtrawick * 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.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *
5c0419d51818eb02045cf923a9fe456127a44c60wrowe * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
5c0419d51818eb02045cf923a9fe456127a44c60wrowe * 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
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
cd3bbd6d2df78d6c75e5d159a81ef8bdd5f70df9trawick * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf * SUCH DAMAGE.
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * ====================================================================
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf *
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf * This software consists of voluntary contributions made by many
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf * individuals on behalf of the Apache Software Foundation. For more
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf * information on the Apache Software Foundation, please see
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf * <http://www.apache.org/>.
bede2929837dfd23863ad4b39199c63126566d61jorton *
0f60998368b493f90120180a93fc2e1e74490872covener * Portions of this software are based upon public domain software
0f60998368b493f90120180a93fc2e1e74490872covener * originally written at the National Center for Supercomputing Applications,
0f60998368b493f90120180a93fc2e1e74490872covener * University of Illinois, Urbana-Champaign.
0f60998368b493f90120180a93fc2e1e74490872covener */
0f60998368b493f90120180a93fc2e1e74490872covener
0f60998368b493f90120180a93fc2e1e74490872covener/*
0f60998368b493f90120180a93fc2e1e74490872covener * http_log.c: Dealing with the logs and errors
0f60998368b493f90120180a93fc2e1e74490872covener *
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * Rob McCool
87587593f1a53030e840acc0dec6cc881022ea40covener *
87587593f1a53030e840acc0dec6cc881022ea40covener */
87587593f1a53030e840acc0dec6cc881022ea40covener
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener#define CORE_PRIVATE
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener#include "apr.h" /* for ap_signal */
97cd2f98ad4abe68aaaba96b5bfc9ebf7109a2c1covener#include "ap_config.h"
97cd2f98ad4abe68aaaba96b5bfc9ebf7109a2c1covener#include "apr_lib.h"
97cd2f98ad4abe68aaaba96b5bfc9ebf7109a2c1covener#include "apr_portable.h"
97cd2f98ad4abe68aaaba96b5bfc9ebf7109a2c1covener#include "httpd.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "http_config.h"
43997561b2302d13dee973998e77743a3ddd2374trawick#include "http_core.h"
fa123db15501821e36e513afa78e839775ad2800covener#include "http_log.h"
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "http_main.h"
0568280364eb026393be492ebc732795c4934643jorton
0568280364eb026393be492ebc732795c4934643jorton#ifdef HAVE_STDARG_H
0568280364eb026393be492ebc732795c4934643jorton#include <stdarg.h>
0568280364eb026393be492ebc732795c4934643jorton#endif
0568280364eb026393be492ebc732795c4934643jorton
0568280364eb026393be492ebc732795c4934643jortontypedef struct {
0568280364eb026393be492ebc732795c4934643jorton char *t_name;
0568280364eb026393be492ebc732795c4934643jorton int t_val;
0568280364eb026393be492ebc732795c4934643jorton} TRANS;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
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
796e4a7141265d8ed7036e4628161c6eafb2a789jorton {"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},
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#ifdef LOG_NEWS
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin {"news", LOG_NEWS},
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#ifdef LOG_SYSLOG
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin {"syslog", LOG_SYSLOG},
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin#ifdef LOG_USER
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes {"user", LOG_USER},
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#ifdef LOG_UUCP
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes {"uucp", LOG_UUCP},
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin#ifdef LOG_LOCAL0
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin {"local0", LOG_LOCAL0},
95b6fe1346805e1731e6e97c15d569c73be22cf7minfrin#endif
a1790fb35c4b352dab721370985c623a9f8f5062rpluem#ifdef LOG_LOCAL1
713a2b68bac4aeb1e9c48785006c0732451039depquerna {"local1", LOG_LOCAL1},
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#ifdef LOG_LOCAL2
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes {"local2", LOG_LOCAL2},
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#ifdef LOG_LOCAL3
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe {"local3", LOG_LOCAL3},
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe#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},
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#ifdef LOG_LOCAL7
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes {"local7", LOG_LOCAL7},
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes {NULL, -1},
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes};
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic const TRANS priorities[] = {
fa123db15501821e36e513afa78e839775ad2800covener {"emerg", APLOG_EMERG},
fa123db15501821e36e513afa78e839775ad2800covener {"alert", APLOG_ALERT},
fa123db15501821e36e513afa78e839775ad2800covener {"crit", APLOG_CRIT},
fa123db15501821e36e513afa78e839775ad2800covener {"error", APLOG_ERR},
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim {"warn", APLOG_WARNING},
fa123db15501821e36e513afa78e839775ad2800covener {"notice", APLOG_NOTICE},
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener {"info", APLOG_INFO},
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim {"debug", APLOG_DEBUG},
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener {NULL, -1},
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener};
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic int log_child(ap_pool_t *p, const char *progname,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_file_t **fpin)
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener{
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...
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int rc = -1;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_procattr_t *procattr;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener ap_proc_t procnew;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe#ifdef SIGHUP
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* No concept of a child process on Win32 */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_signal(SIGHUP, SIG_IGN);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif /* ndef SIGHUP */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if ((ap_createprocattr_init(&procattr, p) != APR_SUCCESS) ||
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes (ap_setprocattr_io(procattr,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes APR_FULL_BLOCK,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes APR_NO_PIPE,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes APR_NO_PIPE) != APR_SUCCESS)) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Something bad happened, give up and go away. */
fa123db15501821e36e513afa78e839775ad2800covener rc = -1;
cceddc0b6c0fdaed0c73abda39975bb1d388243acovener }
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf else {
fa123db15501821e36e513afa78e839775ad2800covener char **args;
cceddc0b6c0fdaed0c73abda39975bb1d388243acovener const char *pname;
f2be127030aa4190033084f0a6add531c9bc41desf
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener ap_tokenize_to_argv(progname, &args, p);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener pname = ap_pstrdup(p, args[0]);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener rc = ap_create_process(&procnew, pname, args, NULL, procattr, p);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
60215f303c7e1ce8b6d272acb5bfa5b3d99dfd34covener if (rc == APR_SUCCESS) {
60215f303c7e1ce8b6d272acb5bfa5b3d99dfd34covener ap_note_subprocess(p, &procnew, kill_after_timeout);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener (*fpin) = procnew.in;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return(rc);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener}
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jimstatic void open_error_log(server_rec *s, ap_pool_t *p)
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener{
6683642c1e0032eeeed5f99e8c14880692ef84c5sf const char *fname;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener int rc;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener if (*s->error_fname == '|') {
6683642c1e0032eeeed5f99e8c14880692ef84c5sf ap_file_t *dummy = NULL;
6683642c1e0032eeeed5f99e8c14880692ef84c5sf
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener /* This starts a new process... */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener rc = log_child (p, s->error_fname+1, &dummy);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener if (rc != APR_SUCCESS) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener perror("ap_spawn_child");
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener "Couldn't fork child for ErrorLog process");
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener exit(1);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener s->error_log = dummy;
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim }
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim#ifdef HAVE_SYSLOG
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener else if (!strncasecmp(s->error_fname, "syslog", 6)) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener if ((fname = strchr(s->error_fname, ':'))) {
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener const TRANS *fac;
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener fname++;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes for (fac = facilities; fac->t_name; fac++) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes 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 {
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim fname = ap_server_root_relative(p, s->error_fname);
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim /* Change to AP funcs. */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (ap_open(&s->error_log, fname, APR_APPEND |
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes APR_READ | APR_WRITE | APR_CREATE, APR_OS_DEFAULT, p) != APR_SUCCESS) {
60215f303c7e1ce8b6d272acb5bfa5b3d99dfd34covener perror("fopen");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "%s: could not open error log file %s.",
0e05808dc59a321566303084c84b9826a4353cefrederpj ap_server_argv0, fname);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes exit(1);
b08925593f214f621161742925dcf074a8047e0acovener }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf}
465bb68501690d7a47bfd2a6129580047d76d8f1rederpj
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jimvoid ap_open_logs(server_rec *s_main, ap_pool_t *p)
465bb68501690d7a47bfd2a6129580047d76d8f1rederpj{
e8f95a682820a599fe41b22977010636be5c2717jim ap_status_t rc = APR_SUCCESS;
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes server_rec *virt, *q;
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes int replace_stderr;
55e2e59e5910072e51c870afc68b0907f41a28e0sf ap_file_t *errfile = NULL;
55e2e59e5910072e51c870afc68b0907f41a28e0sf
55e2e59e5910072e51c870afc68b0907f41a28e0sf open_error_log(s_main, p);
55e2e59e5910072e51c870afc68b0907f41a28e0sf
55e2e59e5910072e51c870afc68b0907f41a28e0sf replace_stderr = 1;
55e2e59e5910072e51c870afc68b0907f41a28e0sf if (s_main->error_log) {
55e2e59e5910072e51c870afc68b0907f41a28e0sf /* replace stderr with this new log */
55e2e59e5910072e51c870afc68b0907f41a28e0sf ap_flush(s_main->error_log);
55e2e59e5910072e51c870afc68b0907f41a28e0sf ap_open_stderr(&errfile, p);
55e2e59e5910072e51c870afc68b0907f41a28e0sf if ((rc = ap_dupfile(&errfile, s_main->error_log, NULL)) != APR_SUCCESS) {
55e2e59e5910072e51c870afc68b0907f41a28e0sf ap_log_error(APLOG_MARK, APLOG_CRIT, rc, s_main,
55e2e59e5910072e51c870afc68b0907f41a28e0sf "unable to replace stderr with error_log");
55e2e59e5910072e51c870afc68b0907f41a28e0sf } else {
55e2e59e5910072e51c870afc68b0907f41a28e0sf replace_stderr = 0;
55e2e59e5910072e51c870afc68b0907f41a28e0sf }
55e2e59e5910072e51c870afc68b0907f41a28e0sf }
55e2e59e5910072e51c870afc68b0907f41a28e0sf /* 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
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * 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 }
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes for (virt = s_main->next; virt; virt = virt->next) {
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf if (virt->error_fname) {
55e2e59e5910072e51c870afc68b0907f41a28e0sf for (q=s_main; q != virt; q = q->next)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (q->error_fname != NULL &&
513b324e774c559b579896df131fd7c8471ed529rederpj strcmp(q->error_fname, virt->error_fname) == 0)
513b324e774c559b579896df131fd7c8471ed529rederpj break;
513b324e774c559b579896df131fd7c8471ed529rederpj if (q == virt)
513b324e774c559b579896df131fd7c8471ed529rederpj open_error_log(virt, p);
513b324e774c559b579896df131fd7c8471ed529rederpj else
513b324e774c559b579896df131fd7c8471ed529rederpj virt->error_log = q->error_log;
513b324e774c559b579896df131fd7c8471ed529rederpj }
513b324e774c559b579896df131fd7c8471ed529rederpj else
513b324e774c559b579896df131fd7c8471ed529rederpj virt->error_log = s_main->error_log;
513b324e774c559b579896df131fd7c8471ed529rederpj }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes}
02fd88c85a9850109753b87612955ad372de1575sf
02fd88c85a9850109753b87612955ad372de1575sfAPI_EXPORT(void) ap_error_log2stderr(server_rec *s) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_file_t *errfile = NULL;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_open_stderr(&errfile, s->process->pool);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (s->error_log != NULL) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_dupfile(&(s->error_log), errfile, s->process->pool);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes}
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesstatic void log_error_core(const char *file, int line, int level,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_status_t status, const server_rec *s,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const request_rec *r, ap_pool_t *pool,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes const char *fmt, va_list args)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes char errstr[MAX_STRING_LEN + 1]; /* + 1 to have room for '\n' */
707f6d077f73cc948deead8df5b40ea42c1eaa78covener size_t len;
707f6d077f73cc948deead8df5b40ea42c1eaa78covener ap_file_t *logf = NULL;
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf
707f6d077f73cc948deead8df5b40ea42c1eaa78covener if (s == NULL) {
185aa71728867671e105178b4c66fbc22b65ae26sf /*
707f6d077f73cc948deead8df5b40ea42c1eaa78covener * If we are doing stderr logging (startup), don't log messages that are
707f6d077f73cc948deead8df5b40ea42c1eaa78covener * above the default server log level unless it is a startup/shutdown
707f6d077f73cc948deead8df5b40ea42c1eaa78covener * notice
707f6d077f73cc948deead8df5b40ea42c1eaa78covener */
707f6d077f73cc948deead8df5b40ea42c1eaa78covener if (((level & APLOG_LEVELMASK) != APLOG_NOTICE) &&
9ad7b260be233be7d7b5576979825cac72e15498rederpj ((level & APLOG_LEVELMASK) > DEFAULT_LOGLEVEL))
9ad7b260be233be7d7b5576979825cac72e15498rederpj return;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_open_stderr(&logf, NULL);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
54d22ed1c429b903b029bbd62621f11a9e286137minfrin else if (s->error_log) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /*
55e2e59e5910072e51c870afc68b0907f41a28e0sf * If we are doing normal logging, don't log messages that are
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf * above the server log level unless it is a startup/shutdown notice
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (((level & APLOG_LEVELMASK) != APLOG_NOTICE) &&
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ((level & APLOG_LEVELMASK) > s->loglevel))
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes logf = s->error_log;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes#ifdef TPF
54d22ed1c429b903b029bbd62621f11a9e286137minfrin else if (tpf_child) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /*
55e2e59e5910072e51c870afc68b0907f41a28e0sf * If we are doing normal logging, don't log messages that are
55e2e59e5910072e51c870afc68b0907f41a28e0sf * above the server log level unless it is a startup/shutdown notice
55e2e59e5910072e51c870afc68b0907f41a28e0sf */
55e2e59e5910072e51c870afc68b0907f41a28e0sf if (((level & APLOG_LEVELMASK) != APLOG_NOTICE) &&
55e2e59e5910072e51c870afc68b0907f41a28e0sf ((level & APLOG_LEVELMASK) > s->loglevel))
55e2e59e5910072e51c870afc68b0907f41a28e0sf return;
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf logf = stderr;
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes#endif /* TPF */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes else {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /*
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * If we are doing syslog logging, don't log messages that are
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * above the server log level (including a startup/shutdown notice)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if ((level & APLOG_LEVELMASK) > s->loglevel)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return;
b08925593f214f621161742925dcf074a8047e0acovener logf = NULL;
b08925593f214f621161742925dcf074a8047e0acovener }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim if (logf && ((level & APLOG_STARTUP) != APLOG_STARTUP)) {
707f6d077f73cc948deead8df5b40ea42c1eaa78covener errstr[0] = '[';
185aa71728867671e105178b4c66fbc22b65ae26sf ap_ctime(errstr + 1, ap_now());
707f6d077f73cc948deead8df5b40ea42c1eaa78covener errstr[1 + AP_CTIME_LEN - 1] = ']';
707f6d077f73cc948deead8df5b40ea42c1eaa78covener errstr[1 + AP_CTIME_LEN ] = ' ';
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf len = 1 + AP_CTIME_LEN + 1;
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf } else {
707f6d077f73cc948deead8df5b40ea42c1eaa78covener len = 0;
707f6d077f73cc948deead8df5b40ea42c1eaa78covener }
707f6d077f73cc948deead8df5b40ea42c1eaa78covener
9ad7b260be233be7d7b5576979825cac72e15498rederpj if ((level & APLOG_STARTUP) != APLOG_STARTUP) {
185aa71728867671e105178b4c66fbc22b65ae26sf len += ap_snprintf(errstr + len, MAX_STRING_LEN - len,
707f6d077f73cc948deead8df5b40ea42c1eaa78covener "[%s] ", priorities[level & APLOG_LEVELMASK].t_name);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener }
707f6d077f73cc948deead8df5b40ea42c1eaa78covener#ifndef TPF
707f6d077f73cc948deead8df5b40ea42c1eaa78covener if (file && (level & APLOG_LEVELMASK) == APLOG_DEBUG) {
707f6d077f73cc948deead8df5b40ea42c1eaa78covener#ifdef _OSD_POSIX
707f6d077f73cc948deead8df5b40ea42c1eaa78covener char tmp[256];
707f6d077f73cc948deead8df5b40ea42c1eaa78covener char *e = strrchr(file, '/');
707f6d077f73cc948deead8df5b40ea42c1eaa78covener
707f6d077f73cc948deead8df5b40ea42c1eaa78covener /* In OSD/POSIX, the compiler returns for __FILE__
707f6d077f73cc948deead8df5b40ea42c1eaa78covener * a string like: __FILE__="*POSIX(/usr/include/stdio.h)"
707f6d077f73cc948deead8df5b40ea42c1eaa78covener * (it even returns an absolute path for sources in
185aa71728867671e105178b4c66fbc22b65ae26sf * the current directory). Here we try to strip this
707f6d077f73cc948deead8df5b40ea42c1eaa78covener * down to the basename.
707f6d077f73cc948deead8df5b40ea42c1eaa78covener */
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf if (e != NULL && e[1] != '\0') {
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf ap_snprintf(tmp, sizeof(tmp), "%s", &e[1]);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener e = &tmp[strlen(tmp)-1];
707f6d077f73cc948deead8df5b40ea42c1eaa78covener if (*e == ')')
707f6d077f73cc948deead8df5b40ea42c1eaa78covener *e = '\0';
185aa71728867671e105178b4c66fbc22b65ae26sf file = tmp;
707f6d077f73cc948deead8df5b40ea42c1eaa78covener }
707f6d077f73cc948deead8df5b40ea42c1eaa78covener#endif /*_OSD_POSIX*/
707f6d077f73cc948deead8df5b40ea42c1eaa78covener len += ap_snprintf(errstr + len, MAX_STRING_LEN - len,
707f6d077f73cc948deead8df5b40ea42c1eaa78covener "%s(%d): ", file, line);
707f6d077f73cc948deead8df5b40ea42c1eaa78covener }
707f6d077f73cc948deead8df5b40ea42c1eaa78covener#endif /* TPF */
707f6d077f73cc948deead8df5b40ea42c1eaa78covener if (r && r->connection) {
707f6d077f73cc948deead8df5b40ea42c1eaa78covener /* XXX: TODO: add a method of selecting whether logged client
9ad7b260be233be7d7b5576979825cac72e15498rederpj * addresses are in dotted quad or resolved form... dotted
9ad7b260be233be7d7b5576979825cac72e15498rederpj * quad is the most secure, which is why I'm implementing it
9ad7b260be233be7d7b5576979825cac72e15498rederpj * first. -djg
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf */
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf len += ap_snprintf(errstr + len, MAX_STRING_LEN - len,
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf "[client %s] ", r->connection->remote_ip);
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem }
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf if (!(level & APLOG_NOERRNO)
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf && (status != 0)) {
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf char buf[120];
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf len += ap_snprintf(errstr + len, MAX_STRING_LEN - len,
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf "(%d)%s: ", status, ap_strerror(status, buf, sizeof(buf)));
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf }
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf len += ap_vsnprintf(errstr + len, MAX_STRING_LEN - len, fmt, args);
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf /* NULL if we are logging to syslog */
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf if (logf) {
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf /* We know that we have one more character of space available because
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf * the array is sized that way */
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf /* ap_assert(len < MAX_STRING_LEN) */
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf errstr[len++] = '\n';
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf errstr[len] = '\0';
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf ap_puts(errstr, logf);
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf ap_flush(logf);
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf }
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf#ifdef HAVE_SYSLOG
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf else {
141e1368614dc7564e1627671361b01b4869b491bnicholes syslog(level & APLOG_LEVELMASK, "%s", errstr);
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes#endif
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf}
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
e8f95a682820a599fe41b22977010636be5c2717jimAPI_EXPORT(void) ap_log_error(const char *file, int line, int level,
1ae7a5fbce5d4f65f3da355792258fe5dbc4ef55covener ap_status_t status, const server_rec *s,
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf const char *fmt, ...)
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf{
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes va_list args;
185aa71728867671e105178b4c66fbc22b65ae26sf
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes va_start(args, fmt);
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes log_error_core(file, line, level, status, s, NULL, NULL, fmt, args);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes va_end(args);
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes}
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes
4be9c459920a7c1cfe62d654327dae5c4bb6b284sfAPI_EXPORT(void) ap_log_perror(const char *file, int line, int level,
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf ap_status_t status, ap_pool_t *p,
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf const char *fmt, ...)
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf{
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf va_list args;
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf va_start(args, fmt);
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf log_error_core(file, line, level, status, NULL, NULL, p, fmt, args);
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf va_end(args);
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf}
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf
4be9c459920a7c1cfe62d654327dae5c4bb6b284sfAPI_EXPORT(void) ap_log_rerror(const char *file, int line, int level,
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf ap_status_t status, const request_rec *r,
185aa71728867671e105178b4c66fbc22b65ae26sf const char *fmt, ...)
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf{
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf va_list args;
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf va_start(args, fmt);
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf log_error_core(file, line, level, status, r->server, r, NULL, fmt, args);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /*
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * IF the error level is 'warning' or more severe,
e8f95a682820a599fe41b22977010636be5c2717jim * AND there isn't already error text associated with this request,
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * THEN make the message text available to ErrorDocument and
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * other error processors. This can be disabled by stuffing
96ebb616bbf4ac2a422cc5d9770c9ad07ccecdc0covener * something, even an empty string, into the "error-notes" cell
96ebb616bbf4ac2a422cc5d9770c9ad07ccecdc0covener * before calling this routine.
96ebb616bbf4ac2a422cc5d9770c9ad07ccecdc0covener */
96ebb616bbf4ac2a422cc5d9770c9ad07ccecdc0covener va_end(args);
96ebb616bbf4ac2a422cc5d9770c9ad07ccecdc0covener va_start(args,fmt);
96ebb616bbf4ac2a422cc5d9770c9ad07ccecdc0covener if (((level & APLOG_LEVELMASK) <= APLOG_WARNING)
96ebb616bbf4ac2a422cc5d9770c9ad07ccecdc0covener && (ap_table_get(r->notes, "error-notes") == NULL)) {
96ebb616bbf4ac2a422cc5d9770c9ad07ccecdc0covener ap_table_setn(r->notes, "error-notes",
96ebb616bbf4ac2a422cc5d9770c9ad07ccecdc0covener ap_escape_html(r->pool, ap_pvsprintf(r->pool, fmt,
783874b86bfe13d7a4fe0922f344a3779cdccea3covener args)));
7dbf29be626018bc389ef94c1846aeac4b72633bsf }
7dbf29be626018bc389ef94c1846aeac4b72633bsf va_end(args);
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim}
7dbf29be626018bc389ef94c1846aeac4b72633bsf
7dbf29be626018bc389ef94c1846aeac4b72633bsfvoid ap_log_pid(ap_pool_t *p, const char *fname)
7dbf29be626018bc389ef94c1846aeac4b72633bsf{
7dbf29be626018bc389ef94c1846aeac4b72633bsf ap_file_t *pid_file = NULL;
7dbf29be626018bc389ef94c1846aeac4b72633bsf ap_finfo_t finfo;
7dbf29be626018bc389ef94c1846aeac4b72633bsf static pid_t saved_pid = -1;
7dbf29be626018bc389ef94c1846aeac4b72633bsf pid_t mypid;
7dbf29be626018bc389ef94c1846aeac4b72633bsf ap_status_t rv;
7dbf29be626018bc389ef94c1846aeac4b72633bsf
7dbf29be626018bc389ef94c1846aeac4b72633bsf if (!fname)
7dbf29be626018bc389ef94c1846aeac4b72633bsf return;
7dbf29be626018bc389ef94c1846aeac4b72633bsf
783874b86bfe13d7a4fe0922f344a3779cdccea3covener fname = ap_server_root_relative(p, fname);
7dbf29be626018bc389ef94c1846aeac4b72633bsf mypid = getpid();
7dbf29be626018bc389ef94c1846aeac4b72633bsf if (mypid != saved_pid && ap_stat(&finfo, fname, p) == APR_SUCCESS) {
7dbf29be626018bc389ef94c1846aeac4b72633bsf /* WINCH and HUP call this on each restart.
7dbf29be626018bc389ef94c1846aeac4b72633bsf * Only warn on first time through for this pid.
7dbf29be626018bc389ef94c1846aeac4b72633bsf *
783874b86bfe13d7a4fe0922f344a3779cdccea3covener * XXX: Could just write first time through too, although
7dbf29be626018bc389ef94c1846aeac4b72633bsf * that may screw up scripts written to do something
7dbf29be626018bc389ef94c1846aeac4b72633bsf * based on the last modification time of the pid file.
7dbf29be626018bc389ef94c1846aeac4b72633bsf */
7dbf29be626018bc389ef94c1846aeac4b72633bsf ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, NULL,
7dbf29be626018bc389ef94c1846aeac4b72633bsf ap_psprintf(p,
7dbf29be626018bc389ef94c1846aeac4b72633bsf "pid file %s overwritten -- Unclean shutdown of previous Apache run?",
7dbf29be626018bc389ef94c1846aeac4b72633bsf fname)
783874b86bfe13d7a4fe0922f344a3779cdccea3covener );
7dbf29be626018bc389ef94c1846aeac4b72633bsf }
7dbf29be626018bc389ef94c1846aeac4b72633bsf
7dbf29be626018bc389ef94c1846aeac4b72633bsf if ((rv = ap_open(&pid_file, fname, APR_WRITE | APR_CREATE | APR_TRUNCATE,
7dbf29be626018bc389ef94c1846aeac4b72633bsf APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD, p)) != APR_SUCCESS) {
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "could not create %s", fname);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, NULL,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "%s: could not log pid to file %s",
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_server_argv0, fname);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes exit(1);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes }
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_fprintf(pid_file, "%ld\n", (long)mypid);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_close(pid_file);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes saved_pid = mypid;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes}
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
4be9c459920a7c1cfe62d654327dae5c4bb6b284sfAPI_EXPORT(void) ap_log_error_old(const char *err, server_rec *s)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes{
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_log_error(APLOG_MARK, APLOG_ERR, errno, s, "%s", err);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes}
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesAPI_EXPORT(void) ap_log_unixerr(const char *routine, const char *file,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes const char *msg, server_rec *s)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes{
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_log_error(file, 0, APLOG_ERR, errno, s, "%s", msg);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes}
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesAPI_EXPORT(void) ap_log_printf(const server_rec *s, const char *fmt, ...)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes{
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes va_list args;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes va_start(args, fmt);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes log_error_core(APLOG_MARK, APLOG_ERR, errno, s, NULL, NULL, fmt, args);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes va_end(args);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes}
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesAPI_EXPORT(void) ap_log_reason(const char *reason, const char *file, request_rec *r)
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes{
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes ap_log_error(APLOG_MARK, APLOG_ERR, errno, r->server,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "access to %s failed for %s, reason: %s",
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes file,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_NAME),
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes reason);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf
4be9c459920a7c1cfe62d654327dae5c4bb6b284sfAPI_EXPORT(void) ap_log_assert(const char *szExp, const char *szFile, int nLine)
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf{
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener char time_str[AP_CTIME_LEN];
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener ap_ctime(time_str, ap_now());
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf "[%s] file %s, line %d, assertion \"%s\" failed",
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes time_str, szFile, nLine, szExp);
e8f95a682820a599fe41b22977010636be5c2717jim#ifndef WIN32
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* unix assert does an abort leading to a core dump */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes abort();
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#else
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf exit(1);
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener#endif
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener}
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener/* piped log support */
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener
7dbf29be626018bc389ef94c1846aeac4b72633bsf#ifdef HAVE_RELIABLE_PIPED_LOGS
7dbf29be626018bc389ef94c1846aeac4b72633bsf/* forward declaration */
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covenerstatic void piped_log_maintenance(int reason, void *data, ap_wait_t status);
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covenerstatic int piped_log_spawn(piped_log *pl)
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener{
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener int rc;
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim ap_procattr_t *procattr;
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener ap_proc_t procnew;
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener ap_status_t status;
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener#ifdef SIGHUP
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener ap_signal(SIGHUP, SIG_IGN);
185aa71728867671e105178b4c66fbc22b65ae26sf#endif
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener if (((status = ap_createprocattr_init(&procattr, pl->p)) != APR_SUCCESS) ||
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim ((status = ap_setprocattr_childin(procattr, ap_piped_log_read_fd(pl),
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener ap_piped_log_write_fd(pl))) != APR_SUCCESS)) {
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener char buf[120];
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim /* Something bad happened, give up and go away. */
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener "piped_log_spawn: unable to setup child process '%s': %s",
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener pl->program, ap_strerror(status, buf, sizeof(buf)));
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener rc = -1;
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener }
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim else {
9c63a05713cb83a44a1590b4af33edeebf39f118sf char **args;
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener const char *pname;
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim
60d81cab99dccfbb0c8d378cf6aa7338be0fdb74covener ap_tokenize_to_argv(pl->program, &args, pl->p);
9c63a05713cb83a44a1590b4af33edeebf39f118sf pname = ap_pstrdup(pl->p, args[0]);
9c63a05713cb83a44a1590b4af33edeebf39f118sf
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf rc = ap_create_process(&procnew, pname, args, NULL, procattr, pl->p);
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (rc == APR_SUCCESS) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* pjr - This no longer happens inside the child, */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* I am assuming that if ap_create_process was */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* successful that the child is running. */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes RAISE_SIGSTOP(PIPED_LOG_SPAWN);
9c63a05713cb83a44a1590b4af33edeebf39f118sf pl->pid = &procnew;
4be9c459920a7c1cfe62d654327dae5c4bb6b284sf ap_register_other_child(&procnew, piped_log_maintenance, pl,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_piped_log_write_fd(pl), pl->p);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return 0;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
54d22ed1c429b903b029bbd62621f11a9e286137minfrinstatic void piped_log_maintenance(int reason, void *data, ap_wait_t status)
54d22ed1c429b903b029bbd62621f11a9e286137minfrin{
54d22ed1c429b903b029bbd62621f11a9e286137minfrin piped_log *pl = data;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin ap_status_t stats;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
54d22ed1c429b903b029bbd62621f11a9e286137minfrin switch (reason) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin case APR_OC_REASON_DEATH:
e8f95a682820a599fe41b22977010636be5c2717jim pl->pid = NULL;
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe ap_unregister_other_child(pl);
8a03cd420b800a2428f49f4617293de9b2387b20jorton if (pl->program == NULL) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* during a restart */
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf break;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin }
54d22ed1c429b903b029bbd62621f11a9e286137minfrin break;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin case APR_OC_REASON_LOST:
54d22ed1c429b903b029bbd62621f11a9e286137minfrin pl->pid = NULL;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin ap_unregister_other_child(pl);
54d22ed1c429b903b029bbd62621f11a9e286137minfrin if (pl->program == NULL) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* during a restart */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin break;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin }
54d22ed1c429b903b029bbd62621f11a9e286137minfrin if ((stats = piped_log_spawn(pl)) != APR_SUCCESS) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* what can we do? This could be the error log we're having
54d22ed1c429b903b029bbd62621f11a9e286137minfrin * problems opening up... */
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf char buf[120];
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
54d22ed1c429b903b029bbd62621f11a9e286137minfrin "piped_log_maintenance: unable to respawn '%s': %s",
6999a76d8eb5ef6b4b295e51df0b2fb6064bd373covener pl->program, ap_strerror(stats, buf, sizeof(buf)));
6999a76d8eb5ef6b4b295e51df0b2fb6064bd373covener }
6999a76d8eb5ef6b4b295e51df0b2fb6064bd373covener break;
6999a76d8eb5ef6b4b295e51df0b2fb6064bd373covener
6999a76d8eb5ef6b4b295e51df0b2fb6064bd373covener case APR_OC_REASON_UNWRITABLE:
6999a76d8eb5ef6b4b295e51df0b2fb6064bd373covener if (pl->pid != NULL) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin ap_kill(pl->pid, SIGTERM);
54d22ed1c429b903b029bbd62621f11a9e286137minfrin }
54d22ed1c429b903b029bbd62621f11a9e286137minfrin break;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin
54d22ed1c429b903b029bbd62621f11a9e286137minfrin case APR_OC_REASON_RESTART:
54d22ed1c429b903b029bbd62621f11a9e286137minfrin pl->program = NULL;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin if (pl->pid != NULL) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_kill(pl->pid, SIGTERM);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes break;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes case APR_OC_REASON_UNREGISTER:
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes break;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes }
e8f95a682820a599fe41b22977010636be5c2717jim}
e8f95a682820a599fe41b22977010636be5c2717jim
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic ap_status_t piped_log_cleanup(void *data)
e8f95a682820a599fe41b22977010636be5c2717jim{
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe piped_log *pl = data;
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe if (pl->pid != NULL) {
f0f6f1b90ab582896f8a7d56d85bd62a55e57d90covener ap_kill(pl->pid, SIGTERM);
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe }
54d22ed1c429b903b029bbd62621f11a9e286137minfrin ap_unregister_other_child(pl);
560fd0658902ab57754616c172d8953e69fc4722bnicholes ap_close(ap_piped_log_read_fd(pl));
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener ap_close(ap_piped_log_write_fd(pl));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return APR_SUCCESS;
e8f95a682820a599fe41b22977010636be5c2717jim}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
9ad7b260be233be7d7b5576979825cac72e15498rederpjstatic ap_status_t piped_log_cleanup_for_exec(void *data)
9ad7b260be233be7d7b5576979825cac72e15498rederpj{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes piped_log *pl = data;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_close(ap_piped_log_read_fd(pl));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_close(ap_piped_log_write_fd(pl));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return APR_SUCCESS;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
ab86c68ce36c715e93f403dde41d0b9c1522c8b0sf
560fd0658902ab57754616c172d8953e69fc4722bnicholesAPI_EXPORT(piped_log *) ap_open_piped_log(ap_pool_t *p, const char *program)
560fd0658902ab57754616c172d8953e69fc4722bnicholes{
560fd0658902ab57754616c172d8953e69fc4722bnicholes piped_log *pl;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pl = ap_palloc(p, sizeof (*pl));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pl->p = p;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pl->program = ap_pstrdup(p, program);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pl->pid = NULL;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (ap_create_pipe(&ap_piped_log_read_fd(pl), &ap_piped_log_write_fd(pl), p) != APR_SUCCESS) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int save_errno = errno;
e8f95a682820a599fe41b22977010636be5c2717jim errno = save_errno;
e8f95a682820a599fe41b22977010636be5c2717jim return NULL;
e8f95a682820a599fe41b22977010636be5c2717jim }
e8f95a682820a599fe41b22977010636be5c2717jim ap_block_pipe(ap_piped_log_read_fd(pl));
e8f95a682820a599fe41b22977010636be5c2717jim ap_block_pipe(ap_piped_log_write_fd(pl));
e8f95a682820a599fe41b22977010636be5c2717jim ap_register_cleanup(p, pl, piped_log_cleanup, piped_log_cleanup_for_exec);
ae1981fc94adf2b231e2d0e15d2f895b2138c969covener if (piped_log_spawn(pl) == -1) {
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe int save_errno = errno;
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim ap_kill_cleanup(p, pl, piped_log_cleanup);
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim ap_close(ap_piped_log_read_fd(pl));
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim ap_close(ap_piped_log_write_fd(pl));
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim errno = save_errno;
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener return NULL;
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener }
54091ac5c596337658fc568231ca1a900abdc5fecovener return pl;
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener}
a81c0c1ae464b2063a21b45f80c9da8d89bb840ecovener
54091ac5c596337658fc568231ca1a900abdc5fecovener#else
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic ap_status_t piped_log_cleanup(void *data)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes piped_log *pl = data;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_close(ap_piped_log_write_fd(pl));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return APR_SUCCESS;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(piped_log *) ap_open_piped_log(ap_pool_t *p, const char *program)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes piped_log *pl;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_file_t *dummy = NULL;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes int rc;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes rc = log_child(p, program, &dummy);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (rc != APR_SUCCESS) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes perror("ap_spawn_child");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "Couldn't fork child for piped log process");
e8f95a682820a599fe41b22977010636be5c2717jim exit (1);
560fd0658902ab57754616c172d8953e69fc4722bnicholes }
ae1981fc94adf2b231e2d0e15d2f895b2138c969covener
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe pl = ap_palloc(p, sizeof (*pl));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes pl->p = p;
7a55c294da84865fe13262ed66ffd0c5841a9da5covener ap_piped_log_read_fd(pl) = NULL;
fa123db15501821e36e513afa78e839775ad2800covener ap_piped_log_write_fd(pl) = dummy;
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim ap_register_cleanup(p, pl, piped_log_cleanup, piped_log_cleanup);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return pl;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesAPI_EXPORT(void) ap_close_piped_log(piped_log *pl)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes{
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_run_cleanup(pl->p, pl, piped_log_cleanup);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes}
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes