log.c revision 33bdcae1f7a1a65e351dda2a766a0cf28b1e695d
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*
* Portions of this software are based upon public domain software
* originally written at the National Center for Supercomputing Applications,
* University of Illinois, Urbana-Champaign.
*/
/*
* http_log.c: Dealing with the logs and errors
*
* Rob McCool
*
*/
#include "apr.h"
#include "apr_general.h" /* for signal stuff */
#include "apr_strings.h"
#include "apr_errno.h"
#include "apr_thread_proc.h"
#include "apr_lib.h"
#include "apr_signal.h"
#define APR_WANT_STDIO
#define APR_WANT_STRFUNC
#include "apr_want.h"
#include <stdarg.h>
#endif
#include <unistd.h>
#endif
#define CORE_PRIVATE
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"
#include "http_main.h"
#include "util_time.h"
typedef struct {
char *t_name;
int t_val;
} TRANS;
)
#ifdef HAVE_SYSLOG
static const TRANS facilities[] = {
{"auth", LOG_AUTH},
#ifdef LOG_AUTHPRIV
{"authpriv",LOG_AUTHPRIV},
#endif
#ifdef LOG_CRON
{"cron", LOG_CRON},
#endif
#ifdef LOG_DAEMON
{"daemon", LOG_DAEMON},
#endif
#ifdef LOG_FTP
{"ftp", LOG_FTP},
#endif
#ifdef LOG_KERN
{"kern", LOG_KERN},
#endif
#ifdef LOG_LPR
{"lpr", LOG_LPR},
#endif
#ifdef LOG_MAIL
{"mail", LOG_MAIL},
#endif
#ifdef LOG_NEWS
{"news", LOG_NEWS},
#endif
#ifdef LOG_SYSLOG
{"syslog", LOG_SYSLOG},
#endif
#ifdef LOG_USER
{"user", LOG_USER},
#endif
#ifdef LOG_UUCP
{"uucp", LOG_UUCP},
#endif
#ifdef LOG_LOCAL0
{"local0", LOG_LOCAL0},
#endif
#ifdef LOG_LOCAL1
{"local1", LOG_LOCAL1},
#endif
#ifdef LOG_LOCAL2
{"local2", LOG_LOCAL2},
#endif
#ifdef LOG_LOCAL3
{"local3", LOG_LOCAL3},
#endif
#ifdef LOG_LOCAL4
{"local4", LOG_LOCAL4},
#endif
#ifdef LOG_LOCAL5
{"local5", LOG_LOCAL5},
#endif
#ifdef LOG_LOCAL6
{"local6", LOG_LOCAL6},
#endif
#ifdef LOG_LOCAL7
{"local7", LOG_LOCAL7},
#endif
{NULL, -1},
};
#endif
static const TRANS priorities[] = {
{"emerg", APLOG_EMERG},
{"alert", APLOG_ALERT},
{"crit", APLOG_CRIT},
{"error", APLOG_ERR},
{"warn", APLOG_WARNING},
{"notice", APLOG_NOTICE},
{"info", APLOG_INFO},
{"debug", APLOG_DEBUG},
{NULL, -1},
};
{
}
const char *fname)
{
if (!filename) {
fname);
return APR_EBADPATH;
}
APR_OS_DEFAULT, p)) != APR_SUCCESS) {
"%s: could not open error log file %s.",
return rc;
}
}
}
if (rc != APR_SUCCESS) {
"unable to replace stderr with error_log");
}
return rc;
}
apr_file_t **fpin)
{
/* Child process code for 'ErrorLog "|..."';
* may want a common framework for this, since I expect it will
* be common for other foo-loggers to want this sort of thing...
*/
APR_NO_PIPE)) == APR_SUCCESS)) {
char **args;
const char *pname;
if (rc == APR_SUCCESS) {
}
}
return rc;
}
{
const char *fname;
int rc;
if (*s->error_fname == '|') {
/* This starts a new process... */
if (rc != APR_SUCCESS) {
"Couldn't start ErrorLog process");
return DONE;
}
}
#ifdef HAVE_SYSLOG
fname++;
return OK;
}
}
}
else {
}
}
#endif
else {
if (!fname) {
"%s: Invalid error log path %s.",
ap_server_argv0, s->error_fname);
return DONE;
}
APR_OS_DEFAULT, p)) != APR_SUCCESS) {
"%s: could not open error log file %s.",
return DONE;
}
}
return OK;
}
{
server_rec *virt, *q;
int replace_stderr;
return DONE;
}
replace_stderr = 1;
/* replace stderr with this new log */
}
if (rc != APR_SUCCESS) {
"unable to replace stderr with error_log");
}
else {
replace_stderr = 0;
}
}
/* note that stderr may still need to be replaced with something
* because it points to the old error log, or back to the tty
* of the submitter.
*/
}
if (virt->error_fname) {
if (q->error_fname != NULL
break;
}
}
if (q == virt) {
return DONE;
}
}
else {
}
}
else {
}
}
return OK;
}
}
}
{
char errstr[MAX_STRING_LEN];
const char *referer;
if (s == NULL) {
/*
* If we are doing stderr logging (startup), don't log messages that are
* notice
*/
if ((level_and_mask != APLOG_NOTICE)
&& (level_and_mask > ap_default_loglevel)) {
return;
}
logf = stderr_log;
}
else if (s->error_log) {
/*
* If we are doing normal logging, don't log messages that are
*/
if ((level_and_mask != APLOG_NOTICE)
&& (level_and_mask > s->loglevel)) {
return;
}
}
#ifdef TPF
else if (tpf_child) {
/*
* If we are doing normal logging, don't log messages that are
*/
if ((level_and_mask != APLOG_NOTICE)
&& (level_and_mask > s->loglevel)) {
return;
}
}
#endif /* TPF */
else {
/*
* If we are doing syslog logging, don't log messages that are
*/
if (level_and_mask > s->loglevel) {
return;
}
}
errstr[0] = '[';
} else {
len = 0;
}
}
#ifndef TPF
#ifdef _OSD_POSIX
char tmp[256];
* (it even returns an absolute path for sources in
* the current directory). Here we try to strip this
* down to the basename.
*/
if (*e == ')') {
*e = '\0';
}
}
#endif /*_OSD_POSIX*/
}
#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
*/
}
if (status != 0) {
if (status < APR_OS_START_EAIERR) {
"(%d)", status);
}
else if (status < APR_OS_START_SYSERR) {
}
}
else {
}
}
}
", referer: %s", referer);
}
/* NULL if we are logging to syslog */
if (logf) {
/* Truncate for the terminator (as apr_snprintf does) */
}
}
#ifdef HAVE_SYSLOG
else {
}
#endif
}
const char *fmt, ...)
{
}
const char *fmt, ...)
{
}
const char *fmt, ...)
{
/*
* IF APLOG_TOCLIENT is set,
* AND 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.
*/
if ((level & APLOG_TOCLIENT)
args)));
}
}
{
const char *fname;
if (!filename) {
return;
}
if (!fname) {
return;
}
/* AP_SIG_GRACEFUL 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.
*/
apr_psprintf(p, "pid file %s overwritten -- Unclean "
"shutdown of previous Apache run?",
fname));
}
!= APR_SUCCESS) {
"could not create %s", fname);
"%s: could not log pid to file %s",
exit(1);
}
}
{
const char *fname;
if (!filename) {
return APR_EGENERAL;
}
if (!fname) {
return APR_EGENERAL;
}
if (rv != APR_SUCCESS) {
return rv;
}
/* Ensure null-termination, so that strtol doesn't go crazy. */
return rv;
}
/* If we fill the buffer, we're probably reading a corrupt pid file.
* To be nice, let's also ensure the first char is a digit. */
return APR_EGENERAL;
}
return APR_SUCCESS;
}
int nLine)
{
char time_str[APR_CTIME_LEN];
"[%s] file %s, line %d, assertion \"%s\" failed",
#if defined(WIN32)
DebugBreak();
#else
/* unix assert does an abort leading to a core dump */
abort();
#endif
}
/* piped log support */
#ifdef AP_HAVE_RELIABLE_PIPED_LOGS
/* forward declaration */
{
int rc;
!= APR_SUCCESS)) {
char buf[120];
/* Something bad happened, give up and go away. */
"piped_log_spawn: unable to setup child process '%s': %s",
rc = -1;
}
else {
char **args;
const char *pname;
if (rc == APR_SUCCESS) {
/* pjr - This no longer happens inside the child, */
/* I am assuming that if apr_proc_create was */
/* successful that the child is running. */
}
}
return 0;
}
{
switch (reason) {
case APR_OC_REASON_DEATH:
/* during a restart */
break;
}
break;
case APR_OC_REASON_LOST:
/* during a restart */
break;
}
/* what can we do? This could be the error log we're having
* problems opening up... */
char buf[120];
"piped_log_maintenance: unable to respawn '%s': %s",
}
break;
case APR_OC_REASON_UNWRITABLE:
/* We should not kill off the pipe here, since it may only be full.
* If it really is locked, we should kill it off manually. */
break;
case APR_OC_REASON_RESTART:
}
break;
case APR_OC_REASON_UNREGISTER:
break;
}
}
{
return APR_SUCCESS;
}
{
}
return piped_log_cleanup_for_exec(data);
}
{
pl->p = p;
return NULL;
}
int save_errno = errno;
errno = save_errno;
return NULL;
}
return pl;
}
#else /* !AP_HAVE_RELIABLE_PIPED_LOGS */
{
return APR_SUCCESS;
}
{
int rc;
if (rc != APR_SUCCESS) {
"Couldn't start piped log process");
return NULL;
}
pl->p = p;
return pl;
}
#endif
{
}