#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"
#define SRVID_CTDB_PUSHDB (CTDB_SRVID_TOOL_RANGE | 0x0002000000000000LL)
static struct {
- const char *socket;
const char *debuglevelstr;
int timelimit;
int pnn;
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);
return h - 'a' + 10;
}
if (h >= 'A' && h <= 'F') {
- return h - 'f' + 10;
+ return h - 'A' + 10;
}
return h - '0';
}
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;
}
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;
}
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;
}
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;
}
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);
}
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);
+ argc, argv);
}
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;
}
TDB_DATA key, data;
int ret;
- if (argc < 2 || argc > 3) {
+ if (argc != 2) {
usage("pfetch");
}
"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,
{ "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,
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,
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");
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 = "|";
/* 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);