1999-09-23 17:43:51 +00:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
1999-09-23 17:43:51 +00:00
|
|
|
*/
|
|
|
|
|
2018-04-17 09:32:20 -07:00
|
|
|
/*! \file */
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
#include <errno.h>
|
2018-03-28 14:19:37 +02:00
|
|
|
#include <inttypes.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <limits.h>
|
2018-04-17 08:29:14 -07:00
|
|
|
#include <stdbool.h>
|
1999-09-23 17:43:51 +00:00
|
|
|
#include <stdlib.h>
|
2020-03-09 16:17:26 +01:00
|
|
|
#include <sys/types.h> /* dev_t FreeBSD 2.1 */
|
2000-08-24 23:22:40 +00:00
|
|
|
#include <time.h>
|
2000-05-08 14:38:29 +00:00
|
|
|
|
2019-12-20 19:29:18 -03:00
|
|
|
#include <isc/atomic.h>
|
1999-09-23 17:43:51 +00:00
|
|
|
#include <isc/dir.h>
|
2001-06-27 04:37:11 +00:00
|
|
|
#include <isc/file.h>
|
1999-09-23 17:43:51 +00:00
|
|
|
#include <isc/log.h>
|
2000-05-16 03:37:39 +00:00
|
|
|
#include <isc/magic.h>
|
1999-09-23 17:43:51 +00:00
|
|
|
#include <isc/mem.h>
|
2019-11-10 20:14:17 +00:00
|
|
|
#include <isc/platform.h>
|
1999-10-11 16:10:06 +00:00
|
|
|
#include <isc/print.h>
|
2020-03-13 15:16:14 +01:00
|
|
|
#include <isc/rwlock.h>
|
2004-03-16 05:52:24 +00:00
|
|
|
#include <isc/stat.h>
|
2001-03-28 04:16:32 +00:00
|
|
|
#include <isc/stdio.h>
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <isc/string.h>
|
1999-10-25 19:55:06 +00:00
|
|
|
#include <isc/time.h>
|
2000-02-26 19:57:02 +00:00
|
|
|
#include <isc/util.h>
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-02-13 14:44:37 -08:00
|
|
|
#define LCTX_MAGIC ISC_MAGIC('L', 'c', 't', 'x')
|
2020-02-12 13:59:18 +01:00
|
|
|
#define VALID_CONTEXT(lctx) ISC_MAGIC_VALID(lctx, LCTX_MAGIC)
|
2001-06-04 19:33:39 +00:00
|
|
|
|
2020-02-13 14:44:37 -08:00
|
|
|
#define LCFG_MAGIC ISC_MAGIC('L', 'c', 'f', 'g')
|
2020-02-12 13:59:18 +01:00
|
|
|
#define VALID_CONFIG(lcfg) ISC_MAGIC_VALID(lcfg, LCFG_MAGIC)
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-03-13 15:16:14 +01:00
|
|
|
#define RDLOCK(lp) RWLOCK(lp, isc_rwlocktype_read);
|
|
|
|
#define WRLOCK(lp) RWLOCK(lp, isc_rwlocktype_write);
|
|
|
|
#define RDUNLOCK(lp) RWUNLOCK(lp, isc_rwlocktype_read);
|
|
|
|
#define WRUNLOCK(lp) RWUNLOCK(lp, isc_rwlocktype_write);
|
|
|
|
|
2000-03-01 17:31:56 +00:00
|
|
|
/*
|
|
|
|
* XXXDCL make dynamic?
|
|
|
|
*/
|
2020-02-12 13:59:18 +01:00
|
|
|
#define LOG_BUFFER_SIZE (8 * 1024)
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*!
|
1999-09-23 17:43:51 +00:00
|
|
|
* This is the structure that holds each named channel. A simple linked
|
|
|
|
* list chains all of the channels together, so an individual channel is
|
|
|
|
* found by doing strcmp()s with the names down the list. Their should
|
2009-01-18 00:50:21 +00:00
|
|
|
* be no performance penalty from this as it is expected that the number
|
1999-09-23 17:43:51 +00:00
|
|
|
* of named channels will be no more than a dozen or so, and name lookups
|
|
|
|
* from the head of the list are only done when isc_log_usechannel() is
|
|
|
|
* called, which should also be very infrequent.
|
|
|
|
*/
|
2000-03-01 17:31:56 +00:00
|
|
|
typedef struct isc_logchannel isc_logchannel_t;
|
|
|
|
|
1999-09-23 17:43:51 +00:00
|
|
|
struct isc_logchannel {
|
2020-02-13 14:44:37 -08:00
|
|
|
char *name;
|
|
|
|
unsigned int type;
|
|
|
|
int level;
|
|
|
|
unsigned int flags;
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_logdestination_t destination;
|
|
|
|
ISC_LINK(isc_logchannel_t) link;
|
1999-09-23 17:43:51 +00:00
|
|
|
};
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*!
|
2000-05-24 02:33:16 +00:00
|
|
|
* The logchannellist structure associates categories and modules with
|
1999-09-23 17:43:51 +00:00
|
|
|
* channels. First the appropriate channellist is found based on the
|
|
|
|
* category, and then each structure in the linked list is checked for
|
|
|
|
* a matching module. It is expected that the number of channels
|
|
|
|
* associated with any given category will be very short, no more than
|
|
|
|
* three or four in the more unusual cases.
|
|
|
|
*/
|
|
|
|
typedef struct isc_logchannellist isc_logchannellist_t;
|
|
|
|
|
|
|
|
struct isc_logchannellist {
|
2020-02-12 13:59:18 +01:00
|
|
|
const isc_logmodule_t *module;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_logchannel_t *channel;
|
2020-02-12 13:59:18 +01:00
|
|
|
ISC_LINK(isc_logchannellist_t) link;
|
1999-10-25 19:55:06 +00:00
|
|
|
};
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*!
|
1999-10-25 19:55:06 +00:00
|
|
|
* This structure is used to remember messages for pruning via
|
|
|
|
* isc_log_[v]write1().
|
|
|
|
*/
|
|
|
|
typedef struct isc_logmessage isc_logmessage_t;
|
|
|
|
|
|
|
|
struct isc_logmessage {
|
2020-02-13 14:44:37 -08:00
|
|
|
char *text;
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_time_t time;
|
|
|
|
ISC_LINK(isc_logmessage_t) link;
|
2000-02-26 19:57:02 +00:00
|
|
|
};
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*!
|
2000-03-01 17:31:56 +00:00
|
|
|
* The isc_logconfig structure is used to store the configurable information
|
|
|
|
* about where messages are actually supposed to be sent -- the information
|
|
|
|
* that could changed based on some configuration file, as opposed to the
|
|
|
|
* the category/module specification of isc_log_[v]write[1] that is compiled
|
|
|
|
* into a program, or the debug_level which is dynamic state information.
|
2000-02-26 19:57:02 +00:00
|
|
|
*/
|
|
|
|
struct isc_logconfig {
|
2020-02-12 13:59:18 +01:00
|
|
|
unsigned int magic;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_log_t *lctx;
|
2020-02-12 13:59:18 +01:00
|
|
|
ISC_LIST(isc_logchannel_t) channels;
|
|
|
|
ISC_LIST(isc_logchannellist_t) * channellists;
|
|
|
|
unsigned int channellist_count;
|
|
|
|
unsigned int duplicate_interval;
|
2020-02-13 14:44:37 -08:00
|
|
|
int highest_level;
|
|
|
|
char *tag;
|
|
|
|
bool dynamic;
|
1999-09-23 17:43:51 +00:00
|
|
|
};
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*!
|
1999-09-23 17:43:51 +00:00
|
|
|
* This isc_log structure provides the context for the isc_log functions.
|
2000-02-26 19:57:02 +00:00
|
|
|
* The log context locks itself in isc_log_doit, the internal backend to
|
1999-09-23 17:43:51 +00:00
|
|
|
* isc_log_write. The locking is necessary both to provide exclusive access
|
2009-01-05 23:20:22 +00:00
|
|
|
* to the buffer into which the message is formatted and to guard against
|
1999-09-23 17:43:51 +00:00
|
|
|
* competing threads trying to write to the same syslog resource. (On
|
|
|
|
* some systems, such as BSD/OS, stdio is thread safe but syslog is not.)
|
|
|
|
* Unfortunately, the lock cannot guard against a _different_ logging
|
|
|
|
* context in the same program competing for syslog's attention. Thus
|
|
|
|
* There Can Be Only One, but this is not enforced.
|
2000-03-01 17:31:56 +00:00
|
|
|
* XXXDCL enforce it?
|
2000-02-26 19:57:02 +00:00
|
|
|
*
|
|
|
|
* Note that the category and module information is not locked.
|
|
|
|
* This is because in the usual case, only one isc_log_t is ever created
|
|
|
|
* in a program, and the category/module registration happens only once.
|
2000-03-01 17:31:56 +00:00
|
|
|
* XXXDCL it might be wise to add more locking overall.
|
1999-09-23 17:43:51 +00:00
|
|
|
*/
|
|
|
|
struct isc_log {
|
2000-02-26 19:57:02 +00:00
|
|
|
/* Not locked. */
|
2020-02-13 14:44:37 -08:00
|
|
|
unsigned int magic;
|
|
|
|
isc_mem_t *mctx;
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_logcategory_t *categories;
|
2020-02-13 14:44:37 -08:00
|
|
|
unsigned int category_count;
|
|
|
|
isc_logmodule_t *modules;
|
|
|
|
unsigned int module_count;
|
|
|
|
int debug_level;
|
2020-03-13 15:16:14 +01:00
|
|
|
isc_rwlock_t lcfg_rwl;
|
|
|
|
/* Locked by isc_log lcfg_rwl */
|
|
|
|
isc_logconfig_t *logconfig;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_mutex_t lock;
|
2000-02-26 19:57:02 +00:00
|
|
|
/* Locked by isc_log lock. */
|
2020-02-13 14:44:37 -08:00
|
|
|
char buffer[LOG_BUFFER_SIZE];
|
2020-02-12 13:59:18 +01:00
|
|
|
ISC_LIST(isc_logmessage_t) messages;
|
1999-09-23 17:43:51 +00:00
|
|
|
};
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*!
|
1999-09-23 17:43:51 +00:00
|
|
|
* Used when ISC_LOG_PRINTLEVEL is enabled for a channel.
|
|
|
|
*/
|
2020-02-12 13:59:18 +01:00
|
|
|
static const char *log_level_strings[] = { "debug", "info", "notice",
|
|
|
|
"warning", "error", "critical" };
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*!
|
1999-09-23 17:43:51 +00:00
|
|
|
* Used to convert ISC_LOG_* priorities into syslog priorities.
|
2000-03-01 17:31:56 +00:00
|
|
|
* XXXDCL This will need modification for NT.
|
1999-09-23 17:43:51 +00:00
|
|
|
*/
|
2020-02-12 13:59:18 +01:00
|
|
|
static const int syslog_map[] = { LOG_DEBUG, LOG_INFO, LOG_NOTICE,
|
|
|
|
LOG_WARNING, LOG_ERR, LOG_CRIT };
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*!
|
1999-09-23 17:43:51 +00:00
|
|
|
* When adding new categories, a corresponding ISC_LOGCATEGORY_foo
|
2000-02-26 19:57:02 +00:00
|
|
|
* definition needs to be added to <isc/log.h>.
|
1999-09-23 17:43:51 +00:00
|
|
|
*
|
|
|
|
* The default category is provided so that the internal default can
|
|
|
|
* be overridden. Since the default is always looked up as the first
|
|
|
|
* channellist in the log context, it must come first in isc_categories[].
|
|
|
|
*/
|
2020-02-12 13:59:18 +01:00
|
|
|
LIBISC_EXTERNAL_DATA isc_logcategory_t isc_categories[] = { { "default",
|
|
|
|
0 }, /* "default"
|
2020-02-13 21:48:23 +01:00
|
|
|
* must come
|
|
|
|
* first. */
|
2020-02-12 13:59:18 +01:00
|
|
|
{ "general", 0 },
|
|
|
|
{ NULL, 0 } };
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*!
|
2020-02-12 13:59:18 +01:00
|
|
|
* See above comment for categories on LIBISC_EXTERNAL_DATA, and apply it to
|
|
|
|
* modules.
|
2000-05-03 21:09:34 +00:00
|
|
|
*/
|
2001-07-12 05:58:28 +00:00
|
|
|
LIBISC_EXTERNAL_DATA isc_logmodule_t isc_modules[] = {
|
2020-02-12 13:59:18 +01:00
|
|
|
{ "socket", 0 }, { "time", 0 }, { "interface", 0 }, { "timer", 0 },
|
|
|
|
{ "file", 0 }, { "netmgr", 0 }, { "other", 0 }, { NULL, 0 }
|
2000-05-03 21:09:34 +00:00
|
|
|
};
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*!
|
2000-04-28 17:29:25 +00:00
|
|
|
* This essentially constant structure must be filled in at run time,
|
2000-03-01 17:31:56 +00:00
|
|
|
* because its channel member is pointed to a channel that is created
|
|
|
|
* dynamically with isc_log_createchannel.
|
1999-09-23 17:43:51 +00:00
|
|
|
*/
|
2000-04-28 17:29:25 +00:00
|
|
|
static isc_logchannellist_t default_channel;
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*!
|
2000-05-03 21:09:34 +00:00
|
|
|
* libisc logs to this context.
|
|
|
|
*/
|
2001-07-12 05:58:28 +00:00
|
|
|
LIBISC_EXTERNAL_DATA isc_log_t *isc_lctx = NULL;
|
2000-05-03 21:09:34 +00:00
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*!
|
1999-09-23 17:43:51 +00:00
|
|
|
* Forward declarations.
|
|
|
|
*/
|
2020-03-18 14:17:55 +11:00
|
|
|
static void
|
2020-02-14 08:14:03 +01:00
|
|
|
assignchannel(isc_logconfig_t *lcfg, unsigned int category_id,
|
|
|
|
const isc_logmodule_t *module, isc_logchannel_t *channel);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-03-18 14:17:55 +11:00
|
|
|
static void
|
2020-02-14 08:14:03 +01:00
|
|
|
sync_channellist(isc_logconfig_t *lcfg);
|
2000-02-26 19:57:02 +00:00
|
|
|
|
2020-02-14 08:14:03 +01:00
|
|
|
static isc_result_t
|
|
|
|
greatest_version(isc_logfile_t *file, int versions, int *greatest);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-02-14 08:14:03 +01:00
|
|
|
static void
|
|
|
|
isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category,
|
|
|
|
isc_logmodule_t *module, int level, bool write_once,
|
|
|
|
const char *format, va_list args) ISC_FORMAT_PRINTF(6, 0);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*@{*/
|
|
|
|
/*!
|
1999-09-23 17:43:51 +00:00
|
|
|
* Convenience macros.
|
|
|
|
*/
|
|
|
|
|
2020-02-13 14:44:37 -08:00
|
|
|
#define FACILITY(channel) (channel->destination.facility)
|
|
|
|
#define FILE_NAME(channel) (channel->destination.file.name)
|
|
|
|
#define FILE_STREAM(channel) (channel->destination.file.stream)
|
|
|
|
#define FILE_VERSIONS(channel) (channel->destination.file.versions)
|
|
|
|
#define FILE_SUFFIX(channel) (channel->destination.file.suffix)
|
|
|
|
#define FILE_MAXSIZE(channel) (channel->destination.file.maximum_size)
|
2000-12-23 19:23:48 +00:00
|
|
|
#define FILE_MAXREACHED(channel) (channel->destination.file.maximum_reached)
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*@}*/
|
1999-09-23 17:43:51 +00:00
|
|
|
/****
|
2020-02-13 21:48:23 +01:00
|
|
|
**** Public interfaces.
|
|
|
|
****/
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Establish a new logging context, with default channels.
|
|
|
|
*/
|
2020-03-18 14:17:55 +11:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_log_create(isc_mem_t *mctx, isc_log_t **lctxp, isc_logconfig_t **lcfgp) {
|
|
|
|
isc_log_t *lctx;
|
2000-02-26 19:57:02 +00:00
|
|
|
isc_logconfig_t *lcfg = NULL;
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
REQUIRE(mctx != NULL);
|
|
|
|
REQUIRE(lctxp != NULL && *lctxp == NULL);
|
2000-11-24 01:37:26 +00:00
|
|
|
REQUIRE(lcfgp == NULL || *lcfgp == NULL);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2000-03-01 17:31:56 +00:00
|
|
|
lctx = isc_mem_get(mctx, sizeof(*lctx));
|
2020-03-18 14:17:55 +11:00
|
|
|
lctx->mctx = NULL;
|
|
|
|
isc_mem_attach(mctx, &lctx->mctx);
|
|
|
|
lctx->categories = NULL;
|
|
|
|
lctx->category_count = 0;
|
|
|
|
lctx->modules = NULL;
|
|
|
|
lctx->module_count = 0;
|
|
|
|
lctx->debug_level = 0;
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-03-18 14:17:55 +11:00
|
|
|
ISC_LIST_INIT(lctx->messages);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2020-03-18 14:17:55 +11:00
|
|
|
isc_mutex_init(&lctx->lock);
|
2020-03-13 15:16:14 +01:00
|
|
|
isc_rwlock_init(&lctx->lcfg_rwl, 0, 0);
|
2000-02-26 19:57:02 +00:00
|
|
|
|
2020-03-18 14:17:55 +11:00
|
|
|
/*
|
|
|
|
* Normally setting the magic number is the last step done
|
|
|
|
* in a creation function, but a valid log context is needed
|
|
|
|
* by isc_log_registercategories and isc_logconfig_create.
|
|
|
|
* If either fails, the lctx is destroyed and not returned
|
|
|
|
* to the caller.
|
|
|
|
*/
|
|
|
|
lctx->magic = LCTX_MAGIC;
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-03-18 14:17:55 +11:00
|
|
|
isc_log_registercategories(lctx, isc_categories);
|
|
|
|
isc_log_registermodules(lctx, isc_modules);
|
|
|
|
isc_logconfig_create(lctx, &lcfg);
|
2000-02-26 19:57:02 +00:00
|
|
|
|
2020-03-18 14:17:55 +11:00
|
|
|
sync_channellist(lcfg);
|
2000-05-24 02:33:16 +00:00
|
|
|
|
2020-03-13 15:16:14 +01:00
|
|
|
lctx->logconfig = lcfg;
|
2000-02-26 19:57:02 +00:00
|
|
|
|
2020-03-18 14:17:55 +11:00
|
|
|
*lctxp = lctx;
|
|
|
|
if (lcfgp != NULL) {
|
|
|
|
*lcfgp = lcfg;
|
2002-01-09 06:16:10 +00:00
|
|
|
}
|
2000-02-26 19:57:02 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 14:17:55 +11:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_logconfig_create(isc_log_t *lctx, isc_logconfig_t **lcfgp) {
|
|
|
|
isc_logconfig_t *lcfg;
|
2000-02-26 19:57:02 +00:00
|
|
|
isc_logdestination_t destination;
|
2020-02-13 14:44:37 -08:00
|
|
|
int level = ISC_LOG_INFO;
|
2000-02-26 19:57:02 +00:00
|
|
|
|
|
|
|
REQUIRE(lcfgp != NULL && *lcfgp == NULL);
|
|
|
|
REQUIRE(VALID_CONTEXT(lctx));
|
|
|
|
|
2000-03-01 17:31:56 +00:00
|
|
|
lcfg = isc_mem_get(lctx->mctx, sizeof(*lcfg));
|
2000-02-26 19:57:02 +00:00
|
|
|
|
2020-02-05 16:45:59 +11:00
|
|
|
lcfg->lctx = lctx;
|
|
|
|
lcfg->channellists = NULL;
|
|
|
|
lcfg->channellist_count = 0;
|
|
|
|
lcfg->duplicate_interval = 0;
|
|
|
|
lcfg->highest_level = level;
|
|
|
|
lcfg->tag = NULL;
|
|
|
|
lcfg->dynamic = false;
|
|
|
|
ISC_LIST_INIT(lcfg->channels);
|
|
|
|
lcfg->magic = LCFG_MAGIC;
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the default channels:
|
1999-10-25 13:11:13 +00:00
|
|
|
* default_syslog, default_stderr, default_debug and null.
|
1999-09-23 17:43:51 +00:00
|
|
|
*/
|
2020-03-18 14:17:55 +11:00
|
|
|
destination.facility = LOG_DAEMON;
|
|
|
|
isc_log_createchannel(lcfg, "default_syslog", ISC_LOG_TOSYSLOG, level,
|
|
|
|
&destination, 0);
|
|
|
|
|
|
|
|
destination.file.stream = stderr;
|
|
|
|
destination.file.name = NULL;
|
|
|
|
destination.file.versions = ISC_LOG_ROLLNEVER;
|
|
|
|
destination.file.suffix = isc_log_rollsuffix_increment;
|
|
|
|
destination.file.maximum_size = 0;
|
|
|
|
isc_log_createchannel(lcfg, "default_stderr", ISC_LOG_TOFILEDESC, level,
|
|
|
|
&destination, ISC_LOG_PRINTTIME);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-03-18 14:17:55 +11:00
|
|
|
/*
|
|
|
|
* Set the default category's channel to default_stderr,
|
|
|
|
* which is at the head of the channels list because it was
|
|
|
|
* just created.
|
|
|
|
*/
|
|
|
|
default_channel.channel = ISC_LIST_HEAD(lcfg->channels);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-03-18 14:17:55 +11:00
|
|
|
destination.file.stream = stderr;
|
|
|
|
destination.file.name = NULL;
|
|
|
|
destination.file.versions = ISC_LOG_ROLLNEVER;
|
|
|
|
destination.file.suffix = isc_log_rollsuffix_increment;
|
|
|
|
destination.file.maximum_size = 0;
|
|
|
|
isc_log_createchannel(lcfg, "default_debug", ISC_LOG_TOFILEDESC,
|
|
|
|
ISC_LOG_DYNAMIC, &destination, ISC_LOG_PRINTTIME);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-03-18 14:17:55 +11:00
|
|
|
isc_log_createchannel(lcfg, "null", ISC_LOG_TONULL, ISC_LOG_DYNAMIC,
|
|
|
|
NULL, 0);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-03-18 14:17:55 +11:00
|
|
|
*lcfgp = lcfg;
|
2000-02-26 19:57:02 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 14:17:55 +11:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_logconfig_use(isc_log_t *lctx, isc_logconfig_t *lcfg) {
|
2000-02-26 19:57:02 +00:00
|
|
|
isc_logconfig_t *old_cfg;
|
|
|
|
|
|
|
|
REQUIRE(VALID_CONTEXT(lctx));
|
|
|
|
REQUIRE(VALID_CONFIG(lcfg));
|
|
|
|
REQUIRE(lcfg->lctx == lctx);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ensure that lcfg->channellist_count == lctx->category_count.
|
|
|
|
* They won't be equal if isc_log_usechannel has not been called
|
|
|
|
* since any call to isc_log_registercategories.
|
|
|
|
*/
|
2020-03-18 14:17:55 +11:00
|
|
|
sync_channellist(lcfg);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-03-13 15:16:14 +01:00
|
|
|
WRLOCK(&lctx->lcfg_rwl);
|
|
|
|
old_cfg = lctx->logconfig;
|
|
|
|
lctx->logconfig = lcfg;
|
|
|
|
WRUNLOCK(&lctx->lcfg_rwl);
|
2000-02-26 19:57:02 +00:00
|
|
|
|
|
|
|
isc_logconfig_destroy(&old_cfg);
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_log_destroy(isc_log_t **lctxp) {
|
|
|
|
isc_log_t *lctx;
|
|
|
|
isc_logconfig_t *lcfg;
|
|
|
|
isc_mem_t *mctx;
|
2000-02-26 19:57:02 +00:00
|
|
|
isc_logmessage_t *message;
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
REQUIRE(lctxp != NULL && VALID_CONTEXT(*lctxp));
|
|
|
|
|
|
|
|
lctx = *lctxp;
|
2020-02-08 04:37:54 -08:00
|
|
|
*lctxp = NULL;
|
1999-09-23 17:43:51 +00:00
|
|
|
mctx = lctx->mctx;
|
|
|
|
|
2020-03-13 15:16:14 +01:00
|
|
|
WRLOCK(&lctx->lcfg_rwl);
|
|
|
|
lcfg = lctx->logconfig;
|
|
|
|
lctx->logconfig = NULL;
|
|
|
|
WRUNLOCK(&lctx->lcfg_rwl);
|
|
|
|
|
2019-12-20 19:29:18 -03:00
|
|
|
if (lcfg != NULL) {
|
2000-02-26 19:57:02 +00:00
|
|
|
isc_logconfig_destroy(&lcfg);
|
|
|
|
}
|
|
|
|
|
2020-03-13 15:16:14 +01:00
|
|
|
isc_rwlock_destroy(&lctx->lcfg_rwl);
|
2018-11-19 10:31:09 +00:00
|
|
|
isc_mutex_destroy(&lctx->lock);
|
2000-02-26 19:57:02 +00:00
|
|
|
|
|
|
|
while ((message = ISC_LIST_HEAD(lctx->messages)) != NULL) {
|
|
|
|
ISC_LIST_UNLINK(lctx->messages, message, link);
|
|
|
|
|
|
|
|
isc_mem_put(mctx, message,
|
|
|
|
sizeof(*message) + strlen(message->text) + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
lctx->buffer[0] = '\0';
|
|
|
|
lctx->debug_level = 0;
|
2000-03-04 00:43:40 +00:00
|
|
|
lctx->categories = NULL;
|
2000-02-26 19:57:02 +00:00
|
|
|
lctx->category_count = 0;
|
2000-03-04 00:43:40 +00:00
|
|
|
lctx->modules = NULL;
|
2000-02-26 19:57:02 +00:00
|
|
|
lctx->module_count = 0;
|
|
|
|
lctx->mctx = NULL;
|
|
|
|
lctx->magic = 0;
|
|
|
|
|
2013-02-20 21:39:05 -08:00
|
|
|
isc_mem_putanddetach(&mctx, lctx, sizeof(*lctx));
|
2000-02-26 19:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_logconfig_destroy(isc_logconfig_t **lcfgp) {
|
|
|
|
isc_logconfig_t *lcfg;
|
|
|
|
isc_mem_t *mctx;
|
|
|
|
isc_logchannel_t *channel;
|
|
|
|
char *filename;
|
|
|
|
unsigned int i;
|
2000-02-26 19:57:02 +00:00
|
|
|
|
|
|
|
REQUIRE(lcfgp != NULL && VALID_CONFIG(*lcfgp));
|
|
|
|
|
|
|
|
lcfg = *lcfgp;
|
2020-02-08 04:37:54 -08:00
|
|
|
*lcfgp = NULL;
|
2000-02-26 19:57:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This function cannot be called with a logconfig that is in
|
|
|
|
* use by a log context.
|
|
|
|
*/
|
2020-03-13 15:16:14 +01:00
|
|
|
REQUIRE(lcfg->lctx != NULL);
|
|
|
|
|
|
|
|
RDLOCK(&lcfg->lctx->lcfg_rwl);
|
|
|
|
REQUIRE(lcfg->lctx->logconfig != lcfg);
|
|
|
|
RDUNLOCK(&lcfg->lctx->lcfg_rwl);
|
2000-02-26 19:57:02 +00:00
|
|
|
|
|
|
|
mctx = lcfg->lctx->mctx;
|
|
|
|
|
2000-03-01 17:31:56 +00:00
|
|
|
while ((channel = ISC_LIST_HEAD(lcfg->channels)) != NULL) {
|
|
|
|
ISC_LIST_UNLINK(lcfg->channels, channel, link);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
if (channel->type == ISC_LOG_TOFILE) {
|
2000-06-01 17:20:56 +00:00
|
|
|
/*
|
|
|
|
* The filename for the channel may have ultimately
|
|
|
|
* started its life in user-land as a const string,
|
|
|
|
* but in isc_log_createchannel it gets copied
|
|
|
|
* into writable memory and is not longer truly const.
|
|
|
|
*/
|
|
|
|
DE_CONST(FILE_NAME(channel), filename);
|
|
|
|
isc_mem_free(mctx, filename);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (FILE_STREAM(channel) != NULL) {
|
2000-06-01 17:20:56 +00:00
|
|
|
(void)fclose(FILE_STREAM(channel));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_mem_free(mctx, channel->name);
|
|
|
|
isc_mem_put(mctx, channel, sizeof(*channel));
|
|
|
|
}
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
for (i = 0; i < lcfg->channellist_count; i++) {
|
2020-03-13 15:16:14 +01:00
|
|
|
isc_logchannellist_t *item;
|
2000-03-01 17:31:56 +00:00
|
|
|
while ((item = ISC_LIST_HEAD(lcfg->channellists[i])) != NULL) {
|
|
|
|
ISC_LIST_UNLINK(lcfg->channellists[i], item, link);
|
|
|
|
isc_mem_put(mctx, item, sizeof(*item));
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (lcfg->channellist_count > 0) {
|
2000-05-24 02:33:16 +00:00
|
|
|
isc_mem_put(mctx, lcfg->channellists,
|
|
|
|
lcfg->channellist_count *
|
2020-02-12 13:59:18 +01:00
|
|
|
sizeof(ISC_LIST(isc_logchannellist_t)));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-10-25 19:55:06 +00:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
lcfg->dynamic = false;
|
2020-02-13 21:48:23 +01:00
|
|
|
if (lcfg->tag != NULL) {
|
2000-08-01 01:33:37 +00:00
|
|
|
isc_mem_free(lcfg->lctx->mctx, lcfg->tag);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-05-16 03:37:39 +00:00
|
|
|
lcfg->tag = NULL;
|
2000-04-06 20:32:31 +00:00
|
|
|
lcfg->highest_level = 0;
|
2000-02-26 19:57:02 +00:00
|
|
|
lcfg->duplicate_interval = 0;
|
|
|
|
lcfg->magic = 0;
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2000-02-26 19:57:02 +00:00
|
|
|
isc_mem_put(mctx, lcfg, sizeof(*lcfg));
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
|
|
|
|
2000-02-26 19:57:02 +00:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_log_registercategories(isc_log_t *lctx, isc_logcategory_t categories[]) {
|
1999-09-23 17:43:51 +00:00
|
|
|
isc_logcategory_t *catp;
|
|
|
|
|
|
|
|
REQUIRE(VALID_CONTEXT(lctx));
|
2000-03-04 00:43:40 +00:00
|
|
|
REQUIRE(categories != NULL && categories[0].name != NULL);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2000-03-04 00:43:40 +00:00
|
|
|
/*
|
|
|
|
* XXXDCL This somewhat sleazy situation of using the last pointer
|
|
|
|
* in one category array to point to the next array exists because
|
|
|
|
* this registration function returns void and I didn't want to have
|
|
|
|
* change everything that used it by making it return an isc_result_t.
|
|
|
|
* It would need to do that if it had to allocate memory to store
|
|
|
|
* pointers to each array passed in.
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
if (lctx->categories == NULL) {
|
2000-03-04 00:43:40 +00:00
|
|
|
lctx->categories = categories;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-03-04 00:43:40 +00:00
|
|
|
/*
|
|
|
|
* Adjust the last (NULL) pointer of the already registered
|
|
|
|
* categories to point to the incoming array.
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
for (catp = lctx->categories; catp->name != NULL;) {
|
|
|
|
if (catp->id == UINT_MAX) {
|
2000-06-01 17:20:56 +00:00
|
|
|
/*
|
|
|
|
* The name pointer points to the next array.
|
|
|
|
* Ick.
|
|
|
|
*/
|
|
|
|
DE_CONST(catp->name, catp);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-06-23 17:52:20 +00:00
|
|
|
catp++;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
}
|
2000-03-04 00:43:40 +00:00
|
|
|
|
|
|
|
catp->name = (void *)categories;
|
|
|
|
catp->id = UINT_MAX;
|
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the id number of the category with its new global id.
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
for (catp = categories; catp->name != NULL; catp++) {
|
2000-03-04 00:43:40 +00:00
|
|
|
catp->id = lctx->category_count++;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-03-04 00:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_logcategory_t *
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_log_categorybyname(isc_log_t *lctx, const char *name) {
|
2000-03-04 00:43:40 +00:00
|
|
|
isc_logcategory_t *catp;
|
|
|
|
|
|
|
|
REQUIRE(VALID_CONTEXT(lctx));
|
2000-03-04 16:41:14 +00:00
|
|
|
REQUIRE(name != NULL);
|
2000-03-04 00:43:40 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
for (catp = lctx->categories; catp->name != NULL;) {
|
|
|
|
if (catp->id == UINT_MAX) {
|
2000-06-01 17:20:56 +00:00
|
|
|
/*
|
|
|
|
* catp is neither modified nor returned to the
|
|
|
|
* caller, so removing its const qualifier is ok.
|
|
|
|
*/
|
|
|
|
DE_CONST(catp->name, catp);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
|
|
|
if (strcmp(catp->name, name) == 0) {
|
2000-06-01 17:20:56 +00:00
|
|
|
return (catp);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-23 17:52:20 +00:00
|
|
|
catp++;
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2000-03-04 00:43:40 +00:00
|
|
|
return (NULL);
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_log_registermodules(isc_log_t *lctx, isc_logmodule_t modules[]) {
|
1999-09-23 17:43:51 +00:00
|
|
|
isc_logmodule_t *modp;
|
|
|
|
|
|
|
|
REQUIRE(VALID_CONTEXT(lctx));
|
2000-03-04 00:43:40 +00:00
|
|
|
REQUIRE(modules != NULL && modules[0].name != NULL);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2000-03-04 00:43:40 +00:00
|
|
|
/*
|
|
|
|
* XXXDCL This somewhat sleazy situation of using the last pointer
|
|
|
|
* in one category array to point to the next array exists because
|
|
|
|
* this registration function returns void and I didn't want to have
|
|
|
|
* change everything that used it by making it return an isc_result_t.
|
|
|
|
* It would need to do that if it had to allocate memory to store
|
|
|
|
* pointers to each array passed in.
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
if (lctx->modules == NULL) {
|
2000-03-04 00:43:40 +00:00
|
|
|
lctx->modules = modules;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-03-04 00:43:40 +00:00
|
|
|
/*
|
|
|
|
* Adjust the last (NULL) pointer of the already registered
|
|
|
|
* modules to point to the incoming array.
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
for (modp = lctx->modules; modp->name != NULL;) {
|
|
|
|
if (modp->id == UINT_MAX) {
|
2000-06-01 17:20:56 +00:00
|
|
|
/*
|
|
|
|
* The name pointer points to the next array.
|
|
|
|
* Ick.
|
|
|
|
*/
|
|
|
|
DE_CONST(modp->name, modp);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-06-23 17:52:20 +00:00
|
|
|
modp++;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
}
|
2000-03-04 00:43:40 +00:00
|
|
|
|
|
|
|
modp->name = (void *)modules;
|
|
|
|
modp->id = UINT_MAX;
|
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the id number of the module with its new global id.
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
for (modp = modules; modp->name != NULL; modp++) {
|
2000-03-04 00:43:40 +00:00
|
|
|
modp->id = lctx->module_count++;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-03-04 00:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_logmodule_t *
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_log_modulebyname(isc_log_t *lctx, const char *name) {
|
2000-03-04 00:43:40 +00:00
|
|
|
isc_logmodule_t *modp;
|
|
|
|
|
|
|
|
REQUIRE(VALID_CONTEXT(lctx));
|
2000-03-04 16:41:14 +00:00
|
|
|
REQUIRE(name != NULL);
|
2000-03-04 00:43:40 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
for (modp = lctx->modules; modp->name != NULL;) {
|
|
|
|
if (modp->id == UINT_MAX) {
|
2000-06-01 17:20:56 +00:00
|
|
|
/*
|
2000-06-23 17:52:20 +00:00
|
|
|
* modp is neither modified nor returned to the
|
2000-06-01 17:20:56 +00:00
|
|
|
* caller, so removing its const qualifier is ok.
|
|
|
|
*/
|
|
|
|
DE_CONST(modp->name, modp);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
|
|
|
if (strcmp(modp->name, name) == 0) {
|
2000-06-01 17:20:56 +00:00
|
|
|
return (modp);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-23 17:52:20 +00:00
|
|
|
modp++;
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2000-03-04 00:43:40 +00:00
|
|
|
return (NULL);
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 14:17:55 +11:00
|
|
|
void
|
2000-02-26 19:57:02 +00:00
|
|
|
isc_log_createchannel(isc_logconfig_t *lcfg, const char *name,
|
|
|
|
unsigned int type, int level,
|
2000-06-01 17:20:56 +00:00
|
|
|
const isc_logdestination_t *destination,
|
2020-02-13 14:44:37 -08:00
|
|
|
unsigned int flags) {
|
1999-09-23 17:43:51 +00:00
|
|
|
isc_logchannel_t *channel;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_mem_t *mctx;
|
|
|
|
unsigned int permitted = ISC_LOG_PRINTALL | ISC_LOG_DEBUGONLY |
|
2016-11-22 23:34:47 -08:00
|
|
|
ISC_LOG_BUFFERED | ISC_LOG_ISO8601 |
|
|
|
|
ISC_LOG_UTC;
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2000-02-26 19:57:02 +00:00
|
|
|
REQUIRE(VALID_CONFIG(lcfg));
|
1999-09-23 17:43:51 +00:00
|
|
|
REQUIRE(name != NULL);
|
2020-02-12 13:59:18 +01:00
|
|
|
REQUIRE(type == ISC_LOG_TOSYSLOG || type == ISC_LOG_TOFILE ||
|
1999-09-23 17:43:51 +00:00
|
|
|
type == ISC_LOG_TOFILEDESC || type == ISC_LOG_TONULL);
|
|
|
|
REQUIRE(destination != NULL || type == ISC_LOG_TONULL);
|
|
|
|
REQUIRE(level >= ISC_LOG_CRITICAL);
|
2014-10-30 11:37:05 +11:00
|
|
|
REQUIRE((flags & ~permitted) == 0);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2000-02-26 19:57:02 +00:00
|
|
|
/* XXXDCL find duplicate names? */
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2000-02-26 19:57:02 +00:00
|
|
|
mctx = lcfg->lctx->mctx;
|
|
|
|
|
2000-03-01 17:31:56 +00:00
|
|
|
channel = isc_mem_get(mctx, sizeof(*channel));
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2000-02-26 19:57:02 +00:00
|
|
|
channel->name = isc_mem_strdup(mctx, name);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
channel->type = type;
|
|
|
|
channel->level = level;
|
|
|
|
channel->flags = flags;
|
2000-10-20 02:21:58 +00:00
|
|
|
ISC_LINK_INIT(channel, link);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case ISC_LOG_TOSYSLOG:
|
|
|
|
FACILITY(channel) = destination->facility;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ISC_LOG_TOFILE:
|
|
|
|
/*
|
|
|
|
* The file name is copied because greatest_version wants
|
|
|
|
* to scribble on it, so it needs to be definitely in
|
|
|
|
* writable memory.
|
|
|
|
*/
|
2020-02-13 14:44:37 -08:00
|
|
|
FILE_NAME(channel) = isc_mem_strdup(mctx,
|
|
|
|
destination->file.name);
|
1999-09-23 17:43:51 +00:00
|
|
|
FILE_STREAM(channel) = NULL;
|
|
|
|
FILE_VERSIONS(channel) = destination->file.versions;
|
2017-03-08 23:20:40 -08:00
|
|
|
FILE_SUFFIX(channel) = destination->file.suffix;
|
2000-12-23 19:23:48 +00:00
|
|
|
FILE_MAXSIZE(channel) = destination->file.maximum_size;
|
2018-04-17 08:29:14 -07:00
|
|
|
FILE_MAXREACHED(channel) = false;
|
1999-09-23 17:43:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ISC_LOG_TOFILEDESC:
|
|
|
|
FILE_NAME(channel) = NULL;
|
|
|
|
FILE_STREAM(channel) = destination->file.stream;
|
|
|
|
FILE_MAXSIZE(channel) = 0;
|
|
|
|
FILE_VERSIONS(channel) = ISC_LOG_ROLLNEVER;
|
2017-03-08 23:20:40 -08:00
|
|
|
FILE_SUFFIX(channel) = isc_log_rollsuffix_increment;
|
1999-09-23 17:43:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ISC_LOG_TONULL:
|
|
|
|
/* Nothing. */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-03-13 15:16:14 +01:00
|
|
|
INSIST(0);
|
2020-03-18 14:17:55 +11:00
|
|
|
ISC_UNREACHABLE();
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-03-01 17:31:56 +00:00
|
|
|
ISC_LIST_PREPEND(lcfg->channels, channel, link);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If default_stderr was redefined, make the default category
|
|
|
|
* point to the new default_stderr.
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
if (strcmp(name, "default_stderr") == 0) {
|
1999-09-23 17:43:51 +00:00
|
|
|
default_channel.channel = channel;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
2000-02-26 19:57:02 +00:00
|
|
|
isc_log_usechannel(isc_logconfig_t *lcfg, const char *name,
|
2000-06-01 17:20:56 +00:00
|
|
|
const isc_logcategory_t *category,
|
2020-02-13 14:44:37 -08:00
|
|
|
const isc_logmodule_t *module) {
|
|
|
|
isc_log_t *lctx;
|
1999-09-23 17:43:51 +00:00
|
|
|
isc_logchannel_t *channel;
|
|
|
|
|
2000-02-26 19:57:02 +00:00
|
|
|
REQUIRE(VALID_CONFIG(lcfg));
|
1999-09-23 17:43:51 +00:00
|
|
|
REQUIRE(name != NULL);
|
2000-02-26 19:57:02 +00:00
|
|
|
|
|
|
|
lctx = lcfg->lctx;
|
|
|
|
|
1999-09-23 17:43:51 +00:00
|
|
|
REQUIRE(category == NULL || category->id < lctx->category_count);
|
|
|
|
REQUIRE(module == NULL || module->id < lctx->module_count);
|
|
|
|
|
2000-03-01 17:31:56 +00:00
|
|
|
for (channel = ISC_LIST_HEAD(lcfg->channels); channel != NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
channel = ISC_LIST_NEXT(channel, link))
|
|
|
|
{
|
2020-02-13 18:16:57 +01:00
|
|
|
if (strcmp(name, channel->name) == 0) {
|
1999-09-23 17:43:51 +00:00
|
|
|
break;
|
2020-02-13 18:16:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (channel == NULL) {
|
1999-09-23 17:43:51 +00:00
|
|
|
return (ISC_R_NOTFOUND);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (category != NULL) {
|
2020-03-18 14:17:55 +11:00
|
|
|
assignchannel(lcfg, category->id, module, channel);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
1999-09-23 17:43:51 +00:00
|
|
|
/*
|
|
|
|
* Assign to all categories. Note that this includes
|
|
|
|
* the default channel.
|
|
|
|
*/
|
2020-03-13 15:16:14 +01:00
|
|
|
for (size_t i = 0; i < lctx->category_count; i++) {
|
2020-03-18 14:17:55 +11:00
|
|
|
assignchannel(lcfg, i, module, channel);
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-03-18 14:17:55 +11:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-12-12 05:29:33 +00:00
|
|
|
isc_log_write(isc_log_t *lctx, isc_logcategory_t *category,
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_logmodule_t *module, int level, const char *format, ...) {
|
1999-09-23 17:43:51 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
/*
|
1999-10-25 19:55:06 +00:00
|
|
|
* Contract checking is done in isc_log_doit().
|
1999-09-23 17:43:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
va_start(args, format);
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_log_doit(lctx, category, module, level, false, format, args);
|
1999-09-23 17:43:51 +00:00
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
1999-10-25 19:55:06 +00:00
|
|
|
void
|
2000-12-12 05:29:33 +00:00
|
|
|
isc_log_vwrite(isc_log_t *lctx, isc_logcategory_t *category,
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_logmodule_t *module, int level, const char *format,
|
2020-02-13 14:44:37 -08:00
|
|
|
va_list args) {
|
1999-10-25 19:55:06 +00:00
|
|
|
/*
|
|
|
|
* Contract checking is done in isc_log_doit().
|
|
|
|
*/
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_log_doit(lctx, category, module, level, false, format, args);
|
1999-10-25 19:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-12-12 05:29:33 +00:00
|
|
|
isc_log_write1(isc_log_t *lctx, isc_logcategory_t *category,
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_logmodule_t *module, int level, const char *format, ...) {
|
1999-10-25 19:55:06 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Contract checking is done in isc_log_doit().
|
|
|
|
*/
|
|
|
|
|
|
|
|
va_start(args, format);
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_log_doit(lctx, category, module, level, true, format, args);
|
1999-10-25 19:55:06 +00:00
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-12-12 05:29:33 +00:00
|
|
|
isc_log_vwrite1(isc_log_t *lctx, isc_logcategory_t *category,
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_logmodule_t *module, int level, const char *format,
|
2020-02-13 14:44:37 -08:00
|
|
|
va_list args) {
|
2000-12-07 19:30:28 +00:00
|
|
|
/*
|
|
|
|
* Contract checking is done in isc_log_doit().
|
|
|
|
*/
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_log_doit(lctx, category, module, level, true, format, args);
|
1999-10-25 19:55:06 +00:00
|
|
|
}
|
|
|
|
|
2000-05-03 21:09:34 +00:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_log_setcontext(isc_log_t *lctx) {
|
2000-05-03 21:09:34 +00:00
|
|
|
isc_lctx = lctx;
|
|
|
|
}
|
|
|
|
|
1999-09-23 17:43:51 +00:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_log_setdebuglevel(isc_log_t *lctx, unsigned int level) {
|
1999-09-23 17:43:51 +00:00
|
|
|
REQUIRE(VALID_CONTEXT(lctx));
|
2002-06-03 03:39:56 +00:00
|
|
|
|
1999-09-23 17:43:51 +00:00
|
|
|
lctx->debug_level = level;
|
2001-06-08 02:57:13 +00:00
|
|
|
/*
|
|
|
|
* Close ISC_LOG_DEBUGONLY channels if level is zero.
|
|
|
|
*/
|
2020-03-13 15:16:14 +01:00
|
|
|
if (level == 0) {
|
|
|
|
RDLOCK(&lctx->lcfg_rwl);
|
|
|
|
isc_logconfig_t *lcfg = lctx->logconfig;
|
2019-12-20 19:29:18 -03:00
|
|
|
if (lcfg != NULL) {
|
2020-03-13 15:16:14 +01:00
|
|
|
LOCK(&lctx->lock);
|
|
|
|
for (isc_logchannel_t *channel =
|
|
|
|
ISC_LIST_HEAD(lcfg->channels);
|
2019-12-20 19:29:18 -03:00
|
|
|
channel != NULL;
|
|
|
|
channel = ISC_LIST_NEXT(channel, link))
|
2020-02-13 14:44:37 -08:00
|
|
|
{
|
2019-12-20 19:29:18 -03:00
|
|
|
if (channel->type == ISC_LOG_TOFILE &&
|
|
|
|
(channel->flags & ISC_LOG_DEBUGONLY) != 0 &&
|
|
|
|
FILE_STREAM(channel) != NULL)
|
2020-02-13 18:16:57 +01:00
|
|
|
{
|
|
|
|
(void)fclose(FILE_STREAM(channel));
|
|
|
|
FILE_STREAM(channel) = NULL;
|
|
|
|
}
|
2001-06-08 02:57:13 +00:00
|
|
|
}
|
2020-03-13 15:16:14 +01:00
|
|
|
UNLOCK(&lctx->lock);
|
2020-02-13 18:16:57 +01:00
|
|
|
}
|
2020-03-24 14:50:31 +11:00
|
|
|
RDUNLOCK(&lctx->lcfg_rwl);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_log_getdebuglevel(isc_log_t *lctx) {
|
1999-09-23 17:43:51 +00:00
|
|
|
REQUIRE(VALID_CONTEXT(lctx));
|
|
|
|
|
|
|
|
return (lctx->debug_level);
|
|
|
|
}
|
|
|
|
|
1999-10-25 19:55:06 +00:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_log_setduplicateinterval(isc_logconfig_t *lcfg, unsigned int interval) {
|
2000-02-26 19:57:02 +00:00
|
|
|
REQUIRE(VALID_CONFIG(lcfg));
|
1999-10-25 19:55:06 +00:00
|
|
|
|
2000-02-26 19:57:02 +00:00
|
|
|
lcfg->duplicate_interval = interval;
|
1999-10-25 19:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_log_getduplicateinterval(isc_logconfig_t *lcfg) {
|
2000-02-26 19:57:02 +00:00
|
|
|
REQUIRE(VALID_CONTEXT(lcfg));
|
1999-10-25 19:55:06 +00:00
|
|
|
|
2000-02-26 19:57:02 +00:00
|
|
|
return (lcfg->duplicate_interval);
|
1999-10-25 19:55:06 +00:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-03-18 14:17:55 +11:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_log_settag(isc_logconfig_t *lcfg, const char *tag) {
|
2000-05-16 03:37:39 +00:00
|
|
|
REQUIRE(VALID_CONFIG(lcfg));
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-06-01 17:20:56 +00:00
|
|
|
if (tag != NULL && *tag != '\0') {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (lcfg->tag != NULL) {
|
2002-01-09 06:16:10 +00:00
|
|
|
isc_mem_free(lcfg->lctx->mctx, lcfg->tag);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-01 17:20:56 +00:00
|
|
|
lcfg->tag = isc_mem_strdup(lcfg->lctx->mctx, tag);
|
|
|
|
} else {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (lcfg->tag != NULL) {
|
2000-06-01 17:20:56 +00:00
|
|
|
isc_mem_free(lcfg->lctx->mctx, lcfg->tag);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-05-16 03:37:39 +00:00
|
|
|
lcfg->tag = NULL;
|
2000-06-01 17:20:56 +00:00
|
|
|
}
|
2000-05-16 03:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_log_gettag(isc_logconfig_t *lcfg) {
|
2000-05-16 03:37:39 +00:00
|
|
|
REQUIRE(VALID_CONFIG(lcfg));
|
|
|
|
|
|
|
|
return (lcfg->tag);
|
|
|
|
}
|
|
|
|
|
1999-09-23 17:43:51 +00:00
|
|
|
/* XXXDCL NT -- This interface will assuredly be changing. */
|
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_log_opensyslog(const char *tag, int options, int facility) {
|
2001-11-30 01:59:49 +00:00
|
|
|
(void)openlog(tag, options, facility);
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_log_closefilelogs(isc_log_t *lctx) {
|
1999-09-23 17:43:51 +00:00
|
|
|
REQUIRE(VALID_CONTEXT(lctx));
|
|
|
|
|
2020-03-13 15:16:14 +01:00
|
|
|
RDLOCK(&lctx->lcfg_rwl);
|
|
|
|
isc_logconfig_t *lcfg = lctx->logconfig;
|
2019-12-20 19:29:18 -03:00
|
|
|
if (lcfg != NULL) {
|
2020-03-13 15:16:14 +01:00
|
|
|
LOCK(&lctx->lock);
|
|
|
|
for (isc_logchannel_t *channel = ISC_LIST_HEAD(lcfg->channels);
|
|
|
|
channel != NULL; channel = ISC_LIST_NEXT(channel, link))
|
2019-12-20 19:29:18 -03:00
|
|
|
{
|
|
|
|
if (channel->type == ISC_LOG_TOFILE &&
|
|
|
|
FILE_STREAM(channel) != NULL) {
|
2020-02-13 18:16:57 +01:00
|
|
|
(void)fclose(FILE_STREAM(channel));
|
|
|
|
FILE_STREAM(channel) = NULL;
|
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
2020-03-13 15:16:14 +01:00
|
|
|
UNLOCK(&lctx->lock);
|
2020-02-13 18:16:57 +01:00
|
|
|
}
|
2020-03-13 15:16:14 +01:00
|
|
|
RDUNLOCK(&lctx->lcfg_rwl);
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
2020-02-13 21:48:23 +01:00
|
|
|
**** Internal functions
|
|
|
|
****/
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-03-18 14:17:55 +11:00
|
|
|
static void
|
2000-02-26 19:57:02 +00:00
|
|
|
assignchannel(isc_logconfig_t *lcfg, unsigned int category_id,
|
2020-02-13 14:44:37 -08:00
|
|
|
const isc_logmodule_t *module, isc_logchannel_t *channel) {
|
1999-09-23 17:43:51 +00:00
|
|
|
isc_logchannellist_t *new_item;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_log_t *lctx;
|
2000-02-26 19:57:02 +00:00
|
|
|
|
|
|
|
REQUIRE(VALID_CONFIG(lcfg));
|
|
|
|
|
|
|
|
lctx = lcfg->lctx;
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
REQUIRE(category_id < lctx->category_count);
|
|
|
|
REQUIRE(module == NULL || module->id < lctx->module_count);
|
|
|
|
REQUIRE(channel != NULL);
|
|
|
|
|
2000-02-26 19:57:02 +00:00
|
|
|
/*
|
|
|
|
* Ensure lcfg->channellist_count == lctx->category_count.
|
|
|
|
*/
|
2020-03-18 14:17:55 +11:00
|
|
|
sync_channellist(lcfg);
|
2000-02-26 19:57:02 +00:00
|
|
|
|
2000-03-01 17:31:56 +00:00
|
|
|
new_item = isc_mem_get(lctx->mctx, sizeof(*new_item));
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
new_item->channel = channel;
|
|
|
|
new_item->module = module;
|
2020-02-12 13:59:18 +01:00
|
|
|
ISC_LIST_INITANDPREPEND(lcfg->channellists[category_id], new_item,
|
|
|
|
link);
|
2000-02-26 19:57:02 +00:00
|
|
|
|
2000-04-06 20:32:31 +00:00
|
|
|
/*
|
|
|
|
* Remember the highest logging level set by any channel in the
|
|
|
|
* logging config, so isc_log_doit() can quickly return if the
|
|
|
|
* message is too high to be logged by any channel.
|
|
|
|
*/
|
2000-04-11 18:22:34 +00:00
|
|
|
if (channel->type != ISC_LOG_TONULL) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (lcfg->highest_level < channel->level) {
|
2000-04-06 20:32:31 +00:00
|
|
|
lcfg->highest_level = channel->level;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (channel->level == ISC_LOG_DYNAMIC) {
|
2018-04-17 08:29:14 -07:00
|
|
|
lcfg->dynamic = true;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-04-06 20:32:31 +00:00
|
|
|
}
|
2000-02-26 19:57:02 +00:00
|
|
|
}
|
|
|
|
|
2000-05-24 02:33:16 +00:00
|
|
|
/*
|
|
|
|
* This would ideally be part of isc_log_registercategories(), except then
|
|
|
|
* that function would have to return isc_result_t instead of void.
|
|
|
|
*/
|
2020-03-18 14:17:55 +11:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
sync_channellist(isc_logconfig_t *lcfg) {
|
2000-06-01 17:20:56 +00:00
|
|
|
unsigned int bytes;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_log_t *lctx;
|
|
|
|
void *lists;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-02-26 19:57:02 +00:00
|
|
|
REQUIRE(VALID_CONFIG(lcfg));
|
|
|
|
|
|
|
|
lctx = lcfg->lctx;
|
|
|
|
|
|
|
|
REQUIRE(lctx->category_count != 0);
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (lctx->category_count == lcfg->channellist_count) {
|
2020-03-18 14:17:55 +11:00
|
|
|
return;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-02-26 19:57:02 +00:00
|
|
|
|
2000-03-01 17:31:56 +00:00
|
|
|
bytes = lctx->category_count * sizeof(ISC_LIST(isc_logchannellist_t));
|
2000-02-26 19:57:02 +00:00
|
|
|
|
2000-03-01 17:31:56 +00:00
|
|
|
lists = isc_mem_get(lctx->mctx, bytes);
|
2000-02-26 19:57:02 +00:00
|
|
|
|
|
|
|
memset(lists, 0, bytes);
|
|
|
|
|
|
|
|
if (lcfg->channellist_count != 0) {
|
|
|
|
bytes = lcfg->channellist_count *
|
2000-03-01 17:31:56 +00:00
|
|
|
sizeof(ISC_LIST(isc_logchannellist_t));
|
2014-01-08 16:27:10 -08:00
|
|
|
memmove(lists, lcfg->channellists, bytes);
|
2000-02-26 19:57:02 +00:00
|
|
|
isc_mem_put(lctx->mctx, lcfg->channellists, bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
lcfg->channellists = lists;
|
|
|
|
lcfg->channellist_count = lctx->category_count;
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
|
|
|
|
2001-04-25 23:59:44 +00:00
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
greatest_version(isc_logfile_t *file, int versions, int *greatestp) {
|
|
|
|
char *bname, *digit_end;
|
|
|
|
const char *dirname;
|
|
|
|
int version, greatest = -1;
|
|
|
|
size_t bnamelen;
|
|
|
|
isc_dir_t dir;
|
1999-09-23 17:43:51 +00:00
|
|
|
isc_result_t result;
|
2020-02-13 14:44:37 -08:00
|
|
|
char sep = '/';
|
2004-06-04 02:19:17 +00:00
|
|
|
#ifdef _WIN32
|
2016-06-28 21:25:30 -04:00
|
|
|
char *bname2;
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef _WIN32 */
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2000-06-01 17:20:56 +00:00
|
|
|
/*
|
|
|
|
* It is safe to DE_CONST the file.name because it was copied
|
2016-07-13 01:12:47 -07:00
|
|
|
* with isc_mem_strdup().
|
2000-06-01 17:20:56 +00:00
|
|
|
*/
|
2016-07-13 01:12:47 -07:00
|
|
|
bname = strrchr(file->name, sep);
|
2004-06-04 02:19:17 +00:00
|
|
|
#ifdef _WIN32
|
2016-07-13 01:12:47 -07:00
|
|
|
bname2 = strrchr(file->name, '\\');
|
2016-06-28 21:25:30 -04:00
|
|
|
if ((bname != NULL && bname2 != NULL && bname2 > bname) ||
|
2020-02-13 14:44:37 -08:00
|
|
|
(bname == NULL && bname2 != NULL))
|
|
|
|
{
|
2016-06-28 21:25:30 -04:00
|
|
|
bname = bname2;
|
2004-06-04 02:19:17 +00:00
|
|
|
sep = '\\';
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef _WIN32 */
|
2016-06-28 21:25:30 -04:00
|
|
|
if (bname != NULL) {
|
|
|
|
*bname++ = '\0';
|
2016-07-13 01:12:47 -07:00
|
|
|
dirname = file->name;
|
1999-09-23 17:43:51 +00:00
|
|
|
} else {
|
2016-07-13 01:12:47 -07:00
|
|
|
DE_CONST(file->name, bname);
|
1999-09-23 17:43:51 +00:00
|
|
|
dirname = ".";
|
|
|
|
}
|
2016-06-28 21:25:30 -04:00
|
|
|
bnamelen = strlen(bname);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
isc_dir_init(&dir);
|
1999-10-31 19:09:23 +00:00
|
|
|
result = isc_dir_open(&dir, dirname);
|
2001-04-25 23:59:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Replace the file separator if it was taken out.
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
if (bname != file->name) {
|
2016-06-28 21:25:30 -04:00
|
|
|
*(bname - 1) = sep;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-04-25 23:59:44 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return if the directory open failed.
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2001-04-25 23:59:44 +00:00
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
while (isc_dir_read(&dir) == ISC_R_SUCCESS) {
|
2016-06-28 21:25:30 -04:00
|
|
|
if (dir.entry.length > bnamelen &&
|
|
|
|
strncmp(dir.entry.name, bname, bnamelen) == 0 &&
|
2020-02-13 14:44:37 -08:00
|
|
|
dir.entry.name[bnamelen] == '.')
|
|
|
|
{
|
2016-06-28 21:25:30 -04:00
|
|
|
version = strtol(&dir.entry.name[bnamelen + 1],
|
2001-04-28 01:08:07 +00:00
|
|
|
&digit_end, 10);
|
2016-11-30 10:55:21 +11:00
|
|
|
/*
|
|
|
|
* Remove any backup files that exceed versions.
|
|
|
|
*/
|
|
|
|
if (*digit_end == '\0' && version >= versions) {
|
|
|
|
result = isc_file_remove(dir.entry.name);
|
|
|
|
if (result != ISC_R_SUCCESS &&
|
2020-02-13 21:48:23 +01:00
|
|
|
result != ISC_R_FILENOTFOUND) {
|
2020-02-12 13:59:18 +01:00
|
|
|
syslog(LOG_ERR,
|
|
|
|
"unable to remove "
|
2016-11-30 10:55:21 +11:00
|
|
|
"log file '%s': %s",
|
|
|
|
dir.entry.name,
|
|
|
|
isc_result_totext(result));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
} else if (*digit_end == '\0' && version > greatest) {
|
1999-09-23 17:43:51 +00:00
|
|
|
greatest = version;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
|
|
|
}
|
2000-08-31 20:58:15 +00:00
|
|
|
isc_dir_close(&dir);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2016-11-30 10:55:21 +11:00
|
|
|
*greatestp = greatest;
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2001-04-25 23:59:44 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 23:20:40 -08:00
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
remove_old_tsversions(isc_logfile_t *file, int versions) {
|
2001-04-25 23:59:44 +00:00
|
|
|
isc_result_t result;
|
2020-02-13 14:44:37 -08:00
|
|
|
char *bname, *digit_end;
|
|
|
|
const char *dirname;
|
|
|
|
int64_t version, last = INT64_MAX;
|
|
|
|
int64_t to_keep[ISC_LOG_MAX_VERSIONS];
|
|
|
|
size_t bnamelen;
|
|
|
|
isc_dir_t dir;
|
|
|
|
char sep = '/';
|
2017-03-08 23:20:40 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
char *bname2;
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef _WIN32 */
|
2017-03-08 23:20:40 -08:00
|
|
|
/*
|
|
|
|
* It is safe to DE_CONST the file.name because it was copied
|
|
|
|
* with isc_mem_strdup().
|
|
|
|
*/
|
|
|
|
bname = strrchr(file->name, sep);
|
|
|
|
#ifdef _WIN32
|
|
|
|
bname2 = strrchr(file->name, '\\');
|
|
|
|
if ((bname != NULL && bname2 != NULL && bname2 > bname) ||
|
2020-02-13 14:44:37 -08:00
|
|
|
(bname == NULL && bname2 != NULL))
|
|
|
|
{
|
2017-03-08 23:20:40 -08:00
|
|
|
bname = bname2;
|
|
|
|
sep = '\\';
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef _WIN32 */
|
2017-03-08 23:20:40 -08:00
|
|
|
if (bname != NULL) {
|
|
|
|
*bname++ = '\0';
|
|
|
|
dirname = file->name;
|
|
|
|
} else {
|
|
|
|
DE_CONST(file->name, bname);
|
|
|
|
dirname = ".";
|
|
|
|
}
|
|
|
|
bnamelen = strlen(bname);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2017-03-08 23:20:40 -08:00
|
|
|
isc_dir_init(&dir);
|
|
|
|
result = isc_dir_open(&dir, dirname);
|
2016-07-13 01:12:47 -07:00
|
|
|
|
1999-09-23 17:43:51 +00:00
|
|
|
/*
|
2017-03-08 23:20:40 -08:00
|
|
|
* Replace the file separator if it was taken out.
|
1999-09-23 17:43:51 +00:00
|
|
|
*/
|
2017-03-08 23:20:40 -08:00
|
|
|
if (bname != file->name) {
|
|
|
|
*(bname - 1) = sep;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return if the directory open failed.
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2017-03-08 23:20:40 -08:00
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2017-03-08 23:20:40 -08:00
|
|
|
|
|
|
|
if (versions > 0) {
|
|
|
|
/*
|
|
|
|
* First we fill 'to_keep' structure using insertion sort
|
|
|
|
*/
|
|
|
|
memset(to_keep, 0, versions * sizeof(long long));
|
|
|
|
while (isc_dir_read(&dir) == ISC_R_SUCCESS) {
|
|
|
|
if (dir.entry.length > bnamelen &&
|
|
|
|
strncmp(dir.entry.name, bname, bnamelen) == 0 &&
|
2020-02-13 14:44:37 -08:00
|
|
|
dir.entry.name[bnamelen] == '.')
|
|
|
|
{
|
2017-03-09 15:17:10 -08:00
|
|
|
char *ename = &dir.entry.name[bnamelen + 1];
|
2018-03-21 16:09:08 +00:00
|
|
|
version = strtoull(ename, &digit_end, 10);
|
2017-03-08 23:20:40 -08:00
|
|
|
if (*digit_end == '\0') {
|
|
|
|
int i = 0;
|
2018-02-15 13:20:59 +11:00
|
|
|
while (i < versions &&
|
2020-02-12 13:59:18 +01:00
|
|
|
version < to_keep[i]) {
|
2017-03-08 23:20:40 -08:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (i < versions) {
|
|
|
|
memmove(&to_keep[i + 1],
|
|
|
|
&to_keep[i],
|
|
|
|
sizeof(long long) *
|
2020-02-12 13:59:18 +01:00
|
|
|
versions -
|
|
|
|
i - 1);
|
2017-03-08 23:20:40 -08:00
|
|
|
to_keep[i] = version;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* to_keep[versions - 1] is the last one we want to keep
|
|
|
|
*/
|
|
|
|
last = to_keep[versions - 1];
|
|
|
|
isc_dir_reset(&dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Then we remove all files that we don't want to_keep
|
|
|
|
*/
|
|
|
|
while (isc_dir_read(&dir) == ISC_R_SUCCESS) {
|
|
|
|
if (dir.entry.length > bnamelen &&
|
|
|
|
strncmp(dir.entry.name, bname, bnamelen) == 0 &&
|
2020-02-13 14:44:37 -08:00
|
|
|
dir.entry.name[bnamelen] == '.')
|
|
|
|
{
|
2017-03-09 15:17:10 -08:00
|
|
|
char *ename = &dir.entry.name[bnamelen + 1];
|
2018-03-21 16:09:08 +00:00
|
|
|
version = strtoull(ename, &digit_end, 10);
|
2017-03-08 23:20:40 -08:00
|
|
|
/*
|
|
|
|
* Remove any backup files that exceed versions.
|
|
|
|
*/
|
|
|
|
if (*digit_end == '\0' && version < last) {
|
|
|
|
result = isc_file_remove(dir.entry.name);
|
|
|
|
if (result != ISC_R_SUCCESS &&
|
2020-02-13 21:48:23 +01:00
|
|
|
result != ISC_R_FILENOTFOUND) {
|
2020-02-12 13:59:18 +01:00
|
|
|
syslog(LOG_ERR,
|
|
|
|
"unable to remove "
|
2017-03-08 23:20:40 -08:00
|
|
|
"log file '%s': %s",
|
|
|
|
dir.entry.name,
|
|
|
|
isc_result_totext(result));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2017-03-08 23:20:40 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_dir_close(&dir);
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
roll_increment(isc_logfile_t *file) {
|
|
|
|
int i, n, greatest;
|
|
|
|
char current[PATH_MAX + 1];
|
|
|
|
char newpath[PATH_MAX + 1];
|
|
|
|
const char *path;
|
2017-03-08 23:20:40 -08:00
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
|
|
|
|
REQUIRE(file != NULL);
|
|
|
|
REQUIRE(file->versions != 0);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2016-07-13 01:12:47 -07:00
|
|
|
path = file->name;
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2016-11-30 10:55:21 +11:00
|
|
|
if (file->versions == ISC_LOG_ROLLINFINITE) {
|
1999-09-23 17:43:51 +00:00
|
|
|
/*
|
2016-11-30 10:55:21 +11:00
|
|
|
* Find the first missing entry in the log file sequence.
|
1999-09-23 17:43:51 +00:00
|
|
|
*/
|
2016-11-30 10:55:21 +11:00
|
|
|
for (greatest = 0; greatest < INT_MAX; greatest++) {
|
2020-02-12 13:59:18 +01:00
|
|
|
n = snprintf(current, sizeof(current), "%s.%u", path,
|
|
|
|
(unsigned)greatest);
|
2017-03-08 23:20:40 -08:00
|
|
|
if (n >= (int)sizeof(current) || n < 0 ||
|
2020-02-12 13:59:18 +01:00
|
|
|
!isc_file_exists(current)) {
|
2016-11-30 10:55:21 +11:00
|
|
|
break;
|
2017-03-08 23:20:40 -08:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
2016-11-30 10:55:21 +11:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Get the largest existing version and remove any
|
|
|
|
* version greater than the permitted version.
|
|
|
|
*/
|
|
|
|
result = greatest_version(file, file->versions, &greatest);
|
2017-03-08 23:20:40 -08:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2016-11-30 10:55:21 +11:00
|
|
|
return (result);
|
2017-03-08 23:20:40 -08:00
|
|
|
}
|
2016-11-30 10:55:21 +11:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Increment if greatest is not the actual maximum value.
|
|
|
|
*/
|
2017-03-08 23:20:40 -08:00
|
|
|
if (greatest < file->versions - 1) {
|
2016-11-30 10:55:21 +11:00
|
|
|
greatest++;
|
2017-03-08 23:20:40 -08:00
|
|
|
}
|
2016-11-30 10:55:21 +11:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
for (i = greatest; i > 0; i--) {
|
2002-10-16 13:15:30 +00:00
|
|
|
result = ISC_R_SUCCESS;
|
2018-02-15 13:20:59 +11:00
|
|
|
n = snprintf(current, sizeof(current), "%s.%u", path,
|
|
|
|
(unsigned)(i - 1));
|
2017-03-08 23:20:40 -08:00
|
|
|
if (n >= (int)sizeof(current) || n < 0) {
|
2002-10-16 13:15:30 +00:00
|
|
|
result = ISC_R_NOSPACE;
|
2017-03-08 23:20:40 -08:00
|
|
|
}
|
2002-10-16 13:15:30 +00:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
n = snprintf(newpath, sizeof(newpath), "%s.%u", path,
|
|
|
|
(unsigned)i);
|
2017-03-08 23:20:40 -08:00
|
|
|
if (n >= (int)sizeof(newpath) || n < 0) {
|
2002-10-16 13:15:30 +00:00
|
|
|
result = ISC_R_NOSPACE;
|
2017-03-08 23:20:40 -08:00
|
|
|
}
|
2002-10-16 13:15:30 +00:00
|
|
|
}
|
2017-03-08 23:20:40 -08:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
result = isc_file_rename(current, newpath);
|
|
|
|
}
|
|
|
|
if (result != ISC_R_SUCCESS && result != ISC_R_FILENOTFOUND) {
|
2002-10-16 13:15:30 +00:00
|
|
|
syslog(LOG_ERR,
|
2016-11-30 10:55:21 +11:00
|
|
|
"unable to rename log file '%s.%u' to "
|
2020-02-12 13:59:18 +01:00
|
|
|
"'%s.%u': %s",
|
|
|
|
path, i - 1, path, i, isc_result_totext(result));
|
2017-03-08 23:20:40 -08:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 23:20:40 -08:00
|
|
|
n = snprintf(newpath, sizeof(newpath), "%s.0", path);
|
|
|
|
if (n >= (int)sizeof(newpath) || n < 0) {
|
|
|
|
result = ISC_R_NOSPACE;
|
|
|
|
} else {
|
|
|
|
result = isc_file_rename(path, newpath);
|
|
|
|
}
|
|
|
|
if (result != ISC_R_SUCCESS && result != ISC_R_FILENOTFOUND) {
|
2020-02-12 13:59:18 +01:00
|
|
|
syslog(LOG_ERR, "unable to rename log file '%s' to '%s.0': %s",
|
2017-03-08 23:20:40 -08:00
|
|
|
path, path, isc_result_totext(result));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
roll_timestamp(isc_logfile_t *file) {
|
|
|
|
int n;
|
|
|
|
char newts[PATH_MAX + 1];
|
|
|
|
char newpath[PATH_MAX + 1];
|
|
|
|
const char *path;
|
|
|
|
isc_time_t now;
|
2017-03-08 23:20:40 -08:00
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
|
|
|
|
REQUIRE(file != NULL);
|
|
|
|
REQUIRE(file->versions != 0);
|
|
|
|
|
|
|
|
path = file->name;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First find all the logfiles and remove the oldest ones
|
|
|
|
* Save one fewer than file->versions because we'll be renaming
|
|
|
|
* the existing file to a timestamped version after this.
|
|
|
|
*/
|
|
|
|
if (file->versions != ISC_LOG_ROLLINFINITE) {
|
|
|
|
remove_old_tsversions(file, file->versions - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then just rename the current logfile */
|
|
|
|
isc_time_now(&now);
|
|
|
|
isc_time_formatshorttimestamp(&now, newts, PATH_MAX + 1);
|
|
|
|
n = snprintf(newpath, sizeof(newpath), "%s.%s", path, newts);
|
|
|
|
if (n >= (int)sizeof(newpath) || n < 0) {
|
|
|
|
result = ISC_R_NOSPACE;
|
2002-10-16 13:15:30 +00:00
|
|
|
} else {
|
2017-03-08 23:20:40 -08:00
|
|
|
result = isc_file_rename(path, newpath);
|
|
|
|
}
|
|
|
|
if (result != ISC_R_SUCCESS && result != ISC_R_FILENOTFOUND) {
|
2020-02-12 13:59:18 +01:00
|
|
|
syslog(LOG_ERR, "unable to rename log file '%s' to '%s.0': %s",
|
2017-03-08 23:20:40 -08:00
|
|
|
path, path, isc_result_totext(result));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_logfile_roll(isc_logfile_t *file) {
|
2017-03-08 23:20:40 -08:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
REQUIRE(file != NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do nothing (not even excess version trimming) if ISC_LOG_ROLLNEVER
|
|
|
|
* is specified. Apparently complete external control over the log
|
|
|
|
* files is desired.
|
|
|
|
*/
|
|
|
|
if (file->versions == ISC_LOG_ROLLNEVER) {
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
} else if (file->versions == 0) {
|
|
|
|
result = isc_file_remove(file->name);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS && result != ISC_R_FILENOTFOUND) {
|
2002-10-16 13:15:30 +00:00
|
|
|
syslog(LOG_ERR, "unable to remove log file '%s': %s",
|
2017-03-08 23:20:40 -08:00
|
|
|
file->name, isc_result_totext(result));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2017-03-08 23:20:40 -08:00
|
|
|
return (ISC_R_SUCCESS);
|
2002-10-16 13:15:30 +00:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2017-03-08 23:20:40 -08:00
|
|
|
switch (file->suffix) {
|
|
|
|
case isc_log_rollsuffix_increment:
|
|
|
|
return (roll_increment(file));
|
|
|
|
case isc_log_rollsuffix_timestamp:
|
|
|
|
return (roll_timestamp(file));
|
|
|
|
default:
|
|
|
|
return (ISC_R_UNEXPECTED);
|
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_log_open(isc_logchannel_t *channel) {
|
|
|
|
struct stat statbuf;
|
|
|
|
bool regular_file;
|
|
|
|
bool roll = false;
|
2001-03-28 04:16:32 +00:00
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
2020-02-13 14:44:37 -08:00
|
|
|
const char *path;
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
REQUIRE(channel->type == ISC_LOG_TOFILE);
|
|
|
|
REQUIRE(FILE_STREAM(channel) == NULL);
|
|
|
|
|
|
|
|
path = FILE_NAME(channel);
|
|
|
|
|
|
|
|
REQUIRE(path != NULL && *path != '\0');
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine type of file; only regular files will be
|
2001-03-28 04:16:32 +00:00
|
|
|
* version renamed, and only if the base file exists
|
|
|
|
* and either has no size limit or has reached its size limit.
|
1999-09-23 17:43:51 +00:00
|
|
|
*/
|
2001-03-28 04:16:32 +00:00
|
|
|
if (stat(path, &statbuf) == 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
regular_file = S_ISREG(statbuf.st_mode) ? true : false;
|
2001-03-28 04:16:32 +00:00
|
|
|
/* XXXDCL if not regular_file complain? */
|
2004-06-11 00:36:30 +00:00
|
|
|
if ((FILE_MAXSIZE(channel) == 0 &&
|
|
|
|
FILE_VERSIONS(channel) != ISC_LOG_ROLLNEVER) ||
|
|
|
|
(FILE_MAXSIZE(channel) > 0 &&
|
2020-02-13 14:44:37 -08:00
|
|
|
statbuf.st_size >= FILE_MAXSIZE(channel)))
|
|
|
|
{
|
2004-06-11 00:36:30 +00:00
|
|
|
roll = regular_file;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2011-03-11 06:11:27 +00:00
|
|
|
} else if (errno == ENOENT) {
|
2018-04-17 08:29:14 -07:00
|
|
|
regular_file = true;
|
2011-03-11 06:11:27 +00:00
|
|
|
POST(regular_file);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2001-03-28 04:16:32 +00:00
|
|
|
result = ISC_R_INVALIDFILE;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Version control.
|
|
|
|
*/
|
2001-03-28 04:16:32 +00:00
|
|
|
if (result == ISC_R_SUCCESS && roll) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (FILE_VERSIONS(channel) == ISC_LOG_ROLLNEVER) {
|
2004-03-03 05:39:05 +00:00
|
|
|
return (ISC_R_MAXSIZE);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2016-07-13 01:12:47 -07:00
|
|
|
result = isc_logfile_roll(&channel->destination.file);
|
2002-10-16 13:15:30 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
if ((channel->flags & ISC_LOG_OPENERR) == 0) {
|
|
|
|
syslog(LOG_ERR,
|
2016-07-13 01:12:47 -07:00
|
|
|
"isc_log_open: isc_logfile_roll '%s' "
|
2002-10-16 13:15:30 +00:00
|
|
|
"failed: %s",
|
|
|
|
FILE_NAME(channel),
|
|
|
|
isc_result_totext(result));
|
|
|
|
channel->flags |= ISC_LOG_OPENERR;
|
|
|
|
}
|
2001-03-28 04:16:32 +00:00
|
|
|
return (result);
|
2002-10-16 13:15:30 +00:00
|
|
|
}
|
2001-03-28 04:16:32 +00:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2001-03-28 04:16:32 +00:00
|
|
|
result = isc_stdio_open(path, "a", &FILE_STREAM(channel));
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2001-03-28 04:16:32 +00:00
|
|
|
return (result);
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
|
|
|
|
2020-03-13 15:16:14 +01:00
|
|
|
bool
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_log_wouldlog(isc_log_t *lctx, int level) {
|
2020-03-13 15:16:14 +01:00
|
|
|
bool ret = false;
|
2000-07-13 00:19:02 +00:00
|
|
|
/*
|
|
|
|
* Try to avoid locking the mutex for messages which can't
|
|
|
|
* possibly be logged to any channels -- primarily debugging
|
|
|
|
* messages that the debug level is not high enough to print.
|
|
|
|
*
|
|
|
|
* If the level is (mathematically) less than or equal to the
|
2000-08-01 01:33:37 +00:00
|
|
|
* highest_level, or if there is a dynamic channel and the level is
|
2000-07-13 00:19:02 +00:00
|
|
|
* less than or equal to the debug level, the main loop must be
|
|
|
|
* entered to see if the message should really be output.
|
|
|
|
*/
|
2019-12-20 19:29:18 -03:00
|
|
|
if (lctx == NULL) {
|
|
|
|
return (false);
|
|
|
|
}
|
2000-07-13 00:19:02 +00:00
|
|
|
|
2020-03-13 15:16:14 +01:00
|
|
|
RDLOCK(&lctx->lcfg_rwl);
|
|
|
|
isc_logconfig_t *lcfg = lctx->logconfig;
|
|
|
|
if (lcfg != NULL) {
|
|
|
|
ret = (level <= lcfg->highest_level ||
|
|
|
|
(lcfg->dynamic && level <= lctx->debug_level));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2020-03-13 15:16:14 +01:00
|
|
|
RDUNLOCK(&lctx->lcfg_rwl);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2020-03-13 15:16:14 +01:00
|
|
|
return (ret);
|
2000-07-13 00:19:02 +00:00
|
|
|
}
|
|
|
|
|
1999-10-25 19:55:06 +00:00
|
|
|
static void
|
|
|
|
isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category,
|
2018-04-17 08:29:14 -07:00
|
|
|
isc_logmodule_t *module, int level, bool write_once,
|
2020-02-13 14:44:37 -08:00
|
|
|
const char *format, va_list args) {
|
|
|
|
int syslog_level;
|
|
|
|
const char *time_string;
|
|
|
|
char local_time[64];
|
|
|
|
char iso8601z_string[64];
|
|
|
|
char iso8601l_string[64];
|
|
|
|
char level_string[24] = { 0 };
|
|
|
|
struct stat statbuf;
|
|
|
|
bool matched = false;
|
|
|
|
bool printtime, iso8601, utc, printtag, printcolon;
|
|
|
|
bool printcategory, printmodule, printlevel, buffered;
|
|
|
|
isc_logchannel_t *channel;
|
1999-09-23 17:43:51 +00:00
|
|
|
isc_logchannellist_t *category_channels;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_result_t result;
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
REQUIRE(lctx == NULL || VALID_CONTEXT(lctx));
|
2000-05-18 17:56:35 +00:00
|
|
|
REQUIRE(category != NULL);
|
|
|
|
REQUIRE(module != NULL);
|
2000-05-18 17:20:15 +00:00
|
|
|
REQUIRE(level != ISC_LOG_DYNAMIC);
|
|
|
|
REQUIRE(format != NULL);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Programs can use libraries that use this logging code without
|
|
|
|
* wanting to do any logging, thus the log context is allowed to
|
|
|
|
* be non-existent.
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
if (lctx == NULL) {
|
1999-09-23 17:43:51 +00:00
|
|
|
return;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2000-05-18 22:38:49 +00:00
|
|
|
REQUIRE(category->id < lctx->category_count);
|
|
|
|
REQUIRE(module->id < lctx->module_count);
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (!isc_log_wouldlog(lctx, level)) {
|
2000-04-06 20:32:31 +00:00
|
|
|
return;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-04-06 20:32:31 +00:00
|
|
|
|
2016-11-22 23:34:47 -08:00
|
|
|
local_time[0] = '\0';
|
|
|
|
iso8601l_string[0] = '\0';
|
|
|
|
iso8601z_string[0] = '\0';
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-03-13 15:16:14 +01:00
|
|
|
RDLOCK(&lctx->lcfg_rwl);
|
2000-02-26 19:57:02 +00:00
|
|
|
LOCK(&lctx->lock);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2000-08-24 18:21:40 +00:00
|
|
|
lctx->buffer[0] = '\0';
|
2009-01-06 23:47:57 +00:00
|
|
|
|
2020-03-13 15:16:14 +01:00
|
|
|
isc_logconfig_t *lcfg = lctx->logconfig;
|
2000-02-26 19:57:02 +00:00
|
|
|
|
2000-03-01 17:31:56 +00:00
|
|
|
category_channels = ISC_LIST_HEAD(lcfg->channellists[category->id]);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
/*
|
2000-03-01 17:31:56 +00:00
|
|
|
* XXXDCL add duplicate filtering? (To not write multiple times to
|
|
|
|
* the same source via various channels).
|
1999-09-23 17:43:51 +00:00
|
|
|
*/
|
1999-11-03 01:07:02 +00:00
|
|
|
do {
|
1999-10-25 19:55:06 +00:00
|
|
|
/*
|
|
|
|
* If the channel list end was reached and a match was made,
|
|
|
|
* everything is finished.
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
if (category_channels == NULL && matched) {
|
1999-09-23 17:43:51 +00:00
|
|
|
break;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
if (category_channels == NULL && !matched &&
|
2020-02-13 14:44:37 -08:00
|
|
|
category_channels != ISC_LIST_HEAD(lcfg->channellists[0]))
|
|
|
|
{
|
1999-09-23 17:43:51 +00:00
|
|
|
/*
|
|
|
|
* No category/module pair was explicitly configured.
|
|
|
|
* Try the category named "default".
|
|
|
|
*/
|
2000-03-01 17:31:56 +00:00
|
|
|
category_channels =
|
|
|
|
ISC_LIST_HEAD(lcfg->channellists[0]);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (category_channels == NULL && !matched) {
|
1999-09-23 17:43:51 +00:00
|
|
|
/*
|
|
|
|
* No matching module was explicitly configured
|
|
|
|
* for the category named "default". Use the internal
|
|
|
|
* default channel.
|
|
|
|
*/
|
|
|
|
category_channels = &default_channel;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-09-23 17:43:51 +00:00
|
|
|
if (category_channels->module != NULL &&
|
|
|
|
category_channels->module != module) {
|
2020-02-13 14:44:37 -08:00
|
|
|
category_channels = ISC_LIST_NEXT(category_channels,
|
|
|
|
link);
|
1999-09-23 17:43:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
matched = true;
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
channel = category_channels->channel;
|
2000-03-01 17:31:56 +00:00
|
|
|
category_channels = ISC_LIST_NEXT(category_channels, link);
|
|
|
|
|
2000-05-16 03:37:39 +00:00
|
|
|
if (((channel->flags & ISC_LOG_DEBUGONLY) != 0) &&
|
2020-02-13 21:48:23 +01:00
|
|
|
lctx->debug_level == 0) {
|
2000-03-01 17:31:56 +00:00
|
|
|
continue;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
if (channel->level == ISC_LOG_DYNAMIC) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (lctx->debug_level < level) {
|
1999-09-23 17:43:51 +00:00
|
|
|
continue;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
} else if (channel->level < level) {
|
1999-09-23 17:43:51 +00:00
|
|
|
continue;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2000-05-16 03:37:39 +00:00
|
|
|
if ((channel->flags & ISC_LOG_PRINTTIME) != 0 &&
|
2020-02-12 13:59:18 +01:00
|
|
|
local_time[0] == '\0') {
|
2001-11-30 01:59:49 +00:00
|
|
|
isc_time_t isctime;
|
2009-01-06 23:47:57 +00:00
|
|
|
|
2001-11-30 01:59:49 +00:00
|
|
|
TIME_NOW(&isctime);
|
2016-11-22 23:34:47 -08:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_time_formattimestamp(&isctime, local_time,
|
2016-11-22 23:34:47 -08:00
|
|
|
sizeof(local_time));
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_time_formatISO8601ms(&isctime, iso8601z_string,
|
2016-11-22 23:34:47 -08:00
|
|
|
sizeof(iso8601z_string));
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_time_formatISO8601Lms(&isctime, iso8601l_string,
|
2016-11-22 23:34:47 -08:00
|
|
|
sizeof(iso8601l_string));
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
|
|
|
|
2000-05-16 03:37:39 +00:00
|
|
|
if ((channel->flags & ISC_LOG_PRINTLEVEL) != 0 &&
|
1999-09-23 17:43:51 +00:00
|
|
|
level_string[0] == '\0') {
|
2018-11-23 21:35:01 +01:00
|
|
|
if (level < ISC_LOG_CRITICAL) {
|
2003-04-11 07:25:31 +00:00
|
|
|
snprintf(level_string, sizeof(level_string),
|
2018-11-23 21:35:01 +01:00
|
|
|
"level %d: ", level);
|
|
|
|
} else if (level > ISC_LOG_DYNAMIC) {
|
2003-04-11 07:25:31 +00:00
|
|
|
snprintf(level_string, sizeof(level_string),
|
|
|
|
"%s %d: ", log_level_strings[0],
|
|
|
|
level);
|
2018-11-23 21:35:01 +01:00
|
|
|
} else {
|
2003-04-11 07:25:31 +00:00
|
|
|
snprintf(level_string, sizeof(level_string),
|
|
|
|
"%s: ", log_level_strings[-level]);
|
2018-11-23 21:35:01 +01:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-10-11 14:50:51 +00:00
|
|
|
* Only format the message once.
|
1999-09-23 17:43:51 +00:00
|
|
|
*/
|
1999-10-25 19:55:06 +00:00
|
|
|
if (lctx->buffer[0] == '\0') {
|
1999-10-11 14:50:51 +00:00
|
|
|
(void)vsnprintf(lctx->buffer, sizeof(lctx->buffer),
|
2018-11-23 21:35:01 +01:00
|
|
|
format, args);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
1999-10-25 19:55:06 +00:00
|
|
|
/*
|
|
|
|
* Check for duplicates.
|
|
|
|
*/
|
|
|
|
if (write_once) {
|
2017-07-21 11:52:24 +10:00
|
|
|
isc_logmessage_t *message, *next;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_time_t oldest;
|
|
|
|
isc_interval_t interval;
|
|
|
|
size_t size;
|
1999-10-25 19:55:06 +00:00
|
|
|
|
|
|
|
isc_interval_set(&interval,
|
2000-02-26 19:57:02 +00:00
|
|
|
lcfg->duplicate_interval, 0);
|
1999-10-25 19:55:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 'oldest' is the age of the oldest messages
|
|
|
|
* which fall within the duplicate_interval
|
|
|
|
* range.
|
|
|
|
*/
|
2001-11-30 01:59:49 +00:00
|
|
|
TIME_NOW(&oldest);
|
2017-07-21 11:52:24 +10:00
|
|
|
if (isc_time_subtract(&oldest, &interval,
|
2020-02-13 14:44:37 -08:00
|
|
|
&oldest) != ISC_R_SUCCESS)
|
|
|
|
{
|
2000-05-18 17:20:15 +00:00
|
|
|
/*
|
|
|
|
* Can't effectively do the checking
|
|
|
|
* without having a valid time.
|
|
|
|
*/
|
1999-10-25 19:55:06 +00:00
|
|
|
message = NULL;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2017-07-21 11:52:24 +10:00
|
|
|
message = ISC_LIST_HEAD(lctx->messages);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-10-25 19:55:06 +00:00
|
|
|
|
|
|
|
while (message != NULL) {
|
|
|
|
if (isc_time_compare(&message->time,
|
|
|
|
&oldest) < 0) {
|
|
|
|
/*
|
|
|
|
* This message is older
|
|
|
|
* than the duplicate_interval,
|
|
|
|
* so it should be dropped from
|
|
|
|
* the history.
|
|
|
|
*
|
2000-02-26 19:57:02 +00:00
|
|
|
* Setting the interval to be
|
1999-10-25 19:55:06 +00:00
|
|
|
* to be longer will obviously
|
2000-08-01 01:33:37 +00:00
|
|
|
* not cause the expired
|
1999-10-25 19:55:06 +00:00
|
|
|
* message to spring back into
|
|
|
|
* existence.
|
|
|
|
*/
|
2017-07-21 11:52:24 +10:00
|
|
|
next = ISC_LIST_NEXT(message,
|
|
|
|
link);
|
2000-02-26 19:57:02 +00:00
|
|
|
|
|
|
|
ISC_LIST_UNLINK(lctx->messages,
|
|
|
|
message, link);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_mem_put(
|
|
|
|
lctx->mctx, message,
|
1999-10-25 19:55:06 +00:00
|
|
|
sizeof(*message) + 1 +
|
2020-02-12 13:59:18 +01:00
|
|
|
strlen(message->text));
|
1999-10-25 19:55:06 +00:00
|
|
|
|
2017-07-21 11:52:24 +10:00
|
|
|
message = next;
|
1999-10-25 19:55:06 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This message is in the duplicate
|
|
|
|
* filtering interval ...
|
|
|
|
*/
|
2020-02-12 13:59:18 +01:00
|
|
|
if (strcmp(lctx->buffer,
|
|
|
|
message->text) == 0) {
|
1999-10-25 19:55:06 +00:00
|
|
|
/*
|
|
|
|
* ... and it is a duplicate.
|
|
|
|
* Unlock the mutex and
|
|
|
|
* get the hell out of Dodge.
|
|
|
|
*/
|
2020-03-13 15:16:14 +01:00
|
|
|
goto unlock;
|
1999-10-25 19:55:06 +00:00
|
|
|
}
|
|
|
|
|
2000-02-26 19:57:02 +00:00
|
|
|
message = ISC_LIST_NEXT(message, link);
|
1999-10-25 19:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It wasn't in the duplicate interval,
|
|
|
|
* so add it to the message list.
|
|
|
|
*/
|
2017-10-03 14:54:19 +11:00
|
|
|
size = sizeof(isc_logmessage_t) +
|
|
|
|
strlen(lctx->buffer) + 1;
|
|
|
|
message = isc_mem_get(lctx->mctx, size);
|
2020-03-18 14:17:55 +11:00
|
|
|
message->text = (char *)(message + 1);
|
|
|
|
size -= sizeof(isc_logmessage_t);
|
|
|
|
strlcpy(message->text, lctx->buffer, size);
|
|
|
|
TIME_NOW(&message->time);
|
|
|
|
ISC_LINK_INIT(message, link);
|
|
|
|
ISC_LIST_APPEND(lctx->messages, message, link);
|
1999-10-25 19:55:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
utc = ((channel->flags & ISC_LOG_UTC) != 0);
|
|
|
|
iso8601 = ((channel->flags & ISC_LOG_ISO8601) != 0);
|
|
|
|
printtime = ((channel->flags & ISC_LOG_PRINTTIME) != 0);
|
|
|
|
printtag = ((channel->flags &
|
|
|
|
(ISC_LOG_PRINTTAG | ISC_LOG_PRINTPREFIX)) != 0 &&
|
|
|
|
lcfg->tag != NULL);
|
|
|
|
printcolon = ((channel->flags & ISC_LOG_PRINTTAG) != 0 &&
|
|
|
|
lcfg->tag != NULL);
|
2018-10-11 11:57:57 +02:00
|
|
|
printcategory = ((channel->flags & ISC_LOG_PRINTCATEGORY) != 0);
|
2020-02-12 13:59:18 +01:00
|
|
|
printmodule = ((channel->flags & ISC_LOG_PRINTMODULE) != 0);
|
|
|
|
printlevel = ((channel->flags & ISC_LOG_PRINTLEVEL) != 0);
|
|
|
|
buffered = ((channel->flags & ISC_LOG_BUFFERED) != 0);
|
2000-05-16 03:37:39 +00:00
|
|
|
|
2016-11-22 23:34:47 -08:00
|
|
|
if (printtime) {
|
|
|
|
if (iso8601) {
|
|
|
|
if (utc) {
|
|
|
|
time_string = iso8601z_string;
|
|
|
|
} else {
|
|
|
|
time_string = iso8601l_string;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
time_string = local_time;
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2016-11-22 23:34:47 -08:00
|
|
|
time_string = "";
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2016-11-22 23:34:47 -08:00
|
|
|
|
1999-09-23 17:43:51 +00:00
|
|
|
switch (channel->type) {
|
|
|
|
case ISC_LOG_TOFILE:
|
2000-12-23 19:23:48 +00:00
|
|
|
if (FILE_MAXREACHED(channel)) {
|
|
|
|
/*
|
|
|
|
* If the file can be rolled, OR
|
|
|
|
* If the file no longer exists, OR
|
|
|
|
* If the file is less than the maximum size,
|
|
|
|
* (such as if it had been renamed and
|
|
|
|
* a new one touched, or it was truncated
|
|
|
|
* in place)
|
|
|
|
* ... then close it to trigger reopening.
|
|
|
|
*/
|
|
|
|
if (FILE_VERSIONS(channel) !=
|
2020-02-12 13:59:18 +01:00
|
|
|
ISC_LOG_ROLLNEVER ||
|
2000-12-23 19:23:48 +00:00
|
|
|
(stat(FILE_NAME(channel), &statbuf) != 0 &&
|
|
|
|
errno == ENOENT) ||
|
2020-02-13 14:44:37 -08:00
|
|
|
statbuf.st_size < FILE_MAXSIZE(channel))
|
|
|
|
{
|
2001-11-30 01:59:49 +00:00
|
|
|
(void)fclose(FILE_STREAM(channel));
|
2000-12-23 19:23:48 +00:00
|
|
|
FILE_STREAM(channel) = NULL;
|
2018-04-17 08:29:14 -07:00
|
|
|
FILE_MAXREACHED(channel) = false;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-12-23 19:23:48 +00:00
|
|
|
/*
|
|
|
|
* Eh, skip it.
|
|
|
|
*/
|
|
|
|
break;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-12-23 19:23:48 +00:00
|
|
|
}
|
|
|
|
|
1999-09-23 17:43:51 +00:00
|
|
|
if (FILE_STREAM(channel) == NULL) {
|
|
|
|
result = isc_log_open(channel);
|
2002-10-16 13:15:30 +00:00
|
|
|
if (result != ISC_R_SUCCESS &&
|
2004-03-03 05:39:05 +00:00
|
|
|
result != ISC_R_MAXSIZE &&
|
2020-02-13 14:44:37 -08:00
|
|
|
(channel->flags & ISC_LOG_OPENERR) == 0)
|
|
|
|
{
|
2002-10-16 13:15:30 +00:00
|
|
|
syslog(LOG_ERR,
|
|
|
|
"isc_log_open '%s' failed: %s",
|
|
|
|
FILE_NAME(channel),
|
|
|
|
isc_result_totext(result));
|
|
|
|
channel->flags |= ISC_LOG_OPENERR;
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
1999-09-23 17:43:51 +00:00
|
|
|
break;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2002-10-16 13:15:30 +00:00
|
|
|
channel->flags &= ~ISC_LOG_OPENERR;
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
|
|
case ISC_LOG_TOFILEDESC:
|
2020-02-12 13:59:18 +01:00
|
|
|
fprintf(FILE_STREAM(channel), "%s%s%s%s%s%s%s%s%s%s\n",
|
|
|
|
printtime ? time_string : "",
|
|
|
|
printtime ? " " : "", printtag ? lcfg->tag : "",
|
|
|
|
printcolon ? ": " : "",
|
|
|
|
printcategory ? category->name : "",
|
|
|
|
printcategory ? ": " : "",
|
|
|
|
printmodule ? (module != NULL ? module->name
|
|
|
|
: "no_module")
|
|
|
|
: "",
|
|
|
|
printmodule ? ": " : "",
|
|
|
|
printlevel ? level_string : "", lctx->buffer);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (!buffered) {
|
2014-10-30 11:37:05 +11:00
|
|
|
fflush(FILE_STREAM(channel));
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the file now exceeds its maximum size
|
2000-12-23 19:23:48 +00:00
|
|
|
* threshold, note it so that it will not be logged
|
|
|
|
* to any more.
|
1999-09-23 17:43:51 +00:00
|
|
|
*/
|
2004-04-10 04:33:36 +00:00
|
|
|
if (FILE_MAXSIZE(channel) > 0) {
|
1999-09-23 17:43:51 +00:00
|
|
|
INSIST(channel->type == ISC_LOG_TOFILE);
|
|
|
|
|
|
|
|
/* XXXDCL NT fstat/fileno */
|
|
|
|
/* XXXDCL complain if fstat fails? */
|
|
|
|
if (fstat(fileno(FILE_STREAM(channel)),
|
|
|
|
&statbuf) >= 0 &&
|
2020-02-13 14:44:37 -08:00
|
|
|
statbuf.st_size > FILE_MAXSIZE(channel))
|
|
|
|
{
|
2018-04-17 08:29:14 -07:00
|
|
|
FILE_MAXREACHED(channel) = true;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ISC_LOG_TOSYSLOG:
|
2020-02-13 21:48:23 +01:00
|
|
|
if (level > 0) {
|
1999-09-23 17:43:51 +00:00
|
|
|
syslog_level = LOG_DEBUG;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else if (level < ISC_LOG_CRITICAL) {
|
1999-09-23 17:43:51 +00:00
|
|
|
syslog_level = LOG_CRIT;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
1999-09-23 17:43:51 +00:00
|
|
|
syslog_level = syslog_map[-level];
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
(void)syslog(
|
|
|
|
FACILITY(channel) | syslog_level,
|
|
|
|
"%s%s%s%s%s%s%s%s%s%s",
|
|
|
|
printtime ? time_string : "",
|
|
|
|
printtime ? " " : "", printtag ? lcfg->tag : "",
|
|
|
|
printcolon ? ": " : "",
|
|
|
|
printcategory ? category->name : "",
|
|
|
|
printcategory ? ": " : "",
|
|
|
|
printmodule ? (module != NULL ? module->name
|
|
|
|
: "no_module")
|
|
|
|
: "",
|
|
|
|
printmodule ? ": " : "",
|
|
|
|
printlevel ? level_string : "", lctx->buffer);
|
1999-09-23 17:43:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ISC_LOG_TONULL:
|
|
|
|
break;
|
|
|
|
}
|
1999-11-03 01:07:02 +00:00
|
|
|
} while (1);
|
1999-09-23 17:43:51 +00:00
|
|
|
|
2020-03-13 15:16:14 +01:00
|
|
|
unlock:
|
2000-02-26 19:57:02 +00:00
|
|
|
UNLOCK(&lctx->lock);
|
2020-03-13 15:16:14 +01:00
|
|
|
RDUNLOCK(&lctx->lcfg_rwl);
|
1999-09-23 17:43:51 +00:00
|
|
|
}
|