summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 31a4f8a)
raw | patch | inline | side by side (parent: 31a4f8a)
author | Sebastian Harl <sh@tokkee.org> | |
Wed, 14 Jan 2015 21:01:03 +0000 (22:01 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Wed, 14 Jan 2015 21:01:03 +0000 (22:01 +0100) |
Strip the <type>: prefix early. Else, we'd have to strip it off over and over
again when working with the address string.
again when working with the address string.
src/frontend/sock.c | patch | blob | history |
diff --git a/src/frontend/sock.c b/src/frontend/sock.c
index 642f03f92b0f87d25e3783bb501ecbce793ff6c3..860fb8ee62a5063ce021b9006ea1a90266ce3418 100644 (file)
--- a/src/frontend/sock.c
+++ b/src/frontend/sock.c
*/
static int
-open_unix_sock(listener_t *listener)
+open_unixsock(listener_t *listener)
{
- const char *addr;
char *addr_copy;
char *base_dir;
struct sockaddr_un sa;
return -1;
}
- if (*listener->address == '/')
- addr = listener->address;
- else
- addr = listener->address + strlen("unix:");
-
memset(&sa, 0, sizeof(sa));
sa.sun_family = AF_UNIX;
- strncpy(sa.sun_path, addr, sizeof(sa.sun_path));
+ strncpy(sa.sun_path, listener->address, sizeof(sa.sun_path));
- addr_copy = strdup(addr);
+ addr_copy = strdup(listener->address);
if (! addr_copy) {
char errbuf[1024];
sdb_log(SDB_LOG_ERR, "frontend: strdup failed: %s",
}
free(addr_copy);
- if (unlink(addr) && (errno != ENOENT)) {
+ if (unlink(listener->address) && (errno != ENOENT)) {
char errbuf[1024];
sdb_log(SDB_LOG_WARNING, "frontend: Failed to remove stale UNIX "
- "socket %s: %s", listener->address + strlen("unix:"),
+ "socket %s: %s", listener->address,
sdb_strerror(errno, errbuf, sizeof(errbuf)));
}
return -1;
}
return 0;
-} /* open_unix_sock */
+} /* open_unixsock */
static void
-close_unix_sock(listener_t *listener)
+close_unixsock(listener_t *listener)
{
- const char *addr;
assert(listener);
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;
- unlink(addr);
-} /* close_unix_sock */
+ unlink(listener->address);
+} /* close_unixsock */
/*
* private variables
LISTENER_UNIXSOCK = 0, /* this is the default */
};
static fe_listener_impl_t listener_impls[] = {
- { LISTENER_UNIXSOCK, "unix", open_unix_sock, close_unix_sock },
+ { LISTENER_UNIXSOCK, "unix", open_unixsock, close_unixsock },
};
/*
listener_create(sdb_fe_socket_t *sock, const char *address)
{
listener_t *listener;
+ size_t len;
int type;
type = get_type(address);
sock->listeners = listener;
listener = sock->listeners + sock->listeners_num;
+ len = strlen(listener_impls[type].prefix);
+ if ((! strncmp(address, listener_impls[type].prefix, len))
+ && (address[len] == ':'))
+ address += strlen(listener_impls[type].prefix) + 1;
+
listener->sock_fd = -1;
listener->address = strdup(address);
if (! listener->address) {