Bug in 2.0.7's use_dns(persist_only) and large host files
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. Fix: See the attached patch; it should apply cleanly to any version of 2.0.7, and perhaps older versions as well. Steve -- Steve Bernacki, Jr To date, the Pan-Massachusetts Challenge has raised 204 million dollars for cancer research. Get involved! http://www.pmc.org/ diff -ur syslog-ng-2.0.7/src/dnscache.c syslog-ng-2.0.7-patch/src/dnscache.c --- syslog-ng-2.0.7/src/dnscache.c 2008-01-03 06:59:18.000000000 -0500 +++ syslog-ng-2.0.7-patch/src/dnscache.c 2008-01-27 09:24:52.000000000 -0500 @@ -271,7 +271,7 @@ } g_hash_table_replace(cache, &entry->key, entry); - if (g_hash_table_size(cache) > dns_cache_size) + if (!persistent && g_hash_table_size(cache) > dns_cache_size) { /* remove oldest element */ g_hash_table_remove(cache, &cache_first.next->key);
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
participants (2)
-
Balazs Scheidler
-
Steve Bernacki