ctdb-common: Refactor code to remove a stale socket
authorAmitay Isaacs <amitay@gmail.com>
Mon, 30 Jan 2017 03:30:51 +0000 (14:30 +1100)
committerMartin Schwenke <martins@samba.org>
Fri, 17 Feb 2017 09:44:14 +0000 (10:44 +0100)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/common/sock_io.c
ctdb/common/sock_io.h

index 7431eec3250bb4678ca40ca1331b8289b05a8c66..3f7138f0b7f59ec2cdb7b2668d239389819b5018 100644 (file)
 #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;
index cbb83a89ef2593230fb6a463b3dc3ec431421e3d..8b6e4eb20667fd3b90fa6b77f0dd1e63fc5ab7a9 100644 (file)
@@ -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,