]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-common: Add basic path functionality for new directories
authorMartin Schwenke <mschwenke@ddn.com>
Mon, 6 Jul 2026 08:23:42 +0000 (18:23 +1000)
committerMartin Schwenke <martins@samba.org>
Mon, 13 Jul 2026 12:53:23 +0000 (12:53 +0000)
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 <mschwenke@ddn.com>
Reviewed-by: Anoop C S <anoopcs@samba.org>
ctdb/common/path.c
ctdb/common/path.h
ctdb/common/path_tool.c
ctdb/tests/UNIT/cunit/path_tests_001.sh

index 60bbd50ddc9cb3399f6533cf25b744fb5cc49bb0..c999a6240f4c0927ff0ee06e9039038872fa6b7c 100644 (file)
@@ -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);
index e3c7880ffc79d64b468e836b4e752cddbd94c0c0..068e11b96d0fa0e8d1ab0a4be8ed125eff7d5936 100644 (file)
 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);
index cd5e90fe74a033346669cfee6f72713c08d15e3b..e07388586385b4ad1dfdc36abedebd9f52a299ff 100644 (file)
@@ -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 = "<path>",
+       },
+       {
+               .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 = "<path>",
+       },
+       {
+               .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 = "<path>",
+       },
+       {
+               .name = "socketdir",
+               .fn = path_tool_socketdir,
+               .msg_help = "Get path of CTDB SOCKETDIR",
+               .msg_args = NULL,
+       },
        {
                .name = "vardir append",
                .fn = path_tool_vardir_append,
index d38fd81ac92ddf18c282a22ac52b4065732e5c80..513f0d473735f4994dc25352a9192614c310eb2f 100755 (executable)
@@ -29,11 +29,26 @@ $CTDB_BASE
 EOF
 unit_test ctdb-path etcdir
 
+ok <<EOF
+$CTDB_BASE/run
+EOF
+unit_test ctdb-path lockdir
+
+ok <<EOF
+$CTDB_BASE/run
+EOF
+unit_test ctdb-path piddir
+
 ok <<EOF
 $CTDB_BASE/run
 EOF
 unit_test ctdb-path rundir
 
+ok <<EOF
+$CTDB_BASE/run
+EOF
+unit_test ctdb-path socketdir
+
 ok <<EOF
 $CTDB_BASE/var
 EOF
@@ -49,11 +64,26 @@ $CTDB_BASE/foobar
 EOF
 unit_test ctdb-path etcdir append foobar
 
+ok <<EOF
+$CTDB_BASE/run/foobar
+EOF
+unit_test ctdb-path lockdir append foobar
+
+ok <<EOF
+$CTDB_BASE/run/foobar
+EOF
+unit_test ctdb-path piddir append foobar
+
 ok <<EOF
 $CTDB_BASE/run/foobar
 EOF
 unit_test ctdb-path rundir append foobar
 
+ok <<EOF
+$CTDB_BASE/run/foobar
+EOF
+unit_test ctdb-path socketdir append foobar
+
 ok <<EOF
 $CTDB_BASE/var/foobar
 EOF