log.c revision f5d913e797a32274e105222016bd67617bf224a0
af84459fbf938e508fd10b01cb8d699c79083813takashi/* ====================================================================
af84459fbf938e508fd10b01cb8d699c79083813takashi * The Apache Software License, Version 1.1
af84459fbf938e508fd10b01cb8d699c79083813takashi *
af84459fbf938e508fd10b01cb8d699c79083813takashi * Copyright (c) 2000 The Apache Software Foundation. All rights
af84459fbf938e508fd10b01cb8d699c79083813takashi * reserved.
af84459fbf938e508fd10b01cb8d699c79083813takashi *
af84459fbf938e508fd10b01cb8d699c79083813takashi * Redistribution and use in source and binary forms, with or without
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen * modification, are permitted provided that the following conditions
af84459fbf938e508fd10b01cb8d699c79083813takashi * are met:
af84459fbf938e508fd10b01cb8d699c79083813takashi *
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * 1. Redistributions of source code must retain the above copyright
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * notice, this list of conditions and the following disclaimer.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen *
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * 2. Redistributions in binary form must reproduce the above copyright
af84459fbf938e508fd10b01cb8d699c79083813takashi * notice, this list of conditions and the following disclaimer in
af84459fbf938e508fd10b01cb8d699c79083813takashi * the documentation and/or other materials provided with the
af84459fbf938e508fd10b01cb8d699c79083813takashi * distribution.
3f08db06526d6901aa08c110b5bc7dde6bc39905nd *
af84459fbf938e508fd10b01cb8d699c79083813takashi * 3. The end-user documentation included with the redistribution,
af84459fbf938e508fd10b01cb8d699c79083813takashi * if any, must include the following acknowledgment:
af84459fbf938e508fd10b01cb8d699c79083813takashi * "This product includes software developed by the
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * Apache Software Foundation (http://www.apache.org/)."
af84459fbf938e508fd10b01cb8d699c79083813takashi * Alternately, this acknowledgment may appear in the software itself,
af84459fbf938e508fd10b01cb8d699c79083813takashi * if and wherever such third-party acknowledgments normally appear.
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung *
af84459fbf938e508fd10b01cb8d699c79083813takashi * 4. The names "Apache" and "Apache Software Foundation" must
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen * not be used to endorse or promote products derived from this
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen * software without prior written permission. For written
af84459fbf938e508fd10b01cb8d699c79083813takashi * permission, please contact apache@apache.org.
af84459fbf938e508fd10b01cb8d699c79083813takashi *
af84459fbf938e508fd10b01cb8d699c79083813takashi * 5. Products derived from this software may not be called "Apache",
af84459fbf938e508fd10b01cb8d699c79083813takashi * nor may "Apache" appear in their name, without prior written
3c13a815670b54d1c17bf02954f7d2b066cde95cnd * permission of the Apache Software Foundation.
3c13a815670b54d1c17bf02954f7d2b066cde95cnd *
2d39a41e98476f5235b7c37ce745a4aa0904b1cbrbowen * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
af84459fbf938e508fd10b01cb8d699c79083813takashi * SUCH DAMAGE.
af84459fbf938e508fd10b01cb8d699c79083813takashi * ====================================================================
af84459fbf938e508fd10b01cb8d699c79083813takashi *
af84459fbf938e508fd10b01cb8d699c79083813takashi * This software consists of voluntary contributions made by many
af84459fbf938e508fd10b01cb8d699c79083813takashi * individuals on behalf of the Apache Software Foundation. For more
af84459fbf938e508fd10b01cb8d699c79083813takashi * information on the Apache Software Foundation, please see
af84459fbf938e508fd10b01cb8d699c79083813takashi * <http://www.apache.org/>.
af84459fbf938e508fd10b01cb8d699c79083813takashi *
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen * Portions of this software are based upon public domain software
af84459fbf938e508fd10b01cb8d699c79083813takashi * originally written at the National Center for Supercomputing Applications,
af84459fbf938e508fd10b01cb8d699c79083813takashi * University of Illinois, Urbana-Champaign.
af84459fbf938e508fd10b01cb8d699c79083813takashi */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
af84459fbf938e508fd10b01cb8d699c79083813takashi/*
3c13a815670b54d1c17bf02954f7d2b066cde95cnd * http_log.c: Dealing with the logs and errors
af84459fbf938e508fd10b01cb8d699c79083813takashi *
af84459fbf938e508fd10b01cb8d699c79083813takashi * Rob McCool
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen *
af84459fbf938e508fd10b01cb8d699c79083813takashi */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#define CORE_PRIVATE
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#include "apr.h" /* for ap_signal */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#include "ap_config.h"
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#include "apr_lib.h"
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf#include "apr_portable.h"
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#include "httpd.h"
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#include "http_config.h"
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#include "http_core.h"
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen#include "http_log.h"
78f97ce162b66a0dbfd7af4dcd9984f162569b04minfrin#include "http_main.h"
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#include <stdarg.h>
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowetypedef struct {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe char *t_name;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe int t_val;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe} TRANS;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen#ifdef HAVE_SYSLOG
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic const TRANS facilities[] = {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"auth", LOG_AUTH},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#ifdef LOG_AUTHPRIV
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"authpriv",LOG_AUTHPRIV},
4bebf996eb7002ebfe897d46a0e0572390604a77nd#endif
4bebf996eb7002ebfe897d46a0e0572390604a77nd#ifdef LOG_CRON
4bebf996eb7002ebfe897d46a0e0572390604a77nd {"cron", LOG_CRON},
4bebf996eb7002ebfe897d46a0e0572390604a77nd#endif
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#ifdef LOG_DAEMON
4bebf996eb7002ebfe897d46a0e0572390604a77nd {"daemon", LOG_DAEMON},
9534272616b71aaea50aeec4162e749a96aebd7fsf#endif
4bebf996eb7002ebfe897d46a0e0572390604a77nd#ifdef LOG_FTP
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"ftp", LOG_FTP},
af84459fbf938e508fd10b01cb8d699c79083813takashi#endif
af84459fbf938e508fd10b01cb8d699c79083813takashi#ifdef LOG_KERN
af84459fbf938e508fd10b01cb8d699c79083813takashi {"kern", LOG_KERN},
af84459fbf938e508fd10b01cb8d699c79083813takashi#endif
af84459fbf938e508fd10b01cb8d699c79083813takashi#ifdef LOG_LPR
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"lpr", LOG_LPR},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#endif
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen#ifdef LOG_MAIL
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"mail", LOG_MAIL},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#endif
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#ifdef LOG_NEWS
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"news", LOG_NEWS},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#endif
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#ifdef LOG_SYSLOG
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen {"syslog", LOG_SYSLOG},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#endif
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#ifdef LOG_USER
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"user", LOG_USER},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#endif
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#ifdef LOG_UUCP
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"uucp", LOG_UUCP},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#endif
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#ifdef LOG_LOCAL0
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"local0", LOG_LOCAL0},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#endif
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#ifdef LOG_LOCAL1
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"local1", LOG_LOCAL1},
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen#endif
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#ifdef LOG_LOCAL2
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"local2", LOG_LOCAL2},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#endif
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#ifdef LOG_LOCAL3
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"local3", LOG_LOCAL3},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#endif
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#ifdef LOG_LOCAL4
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"local4", LOG_LOCAL4},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#endif
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#ifdef LOG_LOCAL5
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"local5", LOG_LOCAL5},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#endif
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#ifdef LOG_LOCAL6
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"local6", LOG_LOCAL6},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#endif
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#ifdef LOG_LOCAL7
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"local7", LOG_LOCAL7},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#endif
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {NULL, -1},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe};
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#endif
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic const TRANS priorities[] = {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"emerg", APLOG_EMERG},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"alert", APLOG_ALERT},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"crit", APLOG_CRIT},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"error", APLOG_ERR},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"warn", APLOG_WARNING},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"notice", APLOG_NOTICE},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"info", APLOG_INFO},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {"debug", APLOG_DEBUG},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe {NULL, -1},
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe};
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
f039cf01b271a31e317d5b84f24cb135f1c1b6d7ndstatic int log_child(ap_pool_t *p, const char *progname,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ap_file_t **fpin)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe{
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe /* Child process code for 'ErrorLog "|..."';
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * may want a common framework for this, since I expect it will
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * be common for other foo-loggers to want this sort of thing...
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe */
f039cf01b271a31e317d5b84f24cb135f1c1b6d7nd int rc = -1;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ap_procattr_t *procattr;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ap_proc_t procnew;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
f039cf01b271a31e317d5b84f24cb135f1c1b6d7nd#ifdef SIGHUP
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe /* No concept of a child process on Win32 */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ap_signal(SIGHUP, SIG_IGN);
af84459fbf938e508fd10b01cb8d699c79083813takashi#endif /* ndef SIGHUP */
af84459fbf938e508fd10b01cb8d699c79083813takashi
2d39a41e98476f5235b7c37ce745a4aa0904b1cbrbowen if ((ap_createprocattr_init(&procattr, p) != APR_SUCCESS) ||
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen (ap_setprocattr_io(procattr,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe APR_FULL_BLOCK,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe APR_NO_PIPE,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe APR_NO_PIPE) != APR_SUCCESS)) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe /* Something bad happened, give up and go away. */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe rc = -1;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
c8c717fafa0a09ed13469a603a178921b851dd22igalic else {
c8c717fafa0a09ed13469a603a178921b851dd22igalic char **args;
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic const char *pname;
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic ap_tokenize_to_argv(progname, &args, p);
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic pname = ap_pstrdup(p, args[0]);
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic rc = ap_create_process(&procnew, pname, args, NULL, procattr, p);
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic if (rc == APR_SUCCESS) {
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic ap_note_subprocess(p, &procnew, kill_after_timeout);
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic (*fpin) = procnew.in;
7c7e501f542451bf7225b23cb299ee4228bfe15dgryzor }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe return(rc);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe}
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic void open_error_log(server_rec *s, ap_pool_t *p)
c8c717fafa0a09ed13469a603a178921b851dd22igalic{
7c7e501f542451bf7225b23cb299ee4228bfe15dgryzor const char *fname;
4bebf996eb7002ebfe897d46a0e0572390604a77nd int rc;
4bebf996eb7002ebfe897d46a0e0572390604a77nd
4bebf996eb7002ebfe897d46a0e0572390604a77nd if (*s->error_fname == '|') {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ap_file_t *dummy = NULL;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe /* This starts a new process... */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe rc = log_child (p, s->error_fname+1, &dummy);
8559a67073808d84d85bb5dd552d4247caafe709sf if (rc != APR_SUCCESS) {
8559a67073808d84d85bb5dd552d4247caafe709sf perror("ap_spawn_child");
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe "Couldn't fork child for ErrorLog process");
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe exit(1);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe s->error_log = dummy;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#ifdef HAVE_SYSLOG
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe else if (!strncasecmp(s->error_fname, "syslog", 6)) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe if ((fname = strchr(s->error_fname, ':'))) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe const TRANS *fac;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe fname++;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe for (fac = facilities; fac->t_name; fac++) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe if (!strcasecmp(fname, fac->t_name)) {
8559a67073808d84d85bb5dd552d4247caafe709sf openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID,
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen fac->t_val);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe s->error_log = NULL;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe return;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe else
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID, LOG_LOCAL7);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
8559a67073808d84d85bb5dd552d4247caafe709sf s->error_log = NULL;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#endif
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe else {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe fname = ap_server_root_relative(p, s->error_fname);
c8c717fafa0a09ed13469a603a178921b851dd22igalic /* Change to AP funcs. */
c8c717fafa0a09ed13469a603a178921b851dd22igalic if (ap_open(&s->error_log, fname, APR_APPEND |
8559a67073808d84d85bb5dd552d4247caafe709sf APR_READ | APR_WRITE | APR_CREATE, APR_OS_DEFAULT, p) != APR_SUCCESS) {
c8c717fafa0a09ed13469a603a178921b851dd22igalic perror("fopen");
c8c717fafa0a09ed13469a603a178921b851dd22igalic ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
c8c717fafa0a09ed13469a603a178921b851dd22igalic "%s: could not open error log file %s.",
8559a67073808d84d85bb5dd552d4247caafe709sf ap_server_argv0, fname);
8559a67073808d84d85bb5dd552d4247caafe709sf exit(1);
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf }
8559a67073808d84d85bb5dd552d4247caafe709sf}
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sfvoid ap_open_logs(server_rec *s_main, ap_pool_t *p)
8559a67073808d84d85bb5dd552d4247caafe709sf{
8559a67073808d84d85bb5dd552d4247caafe709sf ap_status_t rc = APR_SUCCESS;
8559a67073808d84d85bb5dd552d4247caafe709sf server_rec *virt, *q;
8559a67073808d84d85bb5dd552d4247caafe709sf int replace_stderr;
8559a67073808d84d85bb5dd552d4247caafe709sf ap_file_t *errfile = NULL;
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf open_error_log(s_main, p);
8559a67073808d84d85bb5dd552d4247caafe709sf
8559a67073808d84d85bb5dd552d4247caafe709sf replace_stderr = 1;
8559a67073808d84d85bb5dd552d4247caafe709sf if (s_main->error_log) {
8559a67073808d84d85bb5dd552d4247caafe709sf /* replace stderr with this new log */
8559a67073808d84d85bb5dd552d4247caafe709sf ap_flush(s_main->error_log);
8559a67073808d84d85bb5dd552d4247caafe709sf ap_open_stderr(&errfile, p);
8559a67073808d84d85bb5dd552d4247caafe709sf if ((rc = ap_dupfile(&errfile, s_main->error_log, NULL)) != APR_SUCCESS) {
8559a67073808d84d85bb5dd552d4247caafe709sf ap_log_error(APLOG_MARK, APLOG_CRIT, rc, s_main,
8559a67073808d84d85bb5dd552d4247caafe709sf "unable to replace stderr with error_log");
8559a67073808d84d85bb5dd552d4247caafe709sf } else {
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf replace_stderr = 0;
4bebf996eb7002ebfe897d46a0e0572390604a77nd }
4bebf996eb7002ebfe897d46a0e0572390604a77nd }
4bebf996eb7002ebfe897d46a0e0572390604a77nd /* note that stderr may still need to be replaced with something
4bebf996eb7002ebfe897d46a0e0572390604a77nd * because it points to the old error log, or back to the tty
4bebf996eb7002ebfe897d46a0e0572390604a77nd * of the submitter.
4bebf996eb7002ebfe897d46a0e0572390604a77nd */
4bebf996eb7002ebfe897d46a0e0572390604a77nd if (replace_stderr && freopen("/dev/null", "w", stderr) == NULL) {
4bebf996eb7002ebfe897d46a0e0572390604a77nd ap_log_error(APLOG_MARK, APLOG_CRIT, errno, s_main,
4bebf996eb7002ebfe897d46a0e0572390604a77nd "unable to replace stderr with /dev/null");
4bebf996eb7002ebfe897d46a0e0572390604a77nd }
4bebf996eb7002ebfe897d46a0e0572390604a77nd
4bebf996eb7002ebfe897d46a0e0572390604a77nd for (virt = s_main->next; virt; virt = virt->next) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe if (virt->error_fname) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe for (q=s_main; q != virt; q = q->next)
af84459fbf938e508fd10b01cb8d699c79083813takashi if (q->error_fname != NULL &&
af84459fbf938e508fd10b01cb8d699c79083813takashi strcmp(q->error_fname, virt->error_fname) == 0)
af84459fbf938e508fd10b01cb8d699c79083813takashi break;
af84459fbf938e508fd10b01cb8d699c79083813takashi if (q == virt)
af84459fbf938e508fd10b01cb8d699c79083813takashi open_error_log(virt, p);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe else
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe virt->error_log = q->error_log;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe else
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic virt->error_log = s_main->error_log;
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic }
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic}
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic
9534272616b71aaea50aeec4162e749a96aebd7fsfAPI_EXPORT(void) ap_error_log2stderr(server_rec *s) {
7159c12b7697fe9f5ab3a533cc6dfc3d57803053igalic ap_file_t *errfile = NULL;
7159c12b7697fe9f5ab3a533cc6dfc3d57803053igalic
7159c12b7697fe9f5ab3a533cc6dfc3d57803053igalic ap_open_stderr(&errfile, s->process->pool);
7159c12b7697fe9f5ab3a533cc6dfc3d57803053igalic if (s->error_log != NULL) {
7159c12b7697fe9f5ab3a533cc6dfc3d57803053igalic ap_dupfile(&(s->error_log), errfile, s->process->pool);
8e9c6d6438af1ccb46adaa60d34caa3ac98f3851igalic }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe}
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowenstatic void log_error_core(const char *file, int line, int level,
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen ap_status_t status, const server_rec *s,
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen const request_rec *r, ap_pool_t *pool,
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen const char *fmt, va_list args)
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen{
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen char errstr[MAX_STRING_LEN + 1]; /* + 1 to have room for '\n' */
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen size_t len;
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen ap_file_t *logf = NULL;
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen if (s == NULL) {
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen /*
4126704c4950bfd46d32ad54e3b106ac6d868a73sf * If we are doing stderr logging (startup), don't log messages that are
4126704c4950bfd46d32ad54e3b106ac6d868a73sf * above the default server log level unless it is a startup/shutdown
4126704c4950bfd46d32ad54e3b106ac6d868a73sf * notice
4126704c4950bfd46d32ad54e3b106ac6d868a73sf */
4126704c4950bfd46d32ad54e3b106ac6d868a73sf if (((level & APLOG_LEVELMASK) != APLOG_NOTICE) &&
4126704c4950bfd46d32ad54e3b106ac6d868a73sf ((level & APLOG_LEVELMASK) > DEFAULT_LOGLEVEL))
4126704c4950bfd46d32ad54e3b106ac6d868a73sf return;
4126704c4950bfd46d32ad54e3b106ac6d868a73sf ap_open_stderr(&logf, NULL);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe else if (s->error_log) {
af84459fbf938e508fd10b01cb8d699c79083813takashi /*
af84459fbf938e508fd10b01cb8d699c79083813takashi * If we are doing normal logging, don't log messages that are
af84459fbf938e508fd10b01cb8d699c79083813takashi * above the server log level unless it is a startup/shutdown notice
af84459fbf938e508fd10b01cb8d699c79083813takashi */
af84459fbf938e508fd10b01cb8d699c79083813takashi if (((level & APLOG_LEVELMASK) != APLOG_NOTICE) &&
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ((level & APLOG_LEVELMASK) > s->loglevel))
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe return;
af84459fbf938e508fd10b01cb8d699c79083813takashi logf = s->error_log;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#ifdef TPF
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe else if (tpf_child) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe /*
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * If we are doing normal logging, don't log messages that are
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * above the server log level unless it is a startup/shutdown notice
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe if (((level & APLOG_LEVELMASK) != APLOG_NOTICE) &&
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ((level & APLOG_LEVELMASK) > s->loglevel))
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe return;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe logf = stderr;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe }
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#endif /* TPF */
c8c717fafa0a09ed13469a603a178921b851dd22igalic else {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe /*
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * If we are doing syslog logging, don't log messages that are
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * above the server log level (including a startup/shutdown notice)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe if ((level & APLOG_LEVELMASK) > s->loglevel)
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe return;
c8c717fafa0a09ed13469a603a178921b851dd22igalic logf = NULL;
c8c717fafa0a09ed13469a603a178921b851dd22igalic }
c8c717fafa0a09ed13469a603a178921b851dd22igalic
c8c717fafa0a09ed13469a603a178921b851dd22igalic if (logf && ((level & APLOG_STARTUP) != APLOG_STARTUP)) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe errstr[0] = '[';
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ap_ctime(errstr + 1, ap_now());
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe errstr[1 + AP_CTIME_LEN - 1] = ']';
7e9c796f2dc0dba993a817b3a58cfd56b4e511edwrowe errstr[1 + AP_CTIME_LEN ] = ' ';
7e9c796f2dc0dba993a817b3a58cfd56b4e511edwrowe len = 1 + AP_CTIME_LEN + 1;
7e9c796f2dc0dba993a817b3a58cfd56b4e511edwrowe } else {
7e9c796f2dc0dba993a817b3a58cfd56b4e511edwrowe len = 0;
7e9c796f2dc0dba993a817b3a58cfd56b4e511edwrowe }
c8c717fafa0a09ed13469a603a178921b851dd22igalic
c8c717fafa0a09ed13469a603a178921b851dd22igalic if ((level & APLOG_STARTUP) != APLOG_STARTUP) {
7e9c796f2dc0dba993a817b3a58cfd56b4e511edwrowe len += ap_snprintf(errstr + len, MAX_STRING_LEN - len,
7e9c796f2dc0dba993a817b3a58cfd56b4e511edwrowe "[%s] ", priorities[level & APLOG_LEVELMASK].t_name);
c8c717fafa0a09ed13469a603a178921b851dd22igalic }
c8c717fafa0a09ed13469a603a178921b851dd22igalic#ifndef TPF
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe if (file && (level & APLOG_LEVELMASK) == APLOG_DEBUG) {
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe#ifdef _OSD_POSIX
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe char tmp[256];
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe char *e = strrchr(file, '/');
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe /* In OSD/POSIX, the compiler returns for __FILE__
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * a string like: __FILE__="*POSIX(/usr/include/stdio.h)"
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * (it even returns an absolute path for sources in
af84459fbf938e508fd10b01cb8d699c79083813takashi * the current directory). Here we try to strip this
af84459fbf938e508fd10b01cb8d699c79083813takashi * down to the basename.
af84459fbf938e508fd10b01cb8d699c79083813takashi */
af84459fbf938e508fd10b01cb8d699c79083813takashi if (e != NULL && e[1] != '\0') {
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung ap_snprintf(tmp, sizeof(tmp), "%s", &e[1]);
af84459fbf938e508fd10b01cb8d699c79083813takashi e = &tmp[strlen(tmp)-1];
5effc8b39fae5cd169d17f342bfc265705840014rbowen if (*e == ')')
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd *e = '\0';
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd file = tmp;
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd }
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd#endif /*_OSD_POSIX*/
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd len += ap_snprintf(errstr + len, MAX_STRING_LEN - len,
af84459fbf938e508fd10b01cb8d699c79083813takashi "%s(%d): ", file, line);
}
#endif /* TPF */
if (r && r->connection) {
/* XXX: TODO: add a method of selecting whether logged client
* addresses are in dotted quad or resolved form... dotted
* quad is the most secure, which is why I'm implementing it
* first. -djg
*/
len += ap_snprintf(errstr + len, MAX_STRING_LEN - len,
"[client %s] ", r->connection->remote_ip);
}
if (!(level & APLOG_NOERRNO)
&& (status != 0)) {
char buf[100];
len += ap_snprintf(errstr + len, MAX_STRING_LEN - len,
"(%d)%s: ", status, ap_strerror(status, buf, sizeof(buf)));
}
len += ap_vsnprintf(errstr + len, MAX_STRING_LEN - len, fmt, args);
/* NULL if we are logging to syslog */
if (logf) {
/* We know that we have one more character of space available because
* the array is sized that way */
/* ap_assert(len < MAX_STRING_LEN) */
errstr[len++] = '\n';
errstr[len] = '\0';
ap_puts(errstr, logf);
ap_flush(logf);
}
#ifdef HAVE_SYSLOG
else {
syslog(level & APLOG_LEVELMASK, "%s", errstr);
}
#endif
}
API_EXPORT(void) ap_log_error(const char *file, int line, int level,
ap_status_t status, const server_rec *s,
const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
log_error_core(file, line, level, status, s, NULL, NULL, fmt, args);
va_end(args);
}
API_EXPORT(void) ap_log_perror(const char *file, int line, int level,
ap_status_t status, ap_pool_t *p,
const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
log_error_core(file, line, level, status, NULL, NULL, p, fmt, args);
va_end(args);
}
API_EXPORT(void) ap_log_rerror(const char *file, int line, int level,
ap_status_t status, const request_rec *r,
const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
log_error_core(file, line, level, status, r->server, r, NULL, fmt, args);
/*
* IF the error level is 'warning' or more severe,
* AND there isn't already error text associated with this request,
* THEN make the message text available to ErrorDocument and
* other error processors. This can be disabled by stuffing
* something, even an empty string, into the "error-notes" cell
* before calling this routine.
*/
va_end(args);
va_start(args,fmt);
if (((level & APLOG_LEVELMASK) <= APLOG_WARNING)
&& (ap_table_get(r->notes, "error-notes") == NULL)) {
ap_table_setn(r->notes, "error-notes",
ap_escape_html(r->pool, ap_pvsprintf(r->pool, fmt,
args)));
}
va_end(args);
}
void ap_log_pid(ap_pool_t *p, const char *fname)
{
ap_file_t *pid_file = NULL;
ap_finfo_t finfo;
static pid_t saved_pid = -1;
pid_t mypid;
#ifndef WIN32
mode_t u;
#endif
if (!fname)
return;
fname = ap_server_root_relative(p, fname);
mypid = getpid();
if (mypid != saved_pid && ap_stat(&finfo, fname, p) == APR_SUCCESS) {
/* WINCH and HUP call this on each restart.
* Only warn on first time through for this pid.
*
* XXX: Could just write first time through too, although
* that may screw up scripts written to do something
* based on the last modification time of the pid file.
*/
ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, NULL,
ap_psprintf(p,
"pid file %s overwritten -- Unclean shutdown of previous Apache run?",
fname)
);
}
#ifndef WIN32
u = umask(022);
(void) umask(u | 022);
#endif
if (ap_open(&pid_file, fname, APR_WRITE | APR_CREATE | APR_TRUNCATE,
APR_OS_DEFAULT, p) != APR_SUCCESS) {
perror("fopen");
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
"%s: could not log pid to file %s",
ap_server_argv0, fname);
exit(1);
}
#ifndef WIN32
(void) umask(u);
#endif
ap_fprintf(pid_file, "%ld\n", (long)mypid);
ap_close(pid_file);
saved_pid = mypid;
}
API_EXPORT(void) ap_log_error_old(const char *err, server_rec *s)
{
ap_log_error(APLOG_MARK, APLOG_ERR, errno, s, "%s", err);
}
API_EXPORT(void) ap_log_unixerr(const char *routine, const char *file,
const char *msg, server_rec *s)
{
ap_log_error(file, 0, APLOG_ERR, errno, s, "%s", msg);
}
API_EXPORT(void) ap_log_printf(const server_rec *s, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
log_error_core(APLOG_MARK, APLOG_ERR, errno, s, NULL, NULL, fmt, args);
va_end(args);
}
API_EXPORT(void) ap_log_reason(const char *reason, const char *file, request_rec *r)
{
ap_log_error(APLOG_MARK, APLOG_ERR, errno, r->server,
"access to %s failed for %s, reason: %s",
file,
ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_NAME),
reason);
}
API_EXPORT(void) ap_log_assert(const char *szExp, const char *szFile, int nLine)
{
char time_str[AP_CTIME_LEN];
ap_ctime(time_str, ap_now());
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
"[%s] file %s, line %d, assertion \"%s\" failed",
time_str, szFile, nLine, szExp);
#ifndef WIN32
/* unix assert does an abort leading to a core dump */
abort();
#else
exit(1);
#endif
}
/* piped log support */
#ifdef HAVE_RELIABLE_PIPED_LOGS
/* forward declaration */
static void piped_log_maintenance(int reason, void *data, ap_wait_t status);
static int piped_log_spawn(piped_log *pl)
{
int rc;
ap_procattr_t *procattr;
ap_proc_t procnew;
#ifdef SIGHUP
ap_signal(SIGHUP, SIG_IGN);
#endif
if ((ap_createprocattr_init(&procattr, pl->p) != APR_SUCCESS) ||
(ap_setprocattr_childin(procattr, ap_piped_log_read_fd(pl),
ap_piped_log_write_fd(pl)) != APR_SUCCESS)) {
/* Something bad happened, give up and go away. */
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
"piped_log_spawn: unable to exec '%s': %s",
pl->program, strerror (errno));
rc = -1;
}
else {
char **args;
const char *pname;
ap_tokenize_to_argv(pl->program, &args, pl->p);
pname = ap_pstrdup(pl->p, args[0]);
rc = ap_create_process(&procnew, pname, args, NULL, procattr, pl->p);
if (rc == APR_SUCCESS) {
/* pjr - This no longer happens inside the child, */
/* I am assuming that if ap_create_process was */
/* successful that the child is running. */
RAISE_SIGSTOP(PIPED_LOG_SPAWN);
pl->pid = &procnew;
ap_register_other_child(&procnew, piped_log_maintenance, pl,
ap_piped_log_write_fd(pl), pl->p);
}
}
return 0;
}
static void piped_log_maintenance(int reason, void *data, ap_wait_t status)
{
piped_log *pl = data;
switch (reason) {
case APR_OC_REASON_DEATH:
pl->pid = NULL;
ap_unregister_other_child(pl);
if (pl->program == NULL) {
/* during a restart */
break;
}
break;
case APR_OC_REASON_LOST:
pl->pid = NULL;
ap_unregister_other_child(pl);
if (pl->program == NULL) {
/* during a restart */
break;
}
if (piped_log_spawn(pl) != APR_SUCCESS) {
/* what can we do? This could be the error log we're having
* problems opening up... */
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
"piped_log_maintenance: unable to respawn '%s': %s",
pl->program, strerror(errno));
}
break;
case APR_OC_REASON_UNWRITABLE:
if (pl->pid != NULL) {
ap_kill(pl->pid, SIGTERM);
}
break;
case APR_OC_REASON_RESTART:
pl->program = NULL;
if (pl->pid != NULL) {
ap_kill(pl->pid, SIGTERM);
}
break;
case APR_OC_REASON_UNREGISTER:
break;
}
}
static ap_status_t piped_log_cleanup(void *data)
{
piped_log *pl = data;
if (pl->pid != NULL) {
ap_kill(pl->pid, SIGTERM);
}
ap_unregister_other_child(pl);
ap_close(ap_piped_log_read_fd(pl));
ap_close(ap_piped_log_write_fd(pl));
return APR_SUCCESS;
}
static ap_status_t piped_log_cleanup_for_exec(void *data)
{
piped_log *pl = data;
ap_close(ap_piped_log_read_fd(pl));
ap_close(ap_piped_log_write_fd(pl));
return APR_SUCCESS;
}
API_EXPORT(piped_log *) ap_open_piped_log(ap_pool_t *p, const char *program)
{
piped_log *pl;
pl = ap_palloc(p, sizeof (*pl));
pl->p = p;
pl->program = ap_pstrdup(p, program);
pl->pid = NULL;
if (ap_create_pipe(&ap_piped_log_read_fd(pl), &ap_piped_log_write_fd(pl), p) != APR_SUCCESS) {
int save_errno = errno;
errno = save_errno;
return NULL;
}
ap_block_pipe(ap_piped_log_read_fd(pl));
ap_block_pipe(ap_piped_log_write_fd(pl));
ap_register_cleanup(p, pl, piped_log_cleanup, piped_log_cleanup_for_exec);
if (piped_log_spawn(pl) == -1) {
int save_errno = errno;
ap_kill_cleanup(p, pl, piped_log_cleanup);
ap_close(ap_piped_log_read_fd(pl));
ap_close(ap_piped_log_write_fd(pl));
errno = save_errno;
return NULL;
}
return pl;
}
#else
static ap_status_t piped_log_cleanup(void *data)
{
piped_log *pl = data;
ap_close(ap_piped_log_write_fd(pl));
return APR_SUCCESS;
}
API_EXPORT(piped_log *) ap_open_piped_log(ap_pool_t *p, const char *program)
{
piped_log *pl;
ap_file_t *dummy = NULL;
int rc;
rc = log_child(p, program, &dummy);
if (rc != APR_SUCCESS) {
perror("ap_spawn_child");
ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
"Couldn't fork child for piped log process");
exit (1);
}
pl = ap_palloc(p, sizeof (*pl));
pl->p = p;
ap_piped_log_read_fd(pl) = NULL;
ap_piped_log_write_fd(pl) = dummy;
ap_register_cleanup(p, pl, piped_log_cleanup, piped_log_cleanup);
return pl;
}
#endif
API_EXPORT(void) ap_close_piped_log(piped_log *pl)
{
ap_run_cleanup(pl->p, pl, piped_log_cleanup);
}