log.c revision cc1b6f86f2e0bff7e903a4e7d2cd10e6a59b8b9c
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 1999 Internet Software Consortium.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Permission to use, copy, modify, and distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the above
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * copyright notice and this permission notice appear in all copies.
d48730a446ffffa8d75462a4abefce030425fa64Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
09b46c39456ea75a414d8fcdb13127ed4917dac2Automatic Updater * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
d48730a446ffffa8d75462a4abefce030425fa64Mark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
fb756ba3047770957173ba546257ca43af7ba3e4Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
d48730a446ffffa8d75462a4abefce030425fa64Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
d48730a446ffffa8d75462a4abefce030425fa64Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
d48730a446ffffa8d75462a4abefce030425fa64Mark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
67adc03ef81fb610f8df093b17f55275ee816754Evan Hunt/* $Id: log.c,v 1.13 2000/01/06 14:47:37 tale Exp $ */
d48730a446ffffa8d75462a4abefce030425fa64Mark Andrews/* Principal Authors: DCL */
d48730a446ffffa8d75462a4abefce030425fa64Mark Andrews#define VALID_CONTEXT(lctx) ((lctx) != NULL && (lctx)->magic == LOG_MAGIC)
d1cacbb37474b0cbee6c1ddd05d27f731b2b43baMark Andrews * This is the structure that holds each named channel. A simple linked
d1cacbb37474b0cbee6c1ddd05d27f731b2b43baMark Andrews * list chains all of the channels together, so an individual channel is
d1cacbb37474b0cbee6c1ddd05d27f731b2b43baMark Andrews * found by doing strcmp()s with the names down the list. Their should
fb604d1cee223986d090763292015309adfcf9c7Mark Andrews * be no peformance penalty from this as it is expected that the number
fb604d1cee223986d090763292015309adfcf9c7Mark Andrews * of named channels will be no more than a dozen or so, and name lookups
fb604d1cee223986d090763292015309adfcf9c7Mark Andrews * from the head of the list are only done when isc_log_usechannel() is
fb604d1cee223986d090763292015309adfcf9c7Mark Andrews * called, which should also be very infrequent.
2786b6c53fb198d742e9738294fa0a51a52e4dceckb unsigned int type;
2786b6c53fb198d742e9738294fa0a51a52e4dceckb unsigned int flags;
947cf282a721b089c1106780f13ae8e6298bddb1Mark Andrews * The logchannelist structure associates categories and modules with
65d59a4307d00f6b4e278b730c278502e5449da8Mark Andrews * channels. First the appropriate channellist is found based on the
65d59a4307d00f6b4e278b730c278502e5449da8Mark Andrews * category, and then each structure in the linked list is checked for
65d59a4307d00f6b4e278b730c278502e5449da8Mark Andrews * a matching module. It is expected that the number of channels
65d59a4307d00f6b4e278b730c278502e5449da8Mark Andrews * associated with any given category will be very short, no more than
65d59a4307d00f6b4e278b730c278502e5449da8Mark Andrews * three or four in the more unusual cases.
struct isc_logchannellist {
struct isc_logmessage {
char * text;
struct isc_log {
unsigned int magic;
int debug_level;
unsigned int duplicate_interval;
unsigned int category_count;
unsigned int module_count;
unsigned int context_count;
static char *log_level_strings[] = {
static const int syslog_map[] = {
{ NULL, 0 }
static isc_result_t
static isc_result_t
return (ISC_R_NOMEMORY);
&destination, 0);
NULL, 0);
return (result);
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
if (old_count != 0) {
return (ISC_R_SUCCESS);
sizeof(isc_log_t **));
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
unsigned int flags)
sizeof(*channel));
return (ISC_R_NOMEMORY);
return (ISC_R_NOMEMORY);
switch (type) {
case ISC_LOG_TOSYSLOG:
case ISC_LOG_TOFILE:
case ISC_LOG_TOFILEDESC:
case ISC_LOG_TONULL:
return (ISC_R_UNEXPECTED);
return (ISC_R_SUCCESS);
return (ISC_R_NOTFOUND);
return (result);
return (result);
return (result);
static isc_result_t
sizeof(*new_item));
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
unsigned int basenamelen;
return (++greatest);
static isc_result_t
char *path;
return (ISC_R_SUCCESS);
digits++;
return (ISC_R_INVALIDFILE);
for (i = greatest; i > 0; i--) {
return (ISC_R_SUCCESS);
static isc_result_t
char *path;
return (ISC_R_INVALIDFILE);
if (regular_file)
return (ISC_R_INVALIDFILE);
return (ISC_R_INVALIDFILE);
return (ISC_R_SUCCESS);
int syslog_level;
if (write_once) {
&oldest);
&oldest) < 0) {
NULL;
sizeof(isc_logmessage_t) +
new;
case ISC_LOG_TOFILE:
case ISC_LOG_TOFILEDESC:
&statbuf) >= 0 &&
case ISC_LOG_TOSYSLOG:
if (level > 0)
case ISC_LOG_TONULL: