[or-cvs] r6975: Oops. We shouldnt initialize eventdns when we are not being (in tor/trunk: . src/or)

nickm at seul.org nickm at seul.org
Fri Aug 4 18:24:41 UTC 2006


Author: nickm
Date: 2006-08-04 14:24:41 -0400 (Fri, 04 Aug 2006)
New Revision: 6975

Modified:
   tor/trunk/
   tor/trunk/src/or/dns.c
Log:
 r7008 at Kushana:  nickm | 2006-08-03 10:03:39 -0700
 Oops. We shouldnt initialize eventdns when we are not being a server and not resolving anything.



Property changes on: tor/trunk
___________________________________________________________________
Name: svk:merge
   - 1f724f9b-111a-0410-b636-93f1a77c1813:/local/or/tor/trunk:8207
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/eventdns:7007
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/oo-connections:6950
   + 1f724f9b-111a-0410-b636-93f1a77c1813:/local/or/tor/trunk:8207
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/eventdns:7008
c95137ef-5f19-0410-b913-86e773d04f59:/tor/branches/oo-connections:6950

Modified: tor/trunk/src/or/dns.c
===================================================================
--- tor/trunk/src/or/dns.c	2006-08-04 18:24:25 UTC (rev 6974)
+++ tor/trunk/src/or/dns.c	2006-08-04 18:24:41 UTC (rev 6975)
@@ -104,6 +104,8 @@
 static int dnsworker_main(void *data);
 static int spawn_dnsworker(void);
 static int spawn_enough_dnsworkers(void);
+#else
+static void configure_nameservers(void);
 #endif
 static void assert_cache_ok(void);
 static void assert_resolve_ok(cached_resolve_t *resolve);
@@ -156,34 +158,10 @@
 void
 dns_init(void)
 {
-
   init_cache_map();
   dnsworkers_rotate();
-#ifdef USE_EVENTDNS
-  {
-    or_options_t *options = get_options();
-    eventdns_set_log_fn(eventdns_log_cb);
-    if (options->Nameservers && smartlist_len(options->Nameservers)) {
-      log_info(LD_EXIT, "Configuring nameservers from Tor configuration");
-      SMARTLIST_FOREACH(options->Nameservers, const char *, ip,
-        {
-          struct in_addr in;
-          if (tor_inet_aton(ip, &in)) {
-            log_info(LD_EXIT, "Adding nameserver '%s'", ip);
-            eventdns_nameserver_add(in.s_addr);
-          }
-        });
-    } else {
-#ifdef MS_WINDOWS
-      eventdns_config_windows_nameservers();
-#else
-      log_info(LD_EXIT, "Parsing /etc/resolv.conf");
-      eventdns_resolv_conf_parse(DNS_OPTION_NAMESERVERS|DNS_OPTION_MISC,
-                                 "/etc/resolv.conf");
-#endif
-    }
-  }
-#endif
+  if (server_mode(get_options()))
+    configure_nameservers();
 }
 
 uint32_t
@@ -1198,7 +1176,37 @@
   tor_assert(0);
   return 0;
 }
+static int nameservers_configured = 0;
 static void
+configure_nameservers(void)
+{
+  or_options_t *options;
+  if (nameservers_configured)
+    return;
+  options = get_options();
+  eventdns_set_log_fn(eventdns_log_cb);
+  if (options->Nameservers && smartlist_len(options->Nameservers)) {
+    log_info(LD_EXIT, "Configuring nameservers from Tor configuration");
+    SMARTLIST_FOREACH(options->Nameservers, const char *, ip,
+      {
+        struct in_addr in;
+        if (tor_inet_aton(ip, &in)) {
+          log_info(LD_EXIT, "Adding nameserver '%s'", ip);
+          eventdns_nameserver_add(in.s_addr);
+        }
+      });
+  } else {
+#ifdef MS_WINDOWS
+    eventdns_config_windows_nameservers();
+#else
+    log_info(LD_EXIT, "Parsing /etc/resolv.conf");
+    eventdns_resolv_conf_parse(DNS_OPTION_NAMESERVERS|DNS_OPTION_MISC,
+                               "/etc/resolv.conf");
+#endif
+  }
+  nameservers_configured = 1;
+}
+static void
 eventdns_callback(int result, char type, int count, int ttl, void *addresses,
                   void *arg)
 {
@@ -1237,6 +1245,8 @@
 {
   char *addr = tor_strdup(exitconn->_base.address);
   int r;
+  if (!nameservers_configured)
+    configure_nameservers();
   log_info(LD_EXIT, "Launching eventdns request for %s",
            escaped_safe_str(exitconn->_base.address));
   r = eventdns_resolve(exitconn->_base.address, DNS_QUERY_NO_SEARCH,



More information about the tor-commits mailing list