From: Martin Schwenke Date: Mon, 6 Jul 2026 08:23:42 +0000 (+1000) Subject: ctdb-common: Add basic path functionality for new directories X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e74f5f8269f42e8fdb180a2168e40fcd16b711ed;p=thirdparty%2Fsamba.git ctdb-common: Add basic path functionality for new directories New path_*() functions for CTDB_LOCKDIR, CTDB_PIDDIR, CTDB_SOCKETDIR. In test mode these all use "${CTDB_BASE}/run". The new functions are not yet used, except in the ctdb-path command. path_socket() and path_pidfile() are not modified. If they were then the new functions would be used. Signed-off-by: Martin Schwenke Reviewed-by: Anoop C S --- diff --git a/ctdb/common/path.c b/ctdb/common/path.c index 60bbd50ddc9..c999a6240f4 100644 --- a/ctdb/common/path.c +++ b/ctdb/common/path.c @@ -31,20 +31,29 @@ struct { char datadir[PATH_MAX]; char etcdir[PATH_MAX]; const char* helperdir; + char lockdir[PATH_MAX]; + char piddir[PATH_MAX]; char rundir[PATH_MAX]; + char socketdir[PATH_MAX]; char vardir[PATH_MAX]; bool test_mode; bool basedir_set; bool datadir_set; bool etcdir_set; bool helperdir_set; + bool lockdir_set; + bool piddir_set; bool rundir_set; + bool socketdir_set; bool vardir_set; } ctdb_paths = { .datadir = CTDB_DATADIR, .etcdir = CTDB_ETCDIR, .helperdir = CTDB_HELPER_BINDIR, + .lockdir = CTDB_LOCKDIR, + .piddir = CTDB_PIDDIR, .rundir = CTDB_RUNDIR, + .socketdir = CTDB_SOCKETDIR, .vardir = CTDB_VARDIR, }; @@ -169,6 +178,38 @@ done: return ctdb_paths.helperdir; } +const char *path_lockdir(void) +{ + bool ok; + + if (! ctdb_paths.lockdir_set) { + ok = path_construct(ctdb_paths.lockdir, "run"); + if (!ok) { + D_ERR("Failed to construct LOCKDIR\n"); + } else { + ctdb_paths.lockdir_set = true; + } + } + + return ctdb_paths.lockdir; +} + +const char *path_piddir(void) +{ + bool ok; + + if (! ctdb_paths.piddir_set) { + ok = path_construct(ctdb_paths.piddir, "run"); + if (!ok) { + D_ERR("Failed to construct PIDDIR\n"); + } else { + ctdb_paths.piddir_set = true; + } + } + + return ctdb_paths.piddir; +} + const char *path_rundir(void) { bool ok; @@ -185,6 +226,22 @@ const char *path_rundir(void) return ctdb_paths.rundir; } +const char *path_socketdir(void) +{ + bool ok; + + if (! ctdb_paths.socketdir_set) { + ok = path_construct(ctdb_paths.socketdir, "run"); + if (!ok) { + D_ERR("Failed to construct SOCKETDIR\n"); + } else { + ctdb_paths.socketdir_set = true; + } + } + + return ctdb_paths.socketdir; +} + const char *path_vardir(void) { bool ok; @@ -216,11 +273,26 @@ char *path_helperdir_append(TALLOC_CTX *mem_ctx, const char *path) return talloc_asprintf(mem_ctx, "%s/%s", path_helperdir(), path); } +char *path_lockdir_append(TALLOC_CTX *mem_ctx, const char *path) +{ + return talloc_asprintf(mem_ctx, "%s/%s", path_lockdir(), path); +} + +char *path_piddir_append(TALLOC_CTX *mem_ctx, const char *path) +{ + return talloc_asprintf(mem_ctx, "%s/%s", path_piddir(), path); +} + char *path_rundir_append(TALLOC_CTX *mem_ctx, const char *path) { return talloc_asprintf(mem_ctx, "%s/%s", path_rundir(), path); } +char *path_socketdir_append(TALLOC_CTX *mem_ctx, const char *path) +{ + return talloc_asprintf(mem_ctx, "%s/%s", path_socketdir(), path); +} + char *path_vardir_append(TALLOC_CTX *mem_ctx, const char *path) { return talloc_asprintf(mem_ctx, "%s/%s", path_vardir(), path); diff --git a/ctdb/common/path.h b/ctdb/common/path.h index e3c7880ffc7..068e11b96d0 100644 --- a/ctdb/common/path.h +++ b/ctdb/common/path.h @@ -25,13 +25,19 @@ const char *path_datadir(void); const char *path_etcdir(void); const char *path_helperdir(void); +const char *path_lockdir(void); +const char *path_piddir(void); const char *path_rundir(void); +const char *path_socketdir(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_helperdir_append(TALLOC_CTX *mem_ctx, const char *path); +char *path_lockdir_append(TALLOC_CTX *mem_ctx, const char *path); +char *path_piddir_append(TALLOC_CTX *mem_ctx, const char *path); char *path_rundir_append(TALLOC_CTX *mem_ctx, const char *path); +char *path_socketdir_append(TALLOC_CTX *mem_ctx, const char *path); char *path_vardir_append(TALLOC_CTX *mem_ctx, const char *path); char *path_config(TALLOC_CTX *mem_ctx); diff --git a/ctdb/common/path_tool.c b/ctdb/common/path_tool.c index cd5e90fe74a..e0738858638 100644 --- a/ctdb/common/path_tool.c +++ b/ctdb/common/path_tool.c @@ -182,6 +182,62 @@ static int path_tool_etcdir_append(TALLOC_CTX *mem_ctx, return ret; } +static int path_tool_lockdir(TALLOC_CTX *mem_ctx, + int argc, + const char **argv, + void *private_data) +{ + int ret = path_tool_generic(mem_ctx, + argc, + argv, + private_data, + "lockdir", + path_lockdir); + return ret; +} + +static int path_tool_lockdir_append(TALLOC_CTX *mem_ctx, + int argc, + const char **argv, + void *private_data) +{ + int ret = path_tool_append_generic(mem_ctx, + argc, + argv, + private_data, + "lockdir append", + path_lockdir_append); + return ret; +} + +static int path_tool_piddir(TALLOC_CTX *mem_ctx, + int argc, + const char **argv, + void *private_data) +{ + int ret = path_tool_generic(mem_ctx, + argc, + argv, + private_data, + "piddir", + path_piddir); + return ret; +} + +static int path_tool_piddir_append(TALLOC_CTX *mem_ctx, + int argc, + const char **argv, + void *private_data) +{ + int ret = path_tool_append_generic(mem_ctx, + argc, + argv, + private_data, + "piddir append", + path_piddir_append); + return ret; +} + static int path_tool_rundir(TALLOC_CTX *mem_ctx, int argc, const char **argv, @@ -210,6 +266,34 @@ static int path_tool_rundir_append(TALLOC_CTX *mem_ctx, return ret; } +static int path_tool_socketdir(TALLOC_CTX *mem_ctx, + int argc, + const char **argv, + void *private_data) +{ + int ret = path_tool_generic(mem_ctx, + argc, + argv, + private_data, + "socketdir", + path_socketdir); + return ret; +} + +static int path_tool_socketdir_append(TALLOC_CTX *mem_ctx, + int argc, + const char **argv, + void *private_data) +{ + int ret = path_tool_append_generic(mem_ctx, + argc, + argv, + private_data, + "socketdir append", + path_socketdir_append); + return ret; +} + static int path_tool_vardir(TALLOC_CTX *mem_ctx, int argc, const char **argv, @@ -281,6 +365,30 @@ struct cmdline_command path_commands[] = { .msg_help = "Get path of CTDB ETCDIR", .msg_args = NULL, }, + { + .name = "lockdir append", + .fn = path_tool_lockdir_append, + .msg_help = "Get path relative to CTDB LOCKDIR", + .msg_args = "", + }, + { + .name = "lockdir", + .fn = path_tool_lockdir, + .msg_help = "Get path of CTDB LOCKDIR", + .msg_args = NULL, + }, + { + .name = "piddir append", + .fn = path_tool_piddir_append, + .msg_help = "Get path relative to CTDB PIDDIR", + .msg_args = "", + }, + { + .name = "piddir", + .fn = path_tool_piddir, + .msg_help = "Get path of CTDB PIDDIR", + .msg_args = NULL, + }, { .name = "rundir append", .fn = path_tool_rundir_append, @@ -293,6 +401,18 @@ struct cmdline_command path_commands[] = { .msg_help = "Get path of CTDB RUNDIR", .msg_args = NULL, }, + { + .name = "socketdir append", + .fn = path_tool_socketdir_append, + .msg_help = "Get path relative to CTDB SOCKETDIR", + .msg_args = "", + }, + { + .name = "socketdir", + .fn = path_tool_socketdir, + .msg_help = "Get path of CTDB SOCKETDIR", + .msg_args = NULL, + }, { .name = "vardir append", .fn = path_tool_vardir_append, diff --git a/ctdb/tests/UNIT/cunit/path_tests_001.sh b/ctdb/tests/UNIT/cunit/path_tests_001.sh index d38fd81ac92..513f0d47373 100755 --- a/ctdb/tests/UNIT/cunit/path_tests_001.sh +++ b/ctdb/tests/UNIT/cunit/path_tests_001.sh @@ -29,11 +29,26 @@ $CTDB_BASE EOF unit_test ctdb-path etcdir +ok <