Blob Blame History Raw
Index: modules/mod_ctrls.c
===================================================================
RCS file: /cvsroot/proftp/proftpd/modules/mod_ctrls.c,v
retrieving revision 1.53
diff -u -r1.53 mod_ctrls.c
--- modules/mod_ctrls.c	12 Dec 2011 04:23:33 -0000	1.53
+++ modules/mod_ctrls.c	23 Feb 2012 22:18:37 -0000
@@ -492,19 +492,20 @@
     /* Make sure the path to which we want to bind this socket doesn't already
      * exist.
      */
-    unlink(sock_file);
+    (void) unlink(sock_file);
   }
 
   /* Fill in the socket structure fields */
   memset(&sock, 0, sizeof(sock));
 
   sock.sun_family = AF_UNIX;
-  sstrncpy(sock.sun_path, sock_file, strlen(sock_file));
+  sstrncpy(sock.sun_path, sock_file, sizeof(sock.sun_path));
 
   len = sizeof(sock);
 
   /* Bind the name to the descriptor */
-  pr_trace_msg(trace_channel, 1, "binding ctrls socket to '%s'", sock.sun_path);
+  pr_trace_msg(trace_channel, 1, "binding ctrls socket fd %d to path '%s'",
+    sockfd, sock.sun_path);
   if (bind(sockfd, (struct sockaddr *) &sock, len) < 0) {
     int xerrno = errno;
 
@@ -708,9 +709,10 @@
     close(ctrls_sockfd);
     ctrls_sockfd = -1;
 
-    if (is_master)
+    if (is_master) {
       /* Remove the local socket path as well */
-      unlink(ctrls_sock_file);
+      (void) unlink(ctrls_sock_file);
+    }
 
     return 0;
   }
@@ -1159,9 +1161,30 @@
     }
   }
 
+  close(ctrls_sockfd);
+  ctrls_sockfd = -1;
+
+  /* Remove the local socket path as well */
+  (void) unlink(ctrls_sock_file);
   return;
 }
 
+static void ctrls_postparse_ev(const void *event_data, void *user_data) {
+  if (!ctrls_engine) {
+    return;
+  }
+
+  /* Start listening on the ctrl socket */
+  PRIVS_ROOT
+  ctrls_sockfd = ctrls_listen(ctrls_sock_file, CTRLS_LISTEN_FL_REMOVE_SOCKET);
+  PRIVS_RELINQUISH
+
+  /* Start a timer for the checking/processing of the ctrl socket.  */
+  pr_timer_remove(CTRLS_TIMER_ID, &ctrls_module);
+  pr_timer_add(ctrls_interval, CTRLS_TIMER_ID, &ctrls_module, ctrls_timer_cb,
+    "Controls polling");
+}
+
 static void ctrls_restart_ev(const void *event_data, void *user_data) {
   register unsigned int i;
 
@@ -1209,26 +1232,11 @@
     pr_ctrls_init_acl(ctrls_acttab[i].act_acl);
   }
 
+  pr_timer_remove(CTRLS_TIMER_ID, &ctrls_module);
   pr_alarms_unblock();
   return;
 }
 
-static void ctrls_startup_ev(const void *event_data, void *user_data) {
-  if (!ctrls_engine) {
-    return;
-  }
-
-  /* Start listening on the ctrl socket */
-  PRIVS_ROOT
-  ctrls_sockfd = ctrls_listen(ctrls_sock_file, CTRLS_LISTEN_FL_REMOVE_SOCKET);
-  PRIVS_RELINQUISH
-
-  /* Start a timer for the checking/processing of the ctrl socket.  */
-  pr_timer_remove(CTRLS_TIMER_ID, &ctrls_module);
-  pr_timer_add(ctrls_interval, CTRLS_TIMER_ID, &ctrls_module, ctrls_timer_cb,
-    "Controls polling");
-}
-
 /* Initialization routines
  */
 
@@ -1262,7 +1270,7 @@
 
   pr_event_register(&ctrls_module, "core.restart", ctrls_restart_ev, NULL);
   pr_event_register(&ctrls_module, "core.shutdown", ctrls_shutdown_ev, NULL);
-  pr_event_register(&ctrls_module, "core.startup", ctrls_startup_ev, NULL);
+  pr_event_register(&ctrls_module, "core.postparse", ctrls_postparse_ev, NULL);
 
   return 0;
 }
Index: src/ctrls.c
===================================================================
RCS file: /cvsroot/proftp/proftpd/src/ctrls.c,v
retrieving revision 1.32
diff -u -r1.32 ctrls.c
--- src/ctrls.c	12 Dec 2011 04:23:33 -0000	1.32
+++ src/ctrls.c	23 Feb 2012 22:18:37 -0000
@@ -942,7 +942,11 @@
   /* Create a Unix domain socket */
   sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
   if (sockfd < 0) {
+    int xerrno = errno;
+
     pr_signals_unblock();
+
+    errno = xerrno;
     return -1;
   }
 
@@ -975,15 +979,23 @@
 
   /* Make it a socket */
   if (bind(sockfd, (struct sockaddr *) &cl_sock, len) < 0) {
+    int xerrno = errno;
+
     unlink(cl_sock.sun_path);
     pr_signals_unblock();
+
+    errno = xerrno;
     return -1;
   }
 
   /* Set the proper mode */
   if (chmod(cl_sock.sun_path, PR_CTRLS_CL_MODE) < 0) {
+    int xerrno = errno;
+
     unlink(cl_sock.sun_path);
     pr_signals_unblock();
+
+    errno = xerrno;
     return -1;
   }
 
@@ -991,20 +1003,28 @@
   memset(&ctrl_sock, 0, sizeof(ctrl_sock));
 
   ctrl_sock.sun_family = AF_UNIX;
-  sstrncpy(ctrl_sock.sun_path, socket_file, strlen(socket_file));
+  sstrncpy(ctrl_sock.sun_path, socket_file, sizeof(ctrl_sock.sun_path));
   len = sizeof(ctrl_sock);
 
   if (connect(sockfd, (struct sockaddr *) &ctrl_sock, len) < 0) {
+    int xerrno = errno;
+
     unlink(cl_sock.sun_path);
     pr_signals_unblock();
+
+    errno = xerrno;
     return -1;
   }
 
 #if !defined(SO_PEERCRED) && !defined(HAVE_GETPEEREID) && \
     !defined(HAVE_GETPEERUCRED) && defined(LOCAL_CREDS)
   if (ctrls_connect_local_creds(sockfd) < 0) {
+    int xerrno = errno;
+
     unlink(cl_sock.sun_path);
     pr_signals_unblock();
+
+    errno = xerrno;
     return -1;
   }
 #endif /* LOCAL_CREDS */