mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-02 07:35:26 +00:00
Remove isc_log_write1() and isc_log_vwrite1() functions
The isc_log_write1() and isc_log_vwrite1() functions were meant to de-duplicate the messages sent to the isc_log subsystem. However, they were never used in an entire code base and the whole mechanism around it was complicated and very inefficient. Just remove those, there are better ways to deduplicate syslog messages inside syslog daemons now.
This commit is contained in:
176
lib/isc/log.c
176
lib/isc/log.c
@@ -111,7 +111,6 @@ struct isc_logconfig {
|
||||
ISC_LIST(isc_logchannel_t) channels;
|
||||
ISC_LIST(isc_logchannellist_t) * channellists;
|
||||
unsigned int channellist_count;
|
||||
unsigned int duplicate_interval;
|
||||
int_fast32_t highest_level;
|
||||
char *tag;
|
||||
bool dynamic;
|
||||
@@ -124,7 +123,7 @@ struct isc_logconfig {
|
||||
* to the buffer into which the message is formatted and to guard against
|
||||
* competing threads trying to write to the same syslog resource.
|
||||
*
|
||||
* FIXME: We can remove the locking by using per-thread .buffer and .messages.
|
||||
* FIXME: We can remove the locking by using per-thread .buffer.
|
||||
*/
|
||||
struct isc_log {
|
||||
/* Not locked. */
|
||||
@@ -140,7 +139,6 @@ struct isc_log {
|
||||
isc_mutex_t lock;
|
||||
/* Locked by isc_log lock. */
|
||||
char buffer[LOG_BUFFER_SIZE];
|
||||
ISC_LIST(isc_logmessage_t) messages;
|
||||
atomic_bool dynamic;
|
||||
atomic_int_fast32_t highest_level;
|
||||
};
|
||||
@@ -212,8 +210,8 @@ greatest_version(isc_logfile_t *file, int versions, int *greatest);
|
||||
|
||||
static void
|
||||
isc_log_doit(isc_log_t *__lctx ISC_ATTR_UNUSED, isc_logcategory_t *category,
|
||||
isc_logmodule_t *module, int level, bool write_once,
|
||||
const char *format, va_list args) ISC_FORMAT_PRINTF(6, 0);
|
||||
isc_logmodule_t *module, int level, const char *format,
|
||||
va_list args) ISC_FORMAT_PRINTF(5, 0);
|
||||
|
||||
/*@{*/
|
||||
/*!
|
||||
@@ -384,7 +382,6 @@ isc_logconfig_destroy(isc_logconfig_t **lcfgp) {
|
||||
}
|
||||
lcfg->tag = NULL;
|
||||
lcfg->highest_level = 0;
|
||||
lcfg->duplicate_interval = 0;
|
||||
lcfg->magic = 0;
|
||||
|
||||
isc_mem_put(mctx, lcfg, sizeof(*lcfg));
|
||||
@@ -670,7 +667,7 @@ isc_log_write(isc_log_t *__lctx ISC_ATTR_UNUSED, isc_logcategory_t *category,
|
||||
*/
|
||||
|
||||
va_start(args, format);
|
||||
isc_log_doit(NULL, category, module, level, false, format, args);
|
||||
isc_log_doit(NULL, category, module, level, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
@@ -681,31 +678,7 @@ isc_log_vwrite(isc_log_t *__lctx ISC_ATTR_UNUSED, isc_logcategory_t *category,
|
||||
/*
|
||||
* Contract checking is done in isc_log_doit().
|
||||
*/
|
||||
isc_log_doit(NULL, category, module, level, false, format, args);
|
||||
}
|
||||
|
||||
void
|
||||
isc_log_write1(isc_log_t *__lctx ISC_ATTR_UNUSED, isc_logcategory_t *category,
|
||||
isc_logmodule_t *module, int level, const char *format, ...) {
|
||||
va_list args;
|
||||
|
||||
/*
|
||||
* Contract checking is done in isc_log_doit().
|
||||
*/
|
||||
|
||||
va_start(args, format);
|
||||
isc_log_doit(NULL, category, module, level, true, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void
|
||||
isc_log_vwrite1(isc_log_t *__lctx ISC_ATTR_UNUSED, isc_logcategory_t *category,
|
||||
isc_logmodule_t *module, int level, const char *format,
|
||||
va_list args) {
|
||||
/*
|
||||
* Contract checking is done in isc_log_doit().
|
||||
*/
|
||||
isc_log_doit(NULL, category, module, level, true, format, args);
|
||||
isc_log_doit(NULL, category, module, level, format, args);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -747,20 +720,6 @@ isc_log_getdebuglevel(isc_log_t *__lctx ISC_ATTR_UNUSED) {
|
||||
return (atomic_load_acquire(&isc__lctx->debug_level));
|
||||
}
|
||||
|
||||
void
|
||||
isc_log_setduplicateinterval(isc_logconfig_t *lcfg, unsigned int interval) {
|
||||
REQUIRE(VALID_CONFIG(lcfg));
|
||||
|
||||
lcfg->duplicate_interval = interval;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
isc_log_getduplicateinterval(isc_logconfig_t *lcfg) {
|
||||
REQUIRE(VALID_CONTEXT(lcfg));
|
||||
|
||||
return (lcfg->duplicate_interval);
|
||||
}
|
||||
|
||||
void
|
||||
isc_log_settag(isc_logconfig_t *lcfg, const char *tag) {
|
||||
REQUIRE(VALID_CONFIG(lcfg));
|
||||
@@ -1372,8 +1331,8 @@ isc_log_wouldlog(isc_log_t *__lctx ISC_ATTR_UNUSED, int level) {
|
||||
|
||||
static void
|
||||
isc_log_doit(isc_log_t *__lctx ISC_ATTR_UNUSED, isc_logcategory_t *category,
|
||||
isc_logmodule_t *module, int level, bool write_once,
|
||||
const char *format, va_list args) {
|
||||
isc_logmodule_t *module, int level, const char *format,
|
||||
va_list args) {
|
||||
int syslog_level;
|
||||
const char *time_string;
|
||||
char local_time[64];
|
||||
@@ -1528,110 +1487,6 @@ isc_log_doit(isc_log_t *__lctx ISC_ATTR_UNUSED, isc_logcategory_t *category,
|
||||
(void)vsnprintf(isc__lctx->buffer,
|
||||
sizeof(isc__lctx->buffer), format,
|
||||
args);
|
||||
|
||||
/*
|
||||
* Check for duplicates.
|
||||
*/
|
||||
if (write_once) {
|
||||
isc_logmessage_t *message, *next;
|
||||
isc_time_t oldest;
|
||||
isc_interval_t interval;
|
||||
size_t size;
|
||||
|
||||
isc_interval_set(&interval,
|
||||
lcfg->duplicate_interval, 0);
|
||||
|
||||
/*
|
||||
* 'oldest' is the age of the oldest
|
||||
* messages which fall within the
|
||||
* duplicate_interval range.
|
||||
*/
|
||||
oldest = isc_time_now();
|
||||
if (isc_time_subtract(&oldest, &interval,
|
||||
&oldest) != ISC_R_SUCCESS)
|
||||
{
|
||||
/*
|
||||
* Can't effectively do the
|
||||
* checking without having a
|
||||
* valid time.
|
||||
*/
|
||||
message = NULL;
|
||||
} else {
|
||||
message = ISC_LIST_HEAD(
|
||||
isc__lctx->messages);
|
||||
}
|
||||
|
||||
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.
|
||||
*
|
||||
* Setting the interval
|
||||
* to be to be longer
|
||||
* will obviously not
|
||||
* cause the expired
|
||||
* message to spring
|
||||
* back into existence.
|
||||
*/
|
||||
next = ISC_LIST_NEXT(message,
|
||||
link);
|
||||
|
||||
ISC_LIST_UNLINK(
|
||||
isc__lctx->messages,
|
||||
message, link);
|
||||
|
||||
isc_mem_put(
|
||||
isc__lctx->mctx,
|
||||
message,
|
||||
sizeof(*message) + 1 +
|
||||
strlen(message->text));
|
||||
|
||||
message = next;
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* This message is in the
|
||||
* duplicate filtering interval
|
||||
* ...
|
||||
*/
|
||||
if (strcmp(isc__lctx->buffer,
|
||||
message->text) == 0)
|
||||
{
|
||||
/*
|
||||
* ... and it is a
|
||||
* duplicate. Unlock the
|
||||
* mutex and get the
|
||||
* hell out of Dodge.
|
||||
*/
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
message = ISC_LIST_NEXT(message, link);
|
||||
}
|
||||
|
||||
/*
|
||||
* It wasn't in the duplicate interval,
|
||||
* so add it to the message list.
|
||||
*/
|
||||
size = sizeof(isc_logmessage_t) +
|
||||
strlen(isc__lctx->buffer) + 1;
|
||||
message = isc_mem_get(isc__lctx->mctx, size);
|
||||
message->text = (char *)(message + 1);
|
||||
size -= sizeof(isc_logmessage_t);
|
||||
strlcpy(message->text, isc__lctx->buffer, size);
|
||||
message->time = isc_time_now();
|
||||
ISC_LINK_INIT(message, link);
|
||||
ISC_LIST_APPEND(isc__lctx->messages, message,
|
||||
link);
|
||||
}
|
||||
}
|
||||
|
||||
utc = ((channel->flags & ISC_LOG_UTC) != 0);
|
||||
@@ -1792,17 +1647,6 @@ isc_log_setforcelog(bool v) {
|
||||
forcelog = v;
|
||||
}
|
||||
|
||||
static void
|
||||
isc__log_free_messages(isc_mem_t *mctx, isc_log_t *lctx ISC_ATTR_UNUSED) {
|
||||
isc_logmessage_t *message = NULL, *next = NULL;
|
||||
ISC_LIST_FOREACH_SAFE (lctx->messages, message, link, next) {
|
||||
ISC_LIST_UNLINK(lctx->messages, message, link);
|
||||
|
||||
isc_mem_put(mctx, message,
|
||||
sizeof(*message) + strlen(message->text) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
isc__log_initialize(void) {
|
||||
REQUIRE(isc__lctx == NULL);
|
||||
@@ -1813,9 +1657,7 @@ isc__log_initialize(void) {
|
||||
|
||||
isc__lctx = isc_mem_get(mctx, sizeof(*isc__lctx));
|
||||
*isc__lctx = (isc_log_t){
|
||||
.magic = LCTX_MAGIC,
|
||||
.messages = ISC_LIST_INITIALIZER,
|
||||
.mctx = mctx, /* implicit attach */
|
||||
.magic = LCTX_MAGIC, .mctx = mctx, /* implicit attach */
|
||||
};
|
||||
|
||||
isc_mutex_init(&isc__lctx->lock);
|
||||
@@ -1849,8 +1691,6 @@ isc__log_shutdown(void) {
|
||||
isc_logconfig_destroy(&isc__lctx->logconfig);
|
||||
}
|
||||
|
||||
isc__log_free_messages(mctx, isc__lctx);
|
||||
|
||||
isc_mutex_destroy(&isc__lctx->lock);
|
||||
|
||||
isc_mem_putanddetach(&mctx, isc__lctx, sizeof(*isc__lctx));
|
||||
|
Reference in New Issue
Block a user