summaryrefslogtreecommitdiffstats
path: root/clatd.c
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2013-03-01 20:29:39 +0900
committerLorenzo Colitti <lorenzo@google.com>2013-03-02 12:46:34 +0900
commitbaf62997b598ac38a99fd30419ccf7c109ffb3bc (patch)
tree520f17db43ccd3e559c016747a66ea3483602cca /clatd.c
parentd6ef91bef28020ec019a64561e8fb5e353e42980 (diff)
downloadandroid_external_android-clat-baf62997b598ac38a99fd30419ccf7c109ffb3bc.tar.gz
android_external_android-clat-baf62997b598ac38a99fd30419ccf7c109ffb3bc.tar.bz2
android_external_android-clat-baf62997b598ac38a99fd30419ccf7c109ffb3bc.zip
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
Diffstat (limited to 'clatd.c')
-rw-r--r--clatd.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/clatd.c b/clatd.c
index 17a3548..74aabcb 100644
--- a/clatd.c
+++ b/clatd.c
@@ -109,10 +109,10 @@ void set_accept_ra() {
}
}
-/* function: got_sigterm
- * signal handler: mark it time to clean up
+/* function: stop_loop
+ * signal handler: stop the event loop
*/
-void got_sigterm(int signal) {
+void stop_loop(int signal) {
running = 0;
}
@@ -474,6 +474,7 @@ int main(int argc, char **argv) {
printf("I need an interface\n");
exit(1);
}
+ logmsg(ANDROID_LOG_INFO,"Starting clat on %s", uplink_interface);
// open the tunnel device before dropping privs
tunnel.fd6 = tun_open();
@@ -502,10 +503,9 @@ int main(int argc, char **argv) {
// run under a regular user
drop_root();
- if(signal(SIGTERM, got_sigterm) == SIG_ERR) {
- logmsg(ANDROID_LOG_FATAL, "sigterm handler failed: %s", strerror(errno));
- exit(1);
- }
+ // When run from netd, the environment variable ANDROID_DNS_MODE is set to
+ // "local", but that only works for the netd process itself.
+ unsetenv("ANDROID_DNS_MODE");
configure_interface(uplink_interface, plat_prefix, &tunnel);
@@ -514,9 +514,15 @@ int main(int argc, char **argv) {
set_default_ipv6_route(uplink_interface);
set_forwarding(forwarding_fd,"1\n");
- event_loop(&tunnel); // event_loop returns if someone sets the tun interface down manually
+ // Loop until someone sends us a signal or brings down the tun interface.
+ if(signal(SIGTERM, stop_loop) == SIG_ERR) {
+ logmsg(ANDROID_LOG_FATAL, "sigterm handler failed: %s", strerror(errno));
+ exit(1);
+ }
+ event_loop(&tunnel);
set_forwarding(forwarding_fd,"0\n");
+ logmsg(ANDROID_LOG_INFO,"Shutting down clat on %s", uplink_interface);
return 0;
}