Reconcile "names" and "address" counts when reading hostfiles.

This commit is contained in:
Simon Kelley
2022-10-30 15:40:20 +00:00
parent 34fac952b6
commit d3c21c596e
2 changed files with 6 additions and 6 deletions

View File

@@ -1169,7 +1169,7 @@ int read_hostsfile(char *filename, unsigned int index, int cache_size, struct cr
{ {
FILE *f = fopen(filename, "r"); FILE *f = fopen(filename, "r");
char *token = daemon->namebuff, *domain_suffix = NULL; char *token = daemon->namebuff, *domain_suffix = NULL;
int addr_count = 0, name_count = cache_size, lineno = 1; int names_done = 0, name_count = cache_size, lineno = 1;
unsigned int flags = 0; unsigned int flags = 0;
union all_addr addr; union all_addr addr;
int atnl, addrlen = 0; int atnl, addrlen = 0;
@@ -1205,8 +1205,6 @@ int read_hostsfile(char *filename, unsigned int index, int cache_size, struct cr
continue; continue;
} }
addr_count++;
/* rehash every 1000 names. */ /* rehash every 1000 names. */
if (rhash && ((name_count - cache_size) > 1000)) if (rhash && ((name_count - cache_size) > 1000))
{ {
@@ -1238,6 +1236,7 @@ int read_hostsfile(char *filename, unsigned int index, int cache_size, struct cr
cache->ttd = daemon->local_ttl; cache->ttd = daemon->local_ttl;
add_hosts_entry(cache, &addr, addrlen, index, rhash, hashsz); add_hosts_entry(cache, &addr, addrlen, index, rhash, hashsz);
name_count++; name_count++;
names_done++;
} }
if ((cache = whine_malloc(SIZEOF_BARE_CREC + strlen(canon) + 1))) if ((cache = whine_malloc(SIZEOF_BARE_CREC + strlen(canon) + 1)))
{ {
@@ -1246,6 +1245,7 @@ int read_hostsfile(char *filename, unsigned int index, int cache_size, struct cr
cache->ttd = daemon->local_ttl; cache->ttd = daemon->local_ttl;
add_hosts_entry(cache, &addr, addrlen, index, rhash, hashsz); add_hosts_entry(cache, &addr, addrlen, index, rhash, hashsz);
name_count++; name_count++;
names_done++;
} }
free(canon); free(canon);
@@ -1262,7 +1262,7 @@ int read_hostsfile(char *filename, unsigned int index, int cache_size, struct cr
if (rhash) if (rhash)
rehash(name_count); rehash(name_count);
my_syslog(LOG_INFO, _("read %s - %d addresses"), filename, addr_count); my_syslog(LOG_INFO, _("read %s - %d names"), filename, names_done);
return name_count; return name_count;
} }

View File

@@ -306,7 +306,7 @@ int inotify_check(time_t now)
{ {
const unsigned int removed = cache_remove_uid(ah->index); const unsigned int removed = cache_remove_uid(ah->index);
if (removed > 0) if (removed > 0)
my_syslog(LOG_INFO, _("inotify: flushed %u addresses read from %s"), removed, path); my_syslog(LOG_INFO, _("inotify: flushed %u names read from %s"), removed, path);
/* (Re-)load hostsfile only if this event isn't triggered by deletion */ /* (Re-)load hostsfile only if this event isn't triggered by deletion */
if (!(in->mask & IN_DELETE)) if (!(in->mask & IN_DELETE))