]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpd: remove uncleaned control socket when noone is listening
authorVincent Bernat <vincent.bernat@dailymotion.com>
Mon, 7 Jan 2013 11:26:25 +0000 (12:26 +0100)
committerVincent Bernat <vincent.bernat@dailymotion.com>
Mon, 7 Jan 2013 11:26:25 +0000 (12:26 +0100)
NEWS
src/daemon/lldpd.c

diff --git a/NEWS b/NEWS
index ef9a49fc9b383c037ca319aff4147b90f83dc131..924a7b0a47e518db3c206473b0cbfc0521190869 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,8 @@
+lldpd (0.7.1)
+  * Features
+    + Upstart support.
+    + Remove Unix socket when there is no process listening.
+
 lldpd (0.7.0)
   * Global changes:
     + FreeBSD support.
index 3038e60827685e774e1db60d969060513aa19bc2..27a80a7cc367de09f9a323c8661ead05870c12d1 100644 (file)
@@ -1188,11 +1188,29 @@ lldpd_main(int argc, char *argv[])
        gid = group->gr_gid;
 
        /* Create and setup socket */
+       int retry = 1;
        log_debug("main", "creating control socket");
-       if ((ctl = ctl_create(LLDPD_CTL_SOCKET)) == -1) {
-               log_warn ("main", "unable to create control socket");
-               log_warnx("main", "If another instance is running, please stop it.");
-               log_warnx("main", "Otherwise, remove " LLDPD_CTL_SOCKET);
+       while ((ctl = ctl_create(LLDPD_CTL_SOCKET)) == -1) {
+               if (retry-- && errno == EADDRINUSE) {
+                       /* Check if a daemon is really listening */
+                       int tfd;
+                       log_info("main", "unable to create control socket because it already exists");
+                       log_info("main", "check if another instance is running");
+                       if ((tfd = ctl_connect(LLDPD_CTL_SOCKET)) != -1) {
+                               /* Another instance is running */
+                               close(tfd);
+                               log_warnx("main", "another instance is running, please stop it");
+                               fatalx("giving up");
+                       } else if (errno == ECONNREFUSED) {
+                               /* Nobody is listening */
+                               log_info("main", "old control socket is present, clean it");
+                               ctl_cleanup(LLDPD_CTL_SOCKET);
+                               continue;
+                       }
+                       log_warn("main", "cannot determine if another daemon is already running");
+                       fatalx("giving up");
+               }
+               log_warn("main", "unable to create control socket");
                fatalx("giving up");
        }
        if (chown(LLDPD_CTL_SOCKET, uid, gid) == -1)