log.c revision ab5581cc78e9d865b0a6ab1404c53347b3276968
/* ====================================================================
* Copyright (c) 1995-1999 The Apache Group. 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. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* 4. The names "Apache Server" and "Apache Group" 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 names without prior written
* permission of the Apache Group.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``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 GROUP 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 Group and was originally based
* on public domain software written at the National Center for
* Supercomputing Applications, University of Illinois, Urbana-Champaign.
* For more information on the Apache Group and the Apache HTTP server
* project, please see <http://www.apache.org/>.
*
*/
/*
* http_log.c: Dealing with the logs and errors
*
* Rob McCool
*
*/
#define CORE_PRIVATE
#include "apr_lib.h"
#include "apr_portable.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"
#include "http_main.h"
#include <stdarg.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},
};
{
/* 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...
*/
int child_pid = 0;
#ifdef SIGHUP
/* No concept of a child process on Win32 */
#endif /* ndef SIGHUP */
#if defined(WIN32)
return(child_pid);
/* For OS/2 we need to use a '/' and spawn the child rather than exec as
* we haven't forked */
return(child_pid);
#else
#endif
exit(1);
/* NOT REACHED */
return(child_pid);
}
{
const char *fname;
if (*s->error_fname == '|') {
int dummyno;
#ifdef TPF
#else
#endif /* TPF */
perror("ap_spawn_child");
exit(1);
}
}
#ifdef HAVE_SYSLOG
fname++;
return;
}
}
}
else
}
#endif
else {
/* Change to AP funcs. */
perror("fopen");
exit(1);
}
}
}
{
server_rec *virt, *q;
int replace_stderr;
int errfile;
open_error_log(s_main, p);
replace_stderr = 1;
/* replace stderr with this new log */
"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)
open_error_log(virt, p);
else
}
else
}
}
int errfile;
&& errfile != STDERR_FILENO)
}
const server_rec *s, const request_rec *r,
{
char errstr[MAX_STRING_LEN];
/* change to AP errno funcs. */
int save_errno = errno;
int errfileno = STDERR_FILENO;
if (s == NULL) {
/*
* If we are doing stderr logging (startup), don't log messages that are
* notice
*/
return;
}
else if (s->error_log) {
/*
* If we are doing normal logging, don't log messages that are
*/
return;
}
#ifdef TPF
else if (tpf_child) {
/*
* If we are doing normal logging, don't log messages that are
*/
return;
}
#endif /* TPF */
else {
/*
* If we are doing syslog logging, don't log messages that are
*/
return;
}
if (logf) {
} 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) {
/* 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 (!(level & APLOG_NOERRNO)
&& (save_errno != 0)
#ifdef WIN32
&& !(level & APLOG_WIN32ERROR)
#endif
) {
/* ZZZ use AP funcs to set the errno and the error string. */
}
#ifdef WIN32
if (level & APLOG_WIN32ERROR) {
int nChars;
int nErrorCode;
nErrorCode = GetLastError();
"(%d)", nErrorCode);
NULL,
);
if (nChars == 0) {
/* Um, error occurred, but we can't recurse to log it again
* (and it would probably only fail anyway), so lets just
* log the numeric value.
*/
nErrorCode = GetLastError();
"(FormatMessage failed with code %d): ",
}
else {
/* FormatMessage put the message in the buffer, but it may
* have appended a newline (\r\n). So remove it and use
* ": " instead like the Unix errors. The error may also
* end with a . before the return - if so, trash it.
*/
len--;
}
}
}
#endif
/* NULL if we are logging to syslog */
if (logf) {
/* ZZZ let's just use AP funcs to Write to the error log. If failure,
can we output a message to the console??? */
}
#ifdef HAVE_SYSLOG
else {
}
#endif
}
const server_rec *s, const char *fmt, ...)
{
}
const request_rec *r, const char *fmt, ...)
{
/*
* 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.
*/
}
}
{
if (!fname)
return;
/* 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_psprintf(p,
"pid file %s overwritten -- Unclean shutdown of previous Apache run?",
);
}
perror("fopen");
exit(1);
}
}
{
}
const char *msg, server_rec *s)
{
}
{
}
{
"access to %s failed for %s, reason: %s",
file,
reason);
}
{
/* Use AP funcs to output message and abort program. */
#ifndef WIN32
/* unix assert does an abort leading to a core dump */
abort();
#else
exit(1);
#endif
}
/* piped log support */
#ifndef NO_RELIABLE_PIPED_LOGS
/* forward declaration */
{
int pid;
if (pid == 0) {
/* XXX: this needs porting to OS2 and WIN32 */
/* XXX: need to check what open fds the logger is actually passed,
* XXX: and CGIs for that matter ... cleanup_for_exec *should*
* XXX: close all the relevant stuff, but hey, it could be broken. */
/* we're now in the child */
"piped_log_spawn: unable to exec %s -c '%s': %s\n",
exit(1);
}
if (pid == -1) {
return -1;
}
return 0;
}
{
switch (reason) {
case OC_REASON_DEATH:
case OC_REASON_LOST:
/* during a restart */
break;
}
/* what can we do? This could be the error log we're having
* problems opening up... */
"piped_log_maintenance: unable to respawn '%s': %s\n",
}
break;
case OC_REASON_UNWRITABLE:
}
break;
case OC_REASON_RESTART:
}
break;
case OC_REASON_UNREGISTER:
break;
}
}
static void piped_log_cleanup(void *data)
{
}
}
static void piped_log_cleanup_for_exec(void *data)
{
}
{
pl->p = p;
int save_errno = errno;
errno = save_errno;
return NULL;
}
int save_errno = errno;
errno = save_errno;
return NULL;
}
return pl;
}
{
}
#else
{
/* Child process code for 'TransferLog "|..."';
* may want a common framework for this, since I expect it will
* be common for other foo-loggers to want this sort of thing...
*/
int child_pid = 1;
#ifdef SIGHUP
#endif
#if defined(WIN32)
return(child_pid);
/* For OS/2 we need to use a '/' and spawn the child rather than exec as
* we haven't forked */
return(child_pid);
#else
#endif
perror("exec");
return(child_pid);
}
{
int dummyno;
#ifdef TPF
#else
#endif /* TPF */
perror("ap_spawn_child");
exit (1);
}
pl->p = p;
return pl;
}
{
}
#endif