struct {
char *basedir;
+ char datadir[PATH_MAX];
char etcdir[PATH_MAX];
char rundir[PATH_MAX];
char vardir[PATH_MAX];
bool test_mode;
bool basedir_set;
+ bool datadir_set;
bool etcdir_set;
bool rundir_set;
bool vardir_set;
} ctdb_paths = {
+ .datadir = CTDB_DATADIR,
.etcdir = CTDB_ETCDIR,
.rundir = CTDB_RUNDIR,
.vardir = CTDB_VARDIR,
return true;
}
+const char *path_datadir(void)
+{
+ bool ok;
+
+ if (! ctdb_paths.datadir_set) {
+ ok = path_construct(ctdb_paths.datadir, "share");
+ if (!ok) {
+ D_ERR("Failed to construct DATADIR\n");
+ } else {
+ ctdb_paths.datadir_set = true;
+ }
+ }
+
+ return ctdb_paths.datadir;
+}
+
const char *path_etcdir(void)
{
bool ok;
return ctdb_paths.vardir;
}
+char *path_datadir_append(TALLOC_CTX *mem_ctx, const char *path)
+{
+ return talloc_asprintf(mem_ctx, "%s/%s", path_datadir(), path);
+}
+
char *path_etcdir_append(TALLOC_CTX *mem_ctx, const char *path)
{
return talloc_asprintf(mem_ctx, "%s/%s", path_etcdir(), path);
#include <talloc.h>
+const char *path_datadir(void);
const char *path_etcdir(void);
const char *path_rundir(void);
const char *path_vardir(void);
+char *path_datadir_append(TALLOC_CTX *mem_ctx, const char *path);
char *path_etcdir_append(TALLOC_CTX *mem_ctx, const char *path);
char *path_rundir_append(TALLOC_CTX *mem_ctx, const char *path);
char *path_vardir_append(TALLOC_CTX *mem_ctx, const char *path);
return 0;
}
+static int path_tool_datadir(TALLOC_CTX *mem_ctx,
+ int argc,
+ const char **argv,
+ void *private_data)
+{
+ struct path_tool_context *ctx = talloc_get_type_abort(
+ private_data, struct path_tool_context);
+
+ if (argc != 0) {
+ cmdline_usage(ctx->cmdline, "datadir");
+ return EINVAL;
+ }
+
+ printf("%s\n", path_datadir());
+
+ return 0;
+}
+
+static int path_tool_datadir_append(TALLOC_CTX *mem_ctx,
+ int argc,
+ const char **argv,
+ void *private_data)
+{
+ struct path_tool_context *ctx = talloc_get_type_abort(
+ private_data, struct path_tool_context);
+ char *p;
+
+ if (argc != 1) {
+ cmdline_usage(ctx->cmdline, "datadir append");
+ return EINVAL;
+ }
+
+ p = path_datadir_append(mem_ctx, argv[0]);
+ if (p == NULL) {
+ D_ERR("Memory allocation error\n");
+ return 1;
+ }
+
+ printf("%s\n", p);
+
+ return 0;
+}
+
static int path_tool_etcdir(TALLOC_CTX *mem_ctx,
int argc,
const char **argv,
"Get path of CTDB daemon pidfile", "<daemon>" },
{ "socket", path_tool_socket,
"Get path of CTDB daemon socket", "<daemon>" },
+ { "datadir append", path_tool_datadir_append,
+ "Get path relative to CTDB DATADIR", "<path>" },
+ { "datadir", path_tool_datadir,
+ "Get path of CTDB DATADIR", NULL },
{ "etcdir append", path_tool_etcdir_append,
"Get path relative to CTDB ETCDIR", "<path>" },
{ "etcdir", path_tool_etcdir,