ctdb-daemon: Use path functions for socket and PID file
authorMartin Schwenke <martin@meltin.net>
Thu, 10 May 2018 07:32:33 +0000 (17:32 +1000)
committerAmitay Isaacs <amitay@samba.org>
Tue, 6 Nov 2018 06:16:14 +0000 (07:16 +0100)
Drop the use of ctdb_set_sockname() because it complicates the memory
allocation and this is the only place it is used.  Just assign to the
relevant pointer.

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

index 721347c4733a80f99ed00edf25ee37820ed7affa..9a8e0e8c3f47e6a7c83b316ee67e07bed37fbbfb 100644 (file)
@@ -38,6 +38,7 @@
 #include "common/reqid.h"
 #include "common/system.h"
 #include "common/common.h"
+#include "common/path.h"
 #include "common/logging.h"
 #include "common/logging_conf.h"
 
@@ -100,9 +101,16 @@ static struct ctdb_context *ctdb_init(struct tevent_context *ev)
                return NULL;
        }
 
-       ret = ctdb_set_socketname(ctdb, CTDB_SOCKET);
-       if (ret != 0) {
-               DBG_ERR("ctdb_set_socketname failed.\n");
+       ctdb->daemon.name = path_socket(ctdb, "ctdbd");
+       if (ctdb->daemon.name == NULL) {
+               DBG_ERR("Memory allocation error\n");
+               talloc_free(ctdb);
+               return NULL;
+       }
+
+       ctdbd_pidfile = path_pidfile(ctdb, "ctdbd");
+       if (ctdbd_pidfile == NULL) {
+               DBG_ERR("Memory allocation error\n");
                talloc_free(ctdb);
                return NULL;
        }
@@ -145,7 +153,6 @@ int main(int argc, const char *argv[])
 {
        struct ctdb_context *ctdb = NULL;
        int interactive = 0;
-       const char *ctdb_socket;
 
        struct poptOption popt_options[] = {
                POPT_AUTOHELP
@@ -356,23 +363,6 @@ int main(int argc, const char *argv[])
         * Testing and debug options
         */
 
-       /* Environment variable overrides default */
-       ctdbd_pidfile = getenv("CTDB_PIDFILE");
-       if (ctdbd_pidfile == NULL) {
-               ctdbd_pidfile = CTDB_RUNDIR "/ctdbd.pid";
-       }
-
-       /* Environment variable overrides default */
-       ctdb_socket = getenv("CTDB_SOCKET");
-       if (ctdb_socket == NULL) {
-               ctdb_socket = CTDB_SOCKET;
-       }
-       ret = ctdb_set_socketname(ctdb, ctdb_socket);
-       if (ret == -1) {
-               D_ERR("ctdb_set_socketname() failed\n");
-               goto fail;
-       }
-
        t = getenv("CTDB_TEST_MODE");
        if (t != NULL) {
                ctdb->do_setsched = false;