[syslog-ng] Bug in 2.0.7's use_dns(persist_only) and large host files
Balazs Scheidler
bazsi at balabit.hu
Sun Jan 27 20:47:09 CET 2008
On Sun, 2008-01-27 at 14:25 -0500, Steve Bernacki wrote:
> Environment: CentOS 5 and Syslog-ng 2.0.7 (current snapshot)
> Relevant syslog-ng.conf snippet:
> ===
> options {
> use_dns(persist_only);
> dns_cache_hosts("/etc/hosts");
> };
> ===
>
> If you point syslog-ng to an /etc/hosts file that has more than 1007
> entries, upon receiving its first message, syslog-ng will throw the
> following assertion:
>
> # ./syslog-ng -Fed
> syslog-ng starting up; version='2.0.7'
> Incoming log entry; line='<38>well hello'
> file dnscache.c: line 99 (dns_cache_key_hash): should not be reached
> Aborted
>
> Workaround: In syslog-ng.conf, set dns_cache_size() to a value greater
> than the number of entries in your /etc/hosts file.
Thanks for the bug report and the fix.
What do you think about this patch instead?
diff --git a/src/dnscache.c b/src/dnscache.c
index 097af48..f64ec53 100644
--- a/src/dnscache.c
+++ b/src/dnscache.c
@@ -62,6 +62,7 @@ static DNSCacheEntry cache_first, cache_last, persist_first, persist_last;
static gint dns_cache_size = 1007;
static gint dns_cache_expire = 3600;
static gint dns_cache_expire_failed = 60;
+static gint dns_cache_persistent_count = 0;
static gchar *dns_cache_hosts = NULL;
static time_t dns_cache_hosts_mtime = -1;
@@ -146,6 +147,7 @@ dns_cache_cleanup_persistent_hosts(void)
while (persist_first.next != &persist_last)
{
g_hash_table_remove(cache, &persist_first.next->key);
+ dns_cache_persistent_count--;
}
}
@@ -266,12 +268,14 @@ dns_cache_store(gboolean persistent, gint family, void *addr, const gchar *hostn
}
else
{
+ dns_cache_persistent_count++;
entry->resolved = 0;
dns_cache_entry_insert_before(&persist_last, entry);
}
g_hash_table_replace(cache, &entry->key, entry);
- if (g_hash_table_size(cache) > dns_cache_size)
+ /* persistent elements are not counted */
+ if (g_hash_table_size(cache) - dns_cache_persistent_count > dns_cache_size)
{
/* remove oldest element */
g_hash_table_remove(cache, &cache_first.next->key);
--
Bazsi
More information about the syslog-ng
mailing list