Code

frontend: Make UNIX sockets the default listener implementation.
authorSebastian Harl <sh@tokkee.org>
Sun, 27 Apr 2014 14:53:50 +0000 (16:53 +0200)
committerSebastian Harl <sh@tokkee.org>
Sun, 27 Apr 2014 14:53:50 +0000 (16:53 +0200)
src/frontend/sock.c

index 90aeab1406a6a6389f8ce083dbab72a624b4a936..2e5a6aff66d6484831907c1bcc31fb0b7dd698cb 100644 (file)
@@ -93,6 +93,7 @@ struct sdb_fe_socket {
 static int
 open_unix_sock(listener_t *listener)
 {
 static int
 open_unix_sock(listener_t *listener)
 {
+       const char *addr;
        struct sockaddr_un sa;
        int status;
 
        struct sockaddr_un sa;
        int status;
 
@@ -104,12 +105,16 @@ open_unix_sock(listener_t *listener)
                return -1;
        }
 
                return -1;
        }
 
+       if (*listener->address == '/')
+               addr = listener->address;
+       else
+               addr = listener->address + strlen("unix:");
+
        memset(&sa, 0, sizeof(sa));
        sa.sun_family = AF_UNIX;
        memset(&sa, 0, sizeof(sa));
        sa.sun_family = AF_UNIX;
-       strncpy(sa.sun_path, listener->address + strlen("unix:"),
-                       sizeof(sa.sun_path));
+       strncpy(sa.sun_path, addr, sizeof(sa.sun_path));
 
 
-       if (unlink(listener->address + strlen("unix:")) && (errno != ENOENT)) {
+       if (unlink(addr) && (errno != ENOENT)) {
                char errbuf[1024];
                sdb_log(SDB_LOG_WARNING, "frontend: Failed to remove stale UNIX "
                                "socket %s: %s", listener->address + strlen("unix:"),
                char errbuf[1024];
                sdb_log(SDB_LOG_WARNING, "frontend: Failed to remove stale UNIX "
                                "socket %s: %s", listener->address + strlen("unix:"),
@@ -129,15 +134,22 @@ open_unix_sock(listener_t *listener)
 static void
 close_unix_sock(listener_t *listener)
 {
 static void
 close_unix_sock(listener_t *listener)
 {
+       const char *addr;
        assert(listener);
        assert(listener);
+
        if (! listener->address)
                return;
 
        if (! listener->address)
                return;
 
+       if (*listener->address == '/')
+               addr = listener->address;
+       else
+               addr = listener->address + strlen("unix:");
+
        if (listener->sock_fd >= 0)
                close(listener->sock_fd);
        listener->sock_fd = -1;
 
        if (listener->sock_fd >= 0)
                close(listener->sock_fd);
        listener->sock_fd = -1;
 
-       unlink(listener->address + strlen("unix:"));
+       unlink(addr);
 } /* close_unix_sock */
 
 /*
 } /* close_unix_sock */
 
 /*
@@ -147,7 +159,7 @@ close_unix_sock(listener_t *listener)
 /* the enum has to be sorted the same as the implementations array
  * to ensure that the type may be used as index into the array */
 enum {
 /* the enum has to be sorted the same as the implementations array
  * to ensure that the type may be used as index into the array */
 enum {
-       LISTENER_UNIXSOCK = 0,
+       LISTENER_UNIXSOCK = 0, /* this is the default */
 };
 static fe_listener_impl_t listener_impls[] = {
        { LISTENER_UNIXSOCK, "unix", open_unix_sock, close_unix_sock },
 };
 static fe_listener_impl_t listener_impls[] = {
        { LISTENER_UNIXSOCK, "unix", open_unix_sock, close_unix_sock },
@@ -199,7 +211,7 @@ get_type(const char *address)
 
        sep = strchr(address, (int)':');
        if (! sep)
 
        sep = strchr(address, (int)':');
        if (! sep)
-               return -1;
+               return listener_impls[0].type;
 
        assert(sep > address);
        len = (size_t)(sep - address);
 
        assert(sep > address);
        len = (size_t)(sep - address);