log.c revision f5d913e797a32274e105222016bd67617bf224a0
af84459fbf938e508fd10b01cb8d699c79083813takashi/* ====================================================================
af84459fbf938e508fd10b01cb8d699c79083813takashi * The Apache Software License, Version 1.1
af84459fbf938e508fd10b01cb8d699c79083813takashi * Copyright (c) 2000 The Apache Software Foundation. All rights
af84459fbf938e508fd10b01cb8d699c79083813takashi * reserved.
af84459fbf938e508fd10b01cb8d699c79083813takashi * Redistribution and use in source and binary forms, with or without
fed47023e9be04c612b5f6d4a5ee2b8e7c587181rbowen * modification, are permitted provided that the following conditions
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * 1. Redistributions of source code must retain the above copyright
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * notice, this list of conditions and the following disclaimer.
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.
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.
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 * 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.
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 * 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
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.
3c13a815670b54d1c17bf02954f7d2b066cde95cnd * http_log.c: Dealing with the logs and errors
af84459fbf938e508fd10b01cb8d699c79083813takashi * Rob McCool
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowetypedef struct {
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 /* No concept of a child process on Win32 */
af84459fbf938e508fd10b01cb8d699c79083813takashi#endif /* ndef SIGHUP */
2d39a41e98476f5235b7c37ce745a4aa0904b1cbrbowen if ((ap_createprocattr_init(&procattr, p) != APR_SUCCESS) ||
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe /* Something bad happened, give up and go away. */
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic const char *pname;
b7f8d802ecaed65eada1fc31472d06d8460d5528igalic rc = ap_create_process(&procnew, pname, args, NULL, procattr, p);
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowestatic void open_error_log(server_rec *s, ap_pool_t *p)
7c7e501f542451bf7225b23cb299ee4228bfe15dgryzor const char *fname;
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe /* This starts a new process... */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe "Couldn't fork child for ErrorLog process");
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID, LOG_LOCAL7);
c8c717fafa0a09ed13469a603a178921b851dd22igalic /* Change to AP funcs. */
8559a67073808d84d85bb5dd552d4247caafe709sf APR_READ | APR_WRITE | APR_CREATE, APR_OS_DEFAULT, p) != APR_SUCCESS) {
c8c717fafa0a09ed13469a603a178921b851dd22igalic ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
c8c717fafa0a09ed13469a603a178921b851dd22igalic "%s: could not open error log file %s.",
8559a67073808d84d85bb5dd552d4247caafe709sf /* replace stderr with this new log */
8559a67073808d84d85bb5dd552d4247caafe709sf if ((rc = ap_dupfile(&errfile, s_main->error_log, NULL)) != APR_SUCCESS) {
8559a67073808d84d85bb5dd552d4247caafe709sf "unable to replace stderr with error_log");
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 if (replace_stderr && freopen("/dev/null", "w", stderr) == NULL) {
4bebf996eb7002ebfe897d46a0e0572390604a77nd "unable to replace stderr with /dev/null");
7159c12b7697fe9f5ab3a533cc6dfc3d57803053igalic ap_dupfile(&(s->error_log), errfile, s->process->pool);
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowenstatic void log_error_core(const char *file, int line, int level,
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen char errstr[MAX_STRING_LEN + 1]; /* + 1 to have room for '\n' */
1d45c1463a8bc69bab1c07a4729269ec7333e713rbowen if (s == NULL) {
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
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe else if (s->error_log) {
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
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#endif /* TPF */
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * If we are doing syslog logging, don't log messages that are
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe * above the server log level (including a startup/shutdown notice)
c8c717fafa0a09ed13469a603a178921b851dd22igalic if (logf && ((level & APLOG_STARTUP) != APLOG_STARTUP)) {
7e9c796f2dc0dba993a817b3a58cfd56b4e511edwrowe len += ap_snprintf(errstr + len, MAX_STRING_LEN - len,
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe if (file && (level & APLOG_LEVELMASK) == APLOG_DEBUG) {
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.
5effc8b39fae5cd169d17f342bfc265705840014rbowen if (*e == ')')
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd *e = '\0';
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd#endif /*_OSD_POSIX*/
if (r && r->connection) {
&& (status != 0)) {
if (logf) {
#ifdef HAVE_SYSLOG
const char *fmt, ...)
const char *fmt, ...)
const char *fmt, ...)
args)));
#ifndef WIN32
mode_t u;
if (!fname)
ap_psprintf(p,
#ifndef WIN32
#ifndef WIN32
(void) umask(u);
file,
reason);
#ifndef WIN32
abort();
#ifdef HAVE_RELIABLE_PIPED_LOGS
int rc;
#ifdef SIGHUP
char **args;
const char *pname;
switch (reason) {
case APR_OC_REASON_DEATH:
case APR_OC_REASON_LOST:
case APR_OC_REASON_UNWRITABLE:
case APR_OC_REASON_RESTART:
case APR_OC_REASON_UNREGISTER:
return APR_SUCCESS;
return APR_SUCCESS;
pl->p = p;
return NULL;
return NULL;
return pl;
return APR_SUCCESS;
int rc;
pl->p = p;
return pl;