summaryrefslogtreecommitdiff
path: root/ctdb/common
diff options
context:
space:
mode:
authorAmitay Isaacs <amitay@gmail.com>2017-01-30 14:30:51 +1100
committerMartin Schwenke <martins@samba.org>2017-02-17 10:44:14 +0100
commita0c22958c5078bde55775a45a3bab52ceffe3980 (patch)
treeeb20426486692b2d909e02bc12229f9ce149df45 /ctdb/common
parent574914f8d45e9ec9f9c2c8a9c83e338c4394c85c (diff)
downloadsamba-a0c22958c5078bde55775a45a3bab52ceffe3980.tar.gz
ctdb-common: Refactor code to remove a stale socket
Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
Diffstat (limited to 'ctdb/common')
-rw-r--r--ctdb/common/sock_io.c15
-rw-r--r--ctdb/common/sock_io.h1
2 files changed, 16 insertions, 0 deletions
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,