]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-mutex: Drop dependency on ctdb_set_helper
authorMartin Schwenke <martin@meltin.net>
Fri, 19 Jul 2019 01:14:43 +0000 (11:14 +1000)
committerMartin Schwenke <martins@samba.org>
Fri, 26 Jul 2019 03:34:17 +0000 (03:34 +0000)
This makes the code more explicit and makes testing easier due to less
dependencies.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/server/ctdb_cluster_mutex.c

index 08784c0340c6709f67a0228198e368827d0765aa..2fbe301420eeea2a7adb44ebbf191fe9962e6225 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "replace.h"
 #include "system/network.h"
+#include "system/filesys.h"
 
 #include <tevent.h>
 
@@ -32,7 +33,6 @@
 #include "lib/util/blocking.h"
 
 #include "ctdb_private.h"
-#include "common/common.h"
 
 #include "ctdb_cluster_mutex.h"
 
@@ -121,21 +121,56 @@ static bool cluster_mutex_helper_args_file(TALLOC_CTX *mem_ctx,
                                           const char *argstring,
                                           char ***argv)
 {
-       bool ok;
+       struct stat st;
+       size_t size = sizeof(cluster_mutex_helper);
+       const char *t;
        char **args = NULL;
+       int ret;
+
+       if (cluster_mutex_helper[0] != '\0') {
+               goto helper_done;
+       }
 
-       ok = ctdb_set_helper("cluster mutex helper",
-                            cluster_mutex_helper,
-                            sizeof(cluster_mutex_helper),
-                            "CTDB_CLUSTER_MUTEX_HELPER",
-                            CTDB_HELPER_BINDIR,
-                            "ctdb_mutex_fcntl_helper");
-       if (! ok) {
-               DBG_ERR("ctdb exiting with error: "
-                       "Unable to set cluster mutex helper\n");
+       t = getenv("CTDB_CLUSTER_MUTEX_HELPER");
+       if (t != NULL) {
+               size_t len;
+
+               len = strlcpy(cluster_mutex_helper, t, size);
+               if (len >= size) {
+                       DBG_ERR("error: CTDB_CLUSTER_MUTEX_HELPER too long\n");
+                       exit(1);
+               }
+       } else {
+               ret = snprintf(cluster_mutex_helper,
+                              size,
+                              "%s/%s",
+                              CTDB_HELPER_BINDIR,
+                              "ctdb_mutex_fcntl_helper");
+               if (ret < 0 || (size_t)ret >= size) {
+                       D_ERR("Unable to set cluster mutex helper - "
+                             "path too long\n");
+                       exit(1);
+               }
+       }
+
+       ret = stat(cluster_mutex_helper, &st);
+       if (ret != 0) {
+               D_ERR("Unable to set cluster mutex helper \"%s\" - %s\n",
+                     cluster_mutex_helper,
+                     strerror(errno));
                exit(1);
        }
 
+       if ((st.st_mode & S_IXUSR) == 0) {
+               D_ERR("Unable to set cluster_mutex helper \"%s\" - "
+                     "not executable\n",
+                     cluster_mutex_helper);
+               exit(1);
+       }
+
+       D_NOTICE("Set cluster mutex helper to \"%s\"\n", cluster_mutex_helper);
+
+helper_done:
 
        /* Array includes default helper, file and NULL */
        args = talloc_array(mem_ctx, char *, 3);