ctdb-tests: Use path_socket() in dummy client
authorMartin Schwenke <martin@meltin.net>
Tue, 28 Aug 2018 22:23:51 +0000 (08:23 +1000)
committerAmitay Isaacs <amitay@samba.org>
Tue, 6 Nov 2018 06:16:14 +0000 (07:16 +0100)
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tests/src/dummy_client.c

index cc6444de968df79e18b7156e8c406c95a0b5a60a..22ba40f6e3bf1780344f9eba55502ff741621a0d 100644 (file)
@@ -25,6 +25,7 @@
 #include <tevent.h>
 
 #include "common/logging.h"
+#include "common/path.h"
 
 #include "client/client.h"
 
@@ -64,24 +65,18 @@ int main(int argc, const char *argv[])
        struct tevent_context *ev;
        struct ctdb_client_context **client;
        struct ctdb_client_context *last_client;
-       const char *ctdb_socket;
        poptContext pc;
        int opt, ret, i;
        int log_level;
        bool status, done;
 
        /* Set default options */
-       options.sockpath = CTDB_SOCKET;
+       options.sockpath = NULL;
        options.debuglevel = "ERR";
        options.num_connections = 1;
        options.timelimit = 60;
        options.srvidstr = NULL;
 
-       ctdb_socket = getenv("CTDB_SOCKET");
-       if (ctdb_socket != NULL) {
-               options.sockpath = ctdb_socket;
-       }
-
        pc = poptGetContext(argv[0], argc, argv, cmdline_options,
                            POPT_CONTEXT_KEEP_FIRST);
        while ((opt = poptGetNextOpt(pc)) != -1) {
@@ -89,12 +84,6 @@ int main(int argc, const char *argv[])
                exit(1);
        }
 
-       if (options.sockpath == NULL) {
-               fprintf(stderr, "Please specify socket path\n");
-               poptPrintHelp(pc, stdout, 0);
-               exit(1);
-       }
-
        mem_ctx = talloc_new(NULL);
        if (mem_ctx == NULL) {
                fprintf(stderr, "Memory allocation error\n");
@@ -117,6 +106,14 @@ int main(int argc, const char *argv[])
        setup_logging("dummy_client", DEBUG_STDERR);
        DEBUGLEVEL = log_level;
 
+       if (options.sockpath == NULL) {
+               options.sockpath = path_socket(mem_ctx, "ctdbd");
+               if (options.sockpath == NULL) {
+                       D_ERR("Memory allocation error\n");
+                       exit(1);
+               }
+       }
+
        client = talloc_array(mem_ctx, struct ctdb_client_context *,
                              options.num_connections);
        if (client == NULL) {