ctdb: Remove <file> parameter from pfetch usage info
[amitay/samba.git] / ctdb / tools / ctdb.c
index d76d17612102262b2ec8282888119942a31a3de9..b598a866c9bd3ab6c090182608e33310fcffe09d 100644 (file)
 
 #include "common/db_hash.h"
 #include "common/logging.h"
+#include "common/path.h"
 #include "protocol/protocol.h"
 #include "protocol/protocol_api.h"
 #include "protocol/protocol_util.h"
-#include "common/system.h"
+#include "common/system_socket.h"
 #include "client/client.h"
 #include "client/client_sync.h"
 
@@ -50,7 +51,6 @@
 #define SRVID_CTDB_PUSHDB  (CTDB_SRVID_TOOL_RANGE | 0x0002000000000000LL)
 
 static struct {
-       const char *socket;
        const char *debuglevelstr;
        int timelimit;
        int pnn;
@@ -478,28 +478,16 @@ static struct ctdb_node_map *ctdb_read_nodes_file(TALLOC_CTX *mem_ctx,
 static struct ctdb_node_map *read_nodes_file(TALLOC_CTX *mem_ctx, uint32_t pnn)
 {
        struct ctdb_node_map *nodemap;
-       char *nodepath;
        const char *nodes_list = NULL;
 
-       if (pnn != CTDB_UNKNOWN_PNN) {
-               nodepath = talloc_asprintf(mem_ctx, "CTDB_NODES_%u", pnn);
-               if (nodepath != NULL) {
-                       nodes_list = getenv(nodepath);
-               }
-       }
-       if (nodes_list == NULL) {
-               nodes_list = getenv("CTDB_NODES");
+       const char *basedir = getenv("CTDB_BASE");
+       if (basedir == NULL) {
+               basedir = CTDB_ETCDIR;
        }
+       nodes_list = talloc_asprintf(mem_ctx, "%s/nodes", basedir);
        if (nodes_list == NULL) {
-               const char *basedir = getenv("CTDB_BASE");
-               if (basedir == NULL) {
-                       basedir = CTDB_ETCDIR;
-               }
-               nodes_list = talloc_asprintf(mem_ctx, "%s/nodes", basedir);
-               if (nodes_list == NULL) {
-                       fprintf(stderr, "Memory allocation error\n");
-                       return NULL;
-               }
+               fprintf(stderr, "Memory allocation error\n");
+               return NULL;
        }
 
        nodemap = ctdb_read_nodes_file(mem_ctx, nodes_list);
@@ -599,7 +587,7 @@ static int h2i(char h)
                return h - 'a' + 10;
        }
        if (h >= 'A' && h <= 'F') {
-               return h - 'f' + 10;
+               return h - 'A' + 10;
        }
        return h - '0';
 }
@@ -3038,10 +3026,11 @@ static int control_tickle(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
 
        if (argc == 0) {
                struct ctdb_connection_list *clist;
-               int i, num_failed;
+               int i;
+               unsigned int num_failed;
 
                /* Client first but the src/dst logic is confused */
-               ret = ctdb_connection_list_read(mem_ctx, false, &clist);
+               ret = ctdb_connection_list_read(mem_ctx, 0, false, &clist);
                if (ret != 0) {
                        return ret;
                }
@@ -3259,7 +3248,7 @@ static int control_addtickle(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
                struct tevent_req *req;
 
                /* Client first but the src/dst logic is confused */
-               ret = ctdb_connection_list_read(mem_ctx, false, &clist);
+               ret = ctdb_connection_list_read(mem_ctx, 0, false, &clist);
                if (ret != 0) {
                        return ret;
                }
@@ -3324,7 +3313,7 @@ static int control_deltickle(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
                struct tevent_req *req;
 
                /* Client first but the src/dst logic is confused */
-               ret = ctdb_connection_list_read(mem_ctx, false, &clist);
+               ret = ctdb_connection_list_read(mem_ctx, 0, false, &clist);
                if (ret != 0) {
                        return ret;
                }
@@ -3861,7 +3850,8 @@ static int control_addip(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
                usage("addip");
        }
 
-       if (! parse_ip_mask(argv[0], argv[1], &addr, &mask)) {
+       ret = ctdb_sock_addr_mask_from_string(argv[0], &addr, &mask);
+       if (ret != 0) {
                fprintf(stderr, "Invalid IP/Mask %s\n", argv[0]);
                return 1;
        }
@@ -4570,15 +4560,12 @@ static int control_event(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
                         int argc, const char **argv)
 {
        char *t, *event_helper = NULL;
-       char *eventd_socket = NULL;
-       const char **new_argv;
-       int i;
 
        t = getenv("CTDB_EVENT_HELPER");
        if (t != NULL) {
                event_helper = talloc_strdup(mem_ctx, t);
        } else {
-               event_helper = talloc_asprintf(mem_ctx, "%s/ctdb_event",
+               event_helper = talloc_asprintf(mem_ctx, "%s/ctdb-event",
                                               CTDB_HELPER_BINDIR);
        }
 
@@ -4587,49 +4574,25 @@ static int control_event(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
                return 1;
        }
 
-       t = getenv("CTDB_SOCKET");
-       if (t != NULL) {
-               eventd_socket = talloc_asprintf(mem_ctx, "%s/eventd.sock",
-                                               dirname(t));
-       } else {
-               eventd_socket = talloc_asprintf(mem_ctx, "%s/eventd.sock",
-                                               CTDB_RUNDIR);
-       }
-
-       if (eventd_socket == NULL) {
-               fprintf(stderr, "Unable to set event daemon socket\n");
-               return 1;
-       }
-
-       new_argv = talloc_array(mem_ctx, const char *, argc + 1);
-       if (new_argv == NULL) {
-               fprintf(stderr, "Memory allocation error\n");
-               return 1;
-       }
-
-       new_argv[0] = eventd_socket;
-       for (i=0; i<argc; i++) {
-               new_argv[i+1] = argv[i];
-       }
-
        return run_helper(mem_ctx, "event daemon helper", event_helper,
-                         argc+1, new_argv);
+                         argcargv);
 }
 
 static int control_scriptstatus(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
                                int argc, const char **argv)
 {
-       const char *new_argv[3];
+       const char *new_argv[4];
 
        if (argc > 1) {
                usage("scriptstatus");
        }
 
        new_argv[0] = "status";
-       new_argv[1] = (argc == 0) ? "monitor" : argv[0];
-       new_argv[2] = NULL;
+       new_argv[1] = "legacy";
+       new_argv[2] = (argc == 0) ? "monitor" : argv[0];
+       new_argv[3] = NULL;
 
-       (void) control_event(mem_ctx, ctdb, 2, new_argv);
+       (void) control_event(mem_ctx, ctdb, 3, new_argv);
        return 0;
 }
 
@@ -4841,7 +4804,7 @@ static int control_pfetch(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
        TDB_DATA key, data;
        int ret;
 
-       if (argc < 2 || argc > 3) {
+       if (argc != 2) {
                usage("pfetch");
        }
 
@@ -5992,9 +5955,9 @@ static const struct ctdb_cmd {
                "wipe the contents of a database.", "<dbname|dbid>"},
        { "recmaster", control_recmaster, false, true,
                "show the pnn for the recovery master", NULL },
-       { "event", control_event, false, false,
+       { "event", control_event, true, false,
                "event and event script commands", NULL },
-       { "scriptstatus", control_scriptstatus, false, false,
+       { "scriptstatus", control_scriptstatus, true, false,
                "show event script status",
                "[init|setup|startup|monitor|takeip|releaseip|ipreallocated]" },
        { "natgw", control_natgw, false, false,
@@ -6010,7 +5973,7 @@ static const struct ctdb_cmd {
        { "setdbsticky", control_setdbsticky, false, true,
                "enable sticky records", "<dbname|dbid>"},
        { "pfetch", control_pfetch, false, false,
-               "fetch record from persistent database", "<dbname|dbid> <key> [<file>]" },
+               "fetch record from persistent database", "<dbname|dbid> <key>" },
        { "pstore", control_pstore, false, false,
                "write record to persistent database", "<dbname|dbid> <key> <value>" },
        { "pdelete", control_pdelete, false, false,
@@ -6097,8 +6060,6 @@ static void usage(const char *command)
 
 struct poptOption cmdline_options[] = {
        POPT_AUTOHELP
-       { "socket", 's', POPT_ARG_STRING, &options.socket, 0,
-               "CTDB socket path", "filename" },
        { "debug", 'd', POPT_ARG_STRING, &options.debuglevelstr, 0,
                "debug level"},
        { "timelimit", 't', POPT_ARG_INT, &options.timelimit, 0,
@@ -6159,15 +6120,16 @@ static int process_command(const struct ctdb_cmd *cmd, int argc,
                goto fail;
        }
 
-       ctdb_socket = getenv("CTDB_SOCKET");
-       if (ctdb_socket != NULL) {
-               options.socket = ctdb_socket;
+       ctdb_socket = path_socket(ctdb, "ctdbd");
+       if (ctdb_socket == NULL) {
+               fprintf(stderr, "Memory allocation error\n");
+               goto fail;
        }
 
-       ret = ctdb_client_init(ctdb, ctdb->ev, options.socket, &ctdb->client);
+       ret = ctdb_client_init(ctdb, ctdb->ev, ctdb_socket, &ctdb->client);
        if (ret != 0) {
                fprintf(stderr, "Failed to connect to CTDB daemon (%s)\n",
-                       options.socket);
+                       ctdb_socket);
 
                if (!find_node_xpnn(ctdb, NULL)) {
                        fprintf(stderr, "Is this node part of CTDB cluster?\n");
@@ -6226,12 +6188,12 @@ int main(int argc, const char *argv[])
        int extra_argc;
        const struct ctdb_cmd *cmd;
        int loglevel;
+       bool ok;
        int ret;
 
        setlinebuf(stdout);
 
        /* Set default options */
-       options.socket = CTDB_SOCKET;
        options.debuglevelstr = NULL;
        options.timelimit = 10;
        options.sep = "|";
@@ -6285,11 +6247,11 @@ int main(int argc, const char *argv[])
 
        /* Enable logging */
        setup_logging("ctdb", DEBUG_STDERR);
-       if (debug_level_parse(options.debuglevelstr, &loglevel)) {
-               DEBUGLEVEL = loglevel;
-       } else {
-               DEBUGLEVEL = DEBUG_ERR;
+       ok = debug_level_parse(options.debuglevelstr, &loglevel);
+       if (!ok) {
+               loglevel = DEBUG_ERR;
        }
+       debuglevel_set(loglevel);
 
        signal(SIGALRM, alarm_handler);
        alarm(options.maxruntime);