Make clatd a bit more robust when started by netd.

1. When started from netd, DNS lookups (used to detect the NAT64
   prefix) fail because ANDROID_DNS_MODE=local. Unset it.
2. Only add the SIGTERM handler just before starting the event
   loop. Otherwise, if clatd hangs before the event loop is
   started (e.g., when #1 happens), it can't be stopped.

While I'm at it, add a couple of logging statements.

Change-Id: Ie24b37e34b729ce6cd3769b5d64348f2c1b9627d
diff --git a/dns64.c b/dns64.c
index ab662c7..b139fe4 100644
--- a/dns64.c
+++ b/dns64.c
@@ -38,6 +38,9 @@
   int status, plat_addr_set, ipv4_records, ipv6_records;
   struct in6_addr plat_addr, this_plat_addr;
   struct sockaddr_in6 *this_addr;
+  char plat_addr_str[INET6_ADDRSTRLEN];
+
+  logmsg(ANDROID_LOG_INFO, "Detecting NAT64 prefix from DNS...");
 
   result = NULL;
   plat_addr_set = 0;
@@ -71,12 +74,12 @@
       continue;
     }
 
+    inet_ntop(AF_INET6, &plat_addr, plat_addr_str, sizeof(plat_addr_str));
     if(!IN6_ARE_ADDR_EQUAL(&plat_addr, &this_plat_addr)) {
-      char plat_addr_str[INET6_ADDRSTRLEN], this_plat_addr_str[INET6_ADDRSTRLEN];
+      char this_plat_addr_str[INET6_ADDRSTRLEN];
+      inet_ntop(AF_INET6, &this_plat_addr, this_plat_addr_str, sizeof(this_plat_addr_str));
       logmsg(ANDROID_LOG_ERROR,"plat_prefix/two different plat addrs = %s,%s",
-          inet_ntop(AF_INET6, &plat_addr, plat_addr_str, sizeof(plat_addr_str)),
-          inet_ntop(AF_INET6, &this_plat_addr, this_plat_addr_str, sizeof(this_plat_addr_str))
-          );
+             plat_addr_str,this_plat_addr_str);
     }
   }
   if(result != NULL) {
@@ -86,6 +89,8 @@
     logmsg(ANDROID_LOG_WARN,"plat_prefix/no dns64 detected\n");
     return -1;
   }
+
+  logmsg(ANDROID_LOG_INFO, "Detected NAT64 prefix %s/96", plat_addr_str);
   *prefix = plat_addr;
   return 1;
 }