2 common commandline code to ctdb test tools
4 Copyright (C) Andrew Tridgell 2007
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "lib/events/events.h"
22 #include "system/filesys.h"
24 #include "../include/ctdb.h"
25 #include "../include/ctdb_private.h"
27 /* Handle common command line options for ctdb test progs
31 const char *socketname;
35 .socketname = CTDB_PATH,
39 enum {OPT_EVENTSYSTEM=1};
41 static void ctdb_cmdline_callback(poptContext con,
42 enum poptCallbackReason reason,
43 const struct poptOption *opt,
44 const char *arg, const void *data)
48 event_set_default_backend(arg);
54 struct poptOption popt_ctdb_cmdline[] = {
55 { NULL, 0, POPT_ARG_CALLBACK, (void *)ctdb_cmdline_callback },
56 { "socket", 0, POPT_ARG_STRING, &ctdb_cmdline.socketname, 0, "local socket name", "filename" },
57 { "debug", 'd', POPT_ARG_INT, &LogLevel, 0, "debug level"},
58 { "torture", 0, POPT_ARG_NONE, &ctdb_cmdline.torture, 0, "enable nastiness in library", NULL },
59 { "events", 0, POPT_ARG_STRING, NULL, OPT_EVENTSYSTEM, "event system", NULL },
65 startup daemon side of ctdb according to command line options
67 struct ctdb_context *ctdb_cmdline_init(struct event_context *ev)
69 struct ctdb_context *ctdb;
75 printf("Failed to init ctdb\n");
79 if (ctdb_cmdline.torture) {
80 ctdb_set_flags(ctdb, CTDB_FLAG_TORTURE);
83 /* tell ctdb the socket address */
84 ret = ctdb_set_socketname(ctdb, ctdb_cmdline.socketname);
86 printf("ctdb_set_socketname failed - %s\n", ctdb_errstr(ctdb));
95 startup a client only ctdb context
97 struct ctdb_context *ctdb_cmdline_client(struct event_context *ev)
99 struct ctdb_context *ctdb;
102 /* initialise ctdb */
103 ctdb = ctdb_init(ev);
105 printf("Failed to init ctdb\n");
109 /* tell ctdb the socket address */
110 ret = ctdb_set_socketname(ctdb, ctdb_cmdline.socketname);
112 printf("ctdb_set_socketname failed - %s\n", ctdb_errstr(ctdb));
116 ret = ctdb_socket_connect(ctdb);
118 DEBUG(0,(__location__ " Failed to connect to daemon\n"));
124 ctdb->vnn = ctdb_ctrl_getvnn(ctdb, timeval_zero(), CTDB_CURRENT_NODE);
125 if (ctdb->vnn == (uint32_t)-1) {
126 DEBUG(0,(__location__ " Failed to get ctdb vnn\n"));