diff options
author | Martin Schwenke <martin@meltin.net> | 2018-07-06 17:14:27 +1000 |
---|---|---|
committer | Amitay Isaacs <amitay@samba.org> | 2018-07-11 11:48:38 +0200 |
commit | 3bebc5d8a034f085bd53d7169a69129851b8f140 (patch) | |
tree | 7464d1c9a457d365969e5fc3e908f9dce0e2deb3 /ctdb/common | |
parent | be1c3400587ccf4f04fa56f438cf815a12e04326 (diff) | |
download | samba-3bebc5d8a034f085bd53d7169a69129851b8f140.tar.gz |
ctdb-common: Add path support for datadir
Signed-off-by: Martin Schwenke <martin@meltin.net>
Pair-programmed-with: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb/common')
-rw-r--r-- | ctdb/common/path.c | 24 | ||||
-rw-r--r-- | ctdb/common/path.h | 2 | ||||
-rw-r--r-- | ctdb/common/path_tool.c | 47 |
3 files changed, 73 insertions, 0 deletions
diff --git a/ctdb/common/path.c b/ctdb/common/path.c index 4e69739ba86..36706e43b32 100644 --- a/ctdb/common/path.c +++ b/ctdb/common/path.c @@ -28,15 +28,18 @@ 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, @@ -94,6 +97,22 @@ static bool path_construct(char *path, const char *subdir) 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; @@ -142,6 +161,11 @@ const char *path_vardir(void) 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); diff --git a/ctdb/common/path.h b/ctdb/common/path.h index 370250a0cfe..dcc6c20638d 100644 --- a/ctdb/common/path.h +++ b/ctdb/common/path.h @@ -22,10 +22,12 @@ #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); diff --git a/ctdb/common/path_tool.c b/ctdb/common/path_tool.c index 339066b582e..1c60b023c42 100644 --- a/ctdb/common/path_tool.c +++ b/ctdb/common/path_tool.c @@ -100,6 +100,49 @@ static int path_tool_socket(TALLOC_CTX *mem_ctx, 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, @@ -236,6 +279,10 @@ struct cmdline_command path_commands[] = { "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, |