Commits

Anonymous committed a777654

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.

  • Participants
  • Parent commits 6c0e6ee

Comments (0)

Files changed (1)

         exit(SYSTEM_ERROR);
     }
 
+    timeout = initialize(argc, argv);
+
     signal(SIGHUP, interrupt);
     signal(SIGINT, interrupt);
     signal(SIGTERM, interrupt);
     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;
 
     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);
         }
     }