diff -urN djbdns-1.05.orig/tdlookup.c djbdns-1.05/tdlookup.c --- djbdns-1.05.orig/tdlookup.c 2001-02-11 22:11:45.000000000 +0100 +++ djbdns-1.05/tdlookup.c 2004-04-18 13:56:13.000000000 +0200 @@ -280,15 +280,24 @@ int respond(char *q,char qtype[2],char ip[4]) { - int fd; + static struct tai cdb_valid = { 0 }; + static int fd = -1; + struct tai one_second; int r; char key[6]; tai_now(&now); - fd = open_read("data.cdb"); - if (fd == -1) return 0; - cdb_init(&c,fd); - + if (tai_less(&cdb_valid, &now)) { + if (fd != -1) { + cdb_free(&c); + close(fd); + } + fd = open_read("data.cdb"); + if (fd == -1) return 0; + cdb_init(&c,fd); + tai_uint(&one_second, 1); + tai_add(&cdb_valid, &now, &one_second); + } byte_zero(clientloc,2); key[0] = 0; key[1] = '%'; @@ -304,7 +313,5 @@ r = doit(q,qtype); - cdb_free(&c); - close(fd); return r; }