From a0c22958c5078bde55775a45a3bab52ceffe3980 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Mon, 30 Jan 2017 14:30:51 +1100 Subject: [PATCH] ctdb-common: Refactor code to remove a stale socket Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- ctdb/common/sock_io.c | 15 +++++++++++++++ ctdb/common/sock_io.h | 1 + 2 files changed, 16 insertions(+) diff --git a/ctdb/common/sock_io.c b/ctdb/common/sock_io.c index 7431eec3250..3f7138f0b7f 100644 --- a/ctdb/common/sock_io.c +++ b/ctdb/common/sock_io.c @@ -31,6 +31,21 @@ #include "common/logging.h" #include "common/sock_io.h" +bool sock_clean(const char *sockpath) +{ + int ret; + + ret = unlink(sockpath); + if (ret == 0) { + D_WARNING("Removed stale socket %s\n", sockpath); + } else if (errno != ENOENT) { + D_ERR("Failed to remove stale socket %s\n", sockpath); + return false; + } + + return true; +} + int sock_connect(const char *sockpath) { struct sockaddr_un addr; diff --git a/ctdb/common/sock_io.h b/ctdb/common/sock_io.h index cbb83a89ef2..8b6e4eb2066 100644 --- a/ctdb/common/sock_io.h +++ b/ctdb/common/sock_io.h @@ -25,6 +25,7 @@ typedef void (*sock_queue_callback_fn_t)(uint8_t *buf, size_t buflen, struct sock_queue; +bool sock_clean(const char *sockpath); int sock_connect(const char *sockpath); struct sock_queue *sock_queue_setup(TALLOC_CTX *mem_ctx, -- 2.34.1