ipsec-tools: close the control socket after initialized.

It seems that the socket to be protected by IPSec needs to be created
after SPD policy is inserted. Otherwise the outgoing packets will just
pass through. We close the control socket to notify the framework that
initialization is done.

Change-Id: Ic29188f16333e41d201e0dfe439085e3e6079e39
diff --git a/main.c b/main.c
index 097b9c2..e08d14d 100644
--- a/main.c
+++ b/main.c
@@ -42,7 +42,7 @@
 #include <cutils/sockets.h>
 #include <private/android_filesystem_config.h>
 
-static int get_control_and_arguments(int *argc, char ***argv)
+static int android_get_arguments_and_control(int *argc, char ***argv)
 {
     static char *args[32];
     int control;
@@ -139,14 +139,13 @@
 int main(int argc, char **argv)
 {
 #ifdef ANDROID_CHANGES
-    int control = get_control_and_arguments(&argc, &argv);
+    int control = android_get_arguments_and_control(&argc, &argv);
     if (control != -1) {
         pname = "%p";
     }
 #endif
 
     do_plog(LLV_INFO, "ipsec-tools 0.8.0 (http://ipsec-tools.sf.net)\n");
-    setup(argc, argv);
 
     signal(SIGHUP, terminate);
     signal(SIGINT, terminate);
@@ -154,6 +153,13 @@
     signal(SIGPIPE, SIG_IGN);
     atexit(terminated);
 
+    setup(argc, argv);
+
+#ifdef ANDROID_CHANGES
+    close(control);
+    setuid(AID_VPN);
+#endif
+
     while (1) {
         struct timeval *tv = schedular();
         int timeout = tv->tv_sec * 1000 + tv->tv_usec / 1000 + 1;