From 69c309ec479900f9389aacba18d8c1d3026ece46 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Fri, 30 Jun 2017 08:37:08 -0700 Subject: IPC fixes: correct handling of path removal, and path absence. --- src/platform/posix/posix_socket.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/platform/posix/posix_socket.c b/src/platform/posix/posix_socket.c index 9dd3a274..ce887a78 100644 --- a/src/platform/posix/posix_socket.c +++ b/src/platform/posix/posix_socket.c @@ -280,22 +280,26 @@ nni_posix_sock_listen(nni_posix_sock *s, const nni_sockaddr *saddr) } } (void) close(chkfd); - - // Record the path so we unlink it later - s->unlink = nni_alloc(strlen(saddr->s_un.s_path.sa_path) + 1); - if (s->unlink == NULL) { - (void) close(fd); - return (NNG_ENOMEM); - } } - if (bind(fd, (struct sockaddr *) &ss, len) < 0) { rv = nni_plat_errno(errno); (void) close(fd); return (rv); } + // For IPC, record the path so we unlink it later + if ((saddr->s_un.s_family == NNG_AF_IPC) && + (saddr->s_un.s_path.sa_path[0] != 0)) { + s->unlink = nni_alloc(strlen(saddr->s_un.s_path.sa_path) + 1); + if (s->unlink == NULL) { + (void) close(fd); + (void) unlink(saddr->s_un.s_path.sa_path); + return (NNG_ENOMEM); + } + strcpy(s->unlink, saddr->s_un.s_path.sa_path); + } + // Listen -- 128 depth is probably sufficient. If it isn't, other // bad things are going to happen. if (listen(fd, 128) != 0) { @@ -485,6 +489,12 @@ nni_posix_sock_connect_sync(nni_posix_sock *s, const nni_sockaddr *addr, if (connect(fd, (struct sockaddr *) &ss, len) != 0) { rv = nni_plat_errno(errno); + // Unix domain sockets return ENOENT when nothing is there. + // Massage this into ECONNREFUSED, to provide more consistent + // behavior. + if (rv == NNG_ENOENT) { + rv = NNG_ECONNREFUSED; + } (void) close(fd); return (rv); } -- cgit v1.2.3-70-g09d2