abduco

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit 64713a32191781c104bed7fdc1b24a6e460e20be
parent 277f4d154df9632e215c1ae57080a6dd492fd5d6
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Thu, 30 Jul 2015 12:19:06 +0200

Only delete stale sockets if they are sockets in the first place

Diffstat:
abduco.c | 3++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/abduco.c b/abduco.c @@ -238,11 +238,12 @@ static bool xsnprintf(char *buf, size_t size, const char *fmt, ...) { static int session_connect(const char *name) { int fd; + struct stat sb; if (!set_socket_name(&sockaddr, name) || (fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) return -1; socklen_t socklen = offsetof(struct sockaddr_un, sun_path) + strlen(sockaddr.sun_path) + 1; if (connect(fd, (struct sockaddr*)&sockaddr, socklen) == -1) { - if (errno == ECONNREFUSED) + if (errno == ECONNREFUSED && stat(sockaddr.sun_path, &sb) == 0 && S_ISSOCK(sb.st_mode)) unlink(sockaddr.sun_path); close(fd); return -1;