mtpd: Install signal handlers after the socket is connected.

Connect() automatically restarts after a signal is received.
If the signal handler does not terminate the process, it might
get blocked for few minutes while the remote server is unreachable.
Delaying the installation of signal handlers fixes this problem
since the default handlers do terminate the process.
diff --git a/mtpd.c b/mtpd.c
index 4a06f3b..5ae2bca 100644
--- a/mtpd.c
+++ b/mtpd.c
@@ -172,6 +172,8 @@
         exit(SYSTEM_ERROR);
     }
 
+    timeout = initialize(argc, argv);
+
     signal(SIGHUP, interrupt);
     signal(SIGINT, interrupt);
     signal(SIGTERM, interrupt);
@@ -179,7 +181,6 @@
     signal(SIGPIPE, SIG_IGN);
     atexit(stop_pppd);
 
-    timeout = initialize(argc, argv);
     pollfds[0].fd = signals[0];
     pollfds[0].events = POLLIN;
     pollfds[1].fd = the_socket;
@@ -271,9 +272,11 @@
 
     for (r = records; r; r = r->ai_next) {
         the_socket = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
-        if (the_socket != -1
-            && connect(the_socket, r->ai_addr, r->ai_addrlen) == 0) {
-            break;
+        if (the_socket != -1) {
+            if (connect(the_socket, r->ai_addr, r->ai_addrlen) == 0) {
+                break;
+            }
+            close(the_socket);
         }
     }