aboutsummaryrefslogtreecommitdiff
path: root/eperd/readresolv.c
diff options
context:
space:
mode:
Diffstat (limited to 'eperd/readresolv.c')
-rw-r--r--eperd/readresolv.c64
1 files changed, 60 insertions, 4 deletions
diff --git a/eperd/readresolv.c b/eperd/readresolv.c
index 9d3b8c9..cd43bd3 100644
--- a/eperd/readresolv.c
+++ b/eperd/readresolv.c
@@ -6,6 +6,8 @@
#define LINEL (INET6_ADDRSTRLEN * 2)
#include "libbb.h"
#include "resolv.h"
+#include "eperd.h"
+#include <math.h>
static void nameserver_ip_add (char *nsentry, char *ip_as_string)
{
@@ -39,18 +41,72 @@ static int resolv_conf_parse_line (char *nsentry, char *line)
return 0;
}
-int get_local_resolvers(char nslist[MAXNS][INET6_ADDRSTRLEN * 2])
+void get_local_resolvers(char nslist[MAXNS][INET6_ADDRSTRLEN * 2],
+ int *resolv_max)
{
+
+#ifndef RESOLV_CONF
+#define RESOLV_CONF "/etc/resolv.conf"
+#endif
char buf[LINEL];
+ char *buf_start;
int i = 0;
+ time_t now;
+ int r;
+ struct stat sb;
+
+ static resolv_last_check = -1;
+ static time_t last_time= -1;
+
+ now = time(NULL);
+
+ if(*resolv_max){
+ if ( pow (resolv_last_check - now, 2) > 3) {
+ crondlog(LVL5 "check the %s", RESOLV_CONF);
+ }
+ else {
+ return;
+ }
+
+ }
+
- FILE *R = fopen ("/etc/resolv.conf", "r");
+ r = stat(RESOLV_CONF, &sb);
+ if (r == -1)
+ {
+ crondlog(LVL8 "error accessing resolv.conf: %s",
+ strerror(errno));
+ return;
+ }
+
+ resolv_last_check = now;
+
+ if (last_time == sb.st_mtime)
+ {
+ /* nothing changed */
+ crondlog(LVL5 "re-read %s. not reading this time", RESOLV_CONF);
+ return;
+ }
+ else {
+ crondlog(LVL5 "re-read %s . it has changed", RESOLV_CONF);
+ }
+
+ FILE *R = fopen (RESOLV_CONF, "r");
if (R != NULL) {
while ( (fgets (buf, LINEL, R)) && (i < MAXNS)) {
- if(resolv_conf_parse_line(nslist[i], buf) )
+ buf_start = buf;
+ if(resolv_conf_parse_line(nslist[i], buf) ) {
+ crondlog(LVL5 "parsed file %s , line %s i=%d", RESOLV_CONF, buf_start, i);
i++;
+ }
+ else
+ crondlog(LVL5 "ERROR failed to parse from %s i=%d, line %s", RESOLV_CONF, i, buf_start);
}
fclose (R);
}
- return i;
+
+ last_time = sb.st_mtime;
+
+ *resolv_max = i;
+ return;
}