diff options
author | Craig Tiller <craig.tiller@gmail.com> | 2015-02-17 16:33:35 -0800 |
---|---|---|
committer | Craig Tiller <craig.tiller@gmail.com> | 2015-02-17 16:33:35 -0800 |
commit | aa31da4ffe0703292a9d76b0c543a0fb7e60f0a1 (patch) | |
tree | 5c0fd82fd66f172f2c7960c6bf6e56c4b33232d7 /src/core | |
parent | e1b97b608af67ddc9e15fc9453346f7c7aeaeb79 (diff) |
UDS Fix
Remove existing UDS listeners IFF they are a socket before trying to create a new socket.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/iomgr/tcp_server_posix.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/core/iomgr/tcp_server_posix.c b/src/core/iomgr/tcp_server_posix.c index 6a96163718..9e5076efc7 100644 --- a/src/core/iomgr/tcp_server_posix.c +++ b/src/core/iomgr/tcp_server_posix.c @@ -42,17 +42,18 @@ #include "src/core/iomgr/tcp_server.h" -#include <limits.h> +#include <errno.h> #include <fcntl.h> +#include <limits.h> #include <netinet/in.h> #include <netinet/tcp.h> #include <stdio.h> +#include <string.h> +#include <sys/socket.h> +#include <sys/stat.h> #include <sys/types.h> #include <sys/un.h> -#include <sys/socket.h> #include <unistd.h> -#include <string.h> -#include <errno.h> #include "src/core/iomgr/pollset_posix.h" #include "src/core/iomgr/resolve_address.h" @@ -83,6 +84,14 @@ typedef struct { int addr_len; } server_port; +static void unlink_if_unix_domain_socket(const struct sockaddr_un *un) { + struct stat st; + + if (stat(un->sun_path, &st) == 0 && (st.st_mode & S_IFMT) == S_IFSOCK) { + unlink(un->sun_path); + } +} + /* the overall server */ struct grpc_tcp_server { grpc_tcp_server_cb cb; @@ -130,7 +139,7 @@ void grpc_tcp_server_destroy(grpc_tcp_server *s) { for (i = 0; i < s->nports; i++) { server_port *sp = &s->ports[i]; if (sp->addr.sockaddr.sa_family == AF_UNIX) { - unlink(sp->addr.un.sun_path); + unlink_if_unix_domain_socket(&sp->addr.un); } grpc_fd_orphan(sp->emfd, NULL, NULL); } @@ -301,6 +310,10 @@ int grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr, socklen_t sockname_len; int port; + if (((struct sockaddr *)addr)->sa_family == AF_UNIX) { + unlink_if_unix_domain_socket(addr); + } + /* Check if this is a wildcard port, and if so, try to keep the port the same as some previously created listener. */ if (grpc_sockaddr_get_port(addr) == 0) { |