]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-common: Add path_helperdir() and path_helperdir_append()
authorMartin Schwenke <mschwenke@ddn.com>
Mon, 27 Oct 2025 04:47:55 +0000 (15:47 +1100)
committerVolker Lendecke <vl@samba.org>
Wed, 25 Feb 2026 12:33:39 +0000 (12:33 +0000)
These can be used to locate helpers, either during in-tree
testing (using $CTDB_TEST_HELPER_BINDIR) or in their configured
installation location.

Signed-off-by: Martin Schwenke <mschwenke@ddn.com>
Reviewed-by: Anoop C S <anoopcs@samba.org>
ctdb/common/path.c
ctdb/common/path.h

index 0d9354294600639945ddae4a63becfc770feea55..60bbd50ddc9cb3399f6533cf25b744fb5cc49bb0 100644 (file)
@@ -30,17 +30,20 @@ struct {
        char *basedir;
        char datadir[PATH_MAX];
        char etcdir[PATH_MAX];
+       const char* helperdir;
        char rundir[PATH_MAX];
        char vardir[PATH_MAX];
        bool test_mode;
        bool basedir_set;
        bool datadir_set;
        bool etcdir_set;
+       bool helperdir_set;
        bool rundir_set;
        bool vardir_set;
 } ctdb_paths = {
        .datadir = CTDB_DATADIR,
        .etcdir = CTDB_ETCDIR,
+       .helperdir = CTDB_HELPER_BINDIR,
        .rundir = CTDB_RUNDIR,
        .vardir = CTDB_VARDIR,
 };
@@ -143,6 +146,29 @@ const char *path_etcdir(void)
        return ctdb_paths.etcdir;
 }
 
+const char *path_helperdir(void)
+{
+       path_set_test_mode();
+       if (!ctdb_paths.test_mode) {
+               goto done;
+       }
+
+       if (ctdb_paths.helperdir_set) {
+               goto done;
+       }
+
+       ctdb_paths.helperdir = getenv("CTDB_TEST_HELPER_BINDIR");
+       if (ctdb_paths.helperdir == NULL) {
+               D_ERR("Broken CTDB setup, "
+                     "CTDB_TEST_HELPER_BINDIR not set in test mode\n");
+               abort();
+       }
+
+done:
+       ctdb_paths.helperdir_set = true;
+       return ctdb_paths.helperdir;
+}
+
 const char *path_rundir(void)
 {
        bool ok;
@@ -185,6 +211,11 @@ char *path_etcdir_append(TALLOC_CTX *mem_ctx, const char *path)
        return talloc_asprintf(mem_ctx, "%s/%s", path_etcdir(), path);
 }
 
+char *path_helperdir_append(TALLOC_CTX *mem_ctx, const char *path)
+{
+       return talloc_asprintf(mem_ctx, "%s/%s", path_helperdir(), path);
+}
+
 char *path_rundir_append(TALLOC_CTX *mem_ctx, const char *path)
 {
        return talloc_asprintf(mem_ctx, "%s/%s", path_rundir(), path);
index dcc6c20638df5f2bdb9fca064e81b7896b06e647..e3c7880ffc79d64b468e836b4e752cddbd94c0c0 100644 (file)
 
 const char *path_datadir(void);
 const char *path_etcdir(void);
+const char *path_helperdir(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_helperdir_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);