Code

frontend: Remove stale UNIX sockets before trying to bind().
authorSebastian Harl <sh@tokkee.org>
Wed, 11 Dec 2013 10:26:24 +0000 (11:26 +0100)
committerSebastian Harl <sh@tokkee.org>
Wed, 11 Dec 2013 10:26:24 +0000 (11:26 +0100)
src/frontend/sock.c

index 4cf1d79e295a832e44d08a272156f4800fe6eb6b..65884ea945bf61fe935b48fe60ab819b453b1eb8 100644 (file)
@@ -104,6 +104,13 @@ open_unix_sock(listener_t *listener)
        strncpy(sa.sun_path, listener->address + strlen("unix:"),
                        sizeof(sa.sun_path));
 
+       if (unlink(listener->address + strlen("unix:")) && (errno != ENOENT)) {
+               char errbuf[1024];
+               sdb_log(SDB_LOG_WARNING, "frontend: Failed to remove stale UNIX "
+                               "socket %s: %s", listener->address + strlen("unix:"),
+                               sdb_strerror(errno, errbuf, sizeof(errbuf)));
+       }
+
        status = bind(listener->sock_fd, (struct sockaddr *)&sa, sizeof(sa));
        if (status) {
                char buf[1024];