logging.c revision 1676408640d8283c9f17eec0b183e1302ea7fd70
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996-1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if !defined(LINT) && !defined(CODECENTER)
#endif /* not lint */
#include "port_before.h"
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <syslog.h>
#include <errno.h>
#include <time.h>
#include <unistd.h>
#include <isc/assertions.h>
#include <isc/memcluster.h>
#include "port_after.h"
#ifdef VSPRINTF_CHAR
#else
#endif
#include "logging_p.h"
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
static const char *level_text[] = {
"info: ", "notice: ", "warning: ", "error: ", "critical: "
};
static void
unsigned int ver;
if (ver < 1)
return;
if (ver > LOG_MAX_VERSIONS)
/*
* Need to have room for '.nn' (XXX assumes LOG_MAX_VERSIONS < 100)
*/
return;
}
}
FILE *
int regular;
return (NULL);
}
/*
* Don't open already open streams
*/
"log_open_stream: stat of %s failed: %s",
return (NULL);
}
regular = 1;
} else
if (!regular) {
"log_open_stream: want versions but %s isn't a regular file",
return (NULL);
}
}
if (regular) {
} else {
"log_open_stream: want truncation but %s isn't a regular file",
return (NULL);
}
}
if (fd < 0) {
return (NULL);
}
return (NULL);
}
return (stream);
}
int
return (0);
}
return (-1);
return (0);
}
void
int i;
for (i = 0; i < lc->num_categories; i++)
}
FILE *
return (NULL);
}
}
char *
return (NULL);
}
}
int
int debugging, chan_level;
/*
* If not debugging, short circuit debugging messages very early.
*/
return (0);
return (0);
/* Some channels only log when debugging is on. */
return (0);
/* Some channels use the global level. */
} else
if (level > chan_level)
return (0);
return (1);
}
int
int debugging;
/*
* If not debugging, short circuit debugging messages very early.
*/
return (0);
category = 0; /* use default */
category = 0;
}
return (1);
}
return (0);
}
void
int original_category;
#ifdef HAVE_TIME_R
#endif
const char *category_name;
const char *level_str;
char time_buf[256];
char level_buf[256];
/*
* If not debugging, short circuit debugging messages very early.
*/
return;
category = 0; /* use default */
category = 0;
}
/*
* Get the current time and format it.
*/
time_buf[0]='\0';
} else {
#ifdef HAVE_TIME_R
#else
#endif
}
}
/*
* Make a string representation of the current category and level
*/
else
category_name = "";
if (level >= log_critical) {
if (level >= 0) {
} else
} else {
}
/*
* Write the message to channels.
*/
continue;
if (!did_vsprintf) {
"memory overrun in log_vwrite()");
exit(1);
}
did_vsprintf = 1;
}
case log_syslog:
if (level >= log_critical)
else
pri = -log_critical;
"%s%s%s%s",
category_name : "",
level_str : "",
break;
case log_file:
break;
}
long pos;
if (pos >= 0 &&
(unsigned long)pos >
/*
* try to roll over the log files,
* ignoring all all return codes
* except the open (we don't want
* to write any more anyway)
*/
break;
}
}
category_name : "",
level_str : "",
break;
case log_null:
break;
default:
"unknown channel type in log_vwrite()");
}
}
}
void
}
/*
* Functions to create, set, or destroy contexts
*/
int
return (-1);
}
return (-1);
}
num_categories * sizeof (log_channel_list));
return (0);
}
void
int i;
for (i = 0; i < lc->num_categories; i++)
(void)log_free_channel(chan);
}
}
int
return (-1);
}
return(-1);
}
chan->references++;
return (0);
}
int
int found = 0;
return (-1);
}
else
/*
* We just set found instead of returning because
* the channel might be on the list more than once.
*/
found = 1;
} else
}
if (!found) {
return (-1);
}
return (0);
}
int
return (-1);
}
switch (option) {
case LOG_OPTION_DEBUG:
if (value)
else
break;
case LOG_OPTION_LEVEL:
break;
default:
return (-1);
}
return (0);
}
int
return (-1);
}
return (1);
return (0);
}
return (NULL);
}
chan->references = 0;
return (chan);
}
unsigned long max_size) {
return (NULL);
}
/*
* Quantize length to a multiple of 256. There's space for the
* NUL, since if len is a multiple of 256, the size chosen will
* be the next multiple.
*/
return (NULL);
}
/* This is safe. */
} else {
}
chan->references = 0;
return (chan);
}
int
return (-1);
}
return (0);
}
return (NULL);
}
chan->references = 0;
return (chan);
}
int
return (-1);
}
chan->references++;
return (0);
}
int
return (-1);
}
chan->references--;
return (0);
}
}
int
return (-1);
}
chan->references--;
if (chan->references == 0) {
}
}
return (0);
}