On Sat, Jan 16, 2016 at 10:04:56AM -0700, Todd C. Miller wrote:
> On Sat, 16 Jan 2016 14:56:48 +0100, Landry Breuil wrote:
> 
> > Good point - the other option would be to log_warn() ? Or just call
> > unlink() without checking the return code like its' done for csockpath ?
> 
> I think (void)unlink(...) is fine for cleanup.

So here's a new iteration. log_info() can go away if deemed useless..

Index: control.c
===================================================================
RCS file: /cvs/src/usr.sbin/ldapd/control.c,v
retrieving revision 1.12
diff -u -r1.12 control.c
--- control.c   24 Dec 2015 17:47:57 -0000      1.12
+++ control.c   16 Jan 2016 22:39:43 -0000
@@ -114,7 +114,6 @@
                return;
        event_del(&cs->cs_ev);
        event_del(&cs->cs_evt);
-       (void)unlink(cs->cs_name);
 }
 
 /* ARGSUSED */
Index: ldapd.c
===================================================================
RCS file: /cvs/src/usr.sbin/ldapd/ldapd.c,v
retrieving revision 1.15
diff -u -r1.15 ldapd.c
--- ldapd.c     24 Dec 2015 17:47:57 -0000      1.15
+++ ldapd.c     16 Jan 2016 22:39:43 -0000
@@ -17,6 +17,7 @@
  */
 
 #include <sys/queue.h>
+#include <sys/un.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 
@@ -45,6 +46,7 @@
 static void     ldapd_auth_request(struct imsgev *iev, struct imsg *imsg);
 static void     ldapd_open_request(struct imsgev *iev, struct imsg *imsg);
 static void     ldapd_log_verbose(struct imsg *imsg);
+static void     ldapd_cleanup(char *);
 
 struct ldapd_stats      stats;
 pid_t                   ldape_pid;
@@ -213,9 +215,30 @@
                err(1, "pledge");
 
        event_dispatch();
+
+       ldapd_cleanup(csockpath);
        log_debug("ldapd: exiting");
 
        return 0;
+}
+
+static void
+ldapd_cleanup(char * csockpath)
+{
+       struct listener         *l;
+       struct sockaddr_un      *sun = NULL;
+
+       /* Remove control socket. */
+       (void)unlink(csockpath);
+
+       /* Remove unix listening sockets. */
+       TAILQ_FOREACH(l, &conf->listeners, entry) {
+               if (l->ss.ss_family == AF_UNIX) {
+                       sun = (struct sockaddr_un *)&l->ss;
+                       log_info("ldapd: removing unix socket %s", 
sun->sun_path);
+                       (void)unlink(sun->sun_path);
+               }
+       }
 }
 
 static void

Reply via email to