log.c revision 15a44745412679c30a6d022733925af70a38b715
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 1999, 2000 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.
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews/* $Id: log.c,v 1.41 2000/07/27 09:50:58 tale Exp $ */
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews/* Principal Authors: DCL */
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews#define VALID_CONTEXT(lctx) ISC_MAGIC_VALID(lctx, LCTX_MAGIC)
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews#define VALID_CONFIG(lcfg) ISC_MAGIC_VALID(lcfg, LCFG_MAGIC)
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * XXXDCL make dynamic?
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * This is the structure that holds each named channel. A simple linked
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * list chains all of the channels together, so an individual channel is
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * found by doing strcmp()s with the names down the list. Their should
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * be no peformance penalty from this as it is expected that the number
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * of named channels will be no more than a dozen or so, and name lookups
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * from the head of the list are only done when isc_log_usechannel() is
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * called, which should also be very infrequent.
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews unsigned int type;
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews unsigned int flags;
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * The logchannellist structure associates categories and modules with
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * channels. First the appropriate channellist is found based on the
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * category, and then each structure in the linked list is checked for
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * a matching module. It is expected that the number of channels
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * associated with any given category will be very short, no more than
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * three or four in the more unusual cases.
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrewstypedef struct isc_logchannellist isc_logchannellist_t;
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * This structure is used to remember messages for pruning via
b976c39c07f7672bd1293e878b3306c7decf8afeMark Andrews * isc_log_[v]write1().
struct isc_logmessage {
char * text;
struct isc_logconfig {
unsigned int magic;
unsigned int channellist_count;
unsigned int duplicate_interval;
int highest_level;
char * tag;
struct isc_log {
unsigned int magic;
unsigned int category_count;
unsigned int module_count;
int debug_level;
static const char *log_level_strings[] = {
static const int syslog_map[] = {
{ NULL, 0 }
{ NULL, 0 }
static isc_result_t
static isc_result_t
static isc_result_t
return (result);
&destination, 0);
NULL, 0);
return (result);
return (result);
return (ISC_R_SUCCESS);
char *filename;
catp++;
return (catp);
catp++;
return (NULL);
modp++;
return (modp);
modp++;
return (NULL);
unsigned int flags)
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 (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
static isc_result_t
return (result);
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
static isc_result_t
unsigned int bytes;
void *lists;
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
const char *dirname;
unsigned int basenamelen;
return (++greatest);
static isc_result_t
const 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
const char *path;
return (ISC_R_INVALIDFILE);
if (regular_file)
return (ISC_R_INVALIDFILE);
return (ISC_R_INVALIDFILE);
return (ISC_R_SUCCESS);
return (ISC_FALSE);
int syslog_level;
link);
&now);
unsigned int len;
if (write_once) {
&oldest) !=
&oldest) < 0) {
link);
sizeof(isc_logmessage_t) +
case ISC_LOG_TOFILE:
case ISC_LOG_TOFILEDESC:
&statbuf) >= 0 &&
case ISC_LOG_TOSYSLOG:
if (level > 0)
case ISC_LOG_TONULL: