[PATCH] ctdb: add --rundir switch to override CTDB_RUNDIR
Michael Adam
obnox at samba.org
Tue Sep 8 08:58:54 UTC 2015
Needed to be able to run ctdb without prior install (e.g. in
selftest).
Review/Push appreciated.
Thanks - Michael
-------------- next part --------------
From e6290edd311d0020734717bd5e4f0d39b347093d Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 8 Sep 2015 09:59:06 +0200
Subject: [PATCH] ctdb: make it possible to override compiled-in CTDB_RUNDIR in
ctdbd.
This adds a new command line switch --rundir to ctdbd.
It is needed to be able to run ctdb (in selftest) withour prior install.
Signed-off-by: Michael Adam <obnox at samba.org>
---
ctdb/doc/ctdbd.1.xml | 13 +++++++++++++
ctdb/include/ctdb_private.h | 1 +
ctdb/server/ctdbd.c | 6 ++++++
ctdb/tcp/tcp_connect.c | 10 ++++++++--
4 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/ctdb/doc/ctdbd.1.xml b/ctdb/doc/ctdbd.1.xml
index 558e534..52bf722 100644
--- a/ctdb/doc/ctdbd.1.xml
+++ b/ctdb/doc/ctdbd.1.xml
@@ -126,6 +126,19 @@
</varlistentry>
<varlistentry>
+ <term>--rundir=<parameter>DIRECTORY</parameter></term>
+ <listitem>
+ <para>
+ DIRECTORY where CTDB creates a lockfile when it starts listening
+ on sockets.
+ </para>
+ <para>
+ The default is <filename>/var/run/ctdb</filename>.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term>--listen=<parameter>IPADDR</parameter></term>
<listitem>
<para>
diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h
index 42b87ca..842bb94 100644
--- a/ctdb/include/ctdb_private.h
+++ b/ctdb/include/ctdb_private.h
@@ -456,6 +456,7 @@ struct ctdb_context {
const char *db_directory;
const char *db_directory_persistent;
const char *db_directory_state;
+ const char *run_dir;
struct tdb_wrap *db_persistent_health;
uint32_t db_persistent_startup_generation;
uint64_t db_persistent_check_errors;
diff --git a/ctdb/server/ctdbd.c b/ctdb/server/ctdbd.c
index ec285c0..9cbc32a 100644
--- a/ctdb/server/ctdbd.c
+++ b/ctdb/server/ctdbd.c
@@ -38,6 +38,7 @@ static struct {
const char *db_dir;
const char *db_dir_persistent;
const char *db_dir_state;
+ const char *run_dir;
const char *public_interface;
const char *single_public_ip;
int valgrinding;
@@ -60,6 +61,7 @@ static struct {
.db_dir_persistent = CTDB_VARDIR "/persistent",
.db_dir_state = CTDB_VARDIR "/state",
.script_log_level = DEBUG_ERR,
+ .run_dir = CTDB_RUNDIR,
};
int script_log_level;
@@ -133,6 +135,7 @@ int main(int argc, const char *argv[])
&options.max_persistent_check_errors, 0,
"max allowed persistent check errors (default 0)", NULL },
{ "sloppy-start", 0, POPT_ARG_NONE, &fast_start, 0, "Do not perform full recovery on start", NULL },
+ { "rundir", 0, POPT_ARG_STRING, &options.run_dir, 0, "directory for temporary runtime files", NULL },
POPT_TABLEEND
};
int opt, ret;
@@ -258,6 +261,9 @@ int main(int argc, const char *argv[])
ctdb->db_directory_state = options.db_dir_state;
mkdir_p_or_die(ctdb->db_directory_state, 0700);
+ ctdb->run_dir = options.run_dir;
+ mkdir_p_or_die(ctdb->run_dir, 0700);
+
if (options.public_interface) {
ctdb->default_public_interface = talloc_strdup(ctdb, options.public_interface);
CTDB_NO_MEMORY(ctdb, ctdb->default_public_interface);
diff --git a/ctdb/tcp/tcp_connect.c b/ctdb/tcp/tcp_connect.c
index b106f22..a4a0147 100644
--- a/ctdb/tcp/tcp_connect.c
+++ b/ctdb/tcp/tcp_connect.c
@@ -257,18 +257,21 @@ static int ctdb_tcp_listen_automatic(struct ctdb_context *ctdb)
struct ctdb_tcp);
ctdb_sock_addr sock;
int lock_fd, i;
- const char *lock_path = CTDB_RUNDIR "/.socket_lock";
+ char *lock_path;
struct flock lock;
int one = 1;
int sock_size;
struct tevent_fd *fde;
+ lock_path = talloc_asprintf(ctdb, "%s/.socket_lock", ctdb->run_dir);
+
/* If there are no nodes, then it won't be possible to find
* the first one. Log a failure and short circuit the whole
* process.
*/
if (ctdb->num_nodes == 0) {
DEBUG(DEBUG_CRIT,("No nodes available to attempt bind to - is the nodes file empty?\n"));
+ TALLOC_FREE(lock_path);
return -1;
}
@@ -279,6 +282,7 @@ static int ctdb_tcp_listen_automatic(struct ctdb_context *ctdb)
lock_fd = open(lock_path, O_RDWR|O_CREAT, 0666);
if (lock_fd == -1) {
DEBUG(DEBUG_CRIT,("Unable to open %s\n", lock_path));
+ TALLOC_FREE(lock_path);
return -1;
}
@@ -291,6 +295,7 @@ static int ctdb_tcp_listen_automatic(struct ctdb_context *ctdb)
if (fcntl(lock_fd, F_SETLKW, &lock) != 0) {
DEBUG(DEBUG_CRIT,("Unable to lock %s\n", lock_path));
close(lock_fd);
+ TALLOC_FREE(lock_path);
return -1;
}
@@ -372,7 +377,7 @@ static int ctdb_tcp_listen_automatic(struct ctdb_context *ctdb)
tevent_fd_set_auto_close(fde);
close(lock_fd);
-
+ TALLOC_FREE(lock_path);
return 0;
failed:
@@ -381,6 +386,7 @@ failed:
close(ctcp->listen_fd);
ctcp->listen_fd = -1;
}
+ TALLOC_FREE(lock_path);
return -1;
}
--
2.4.3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20150908/db6ecf50/attachment.sig>
More information about the samba-technical
mailing list