/* startup a client only ctdb context */ struct ctdb_context *ctdb_cmdline_client(struct tevent_context *ev, struct timeval req_timeout) { struct ctdb_context *ctdb; char *socket_name; int ret; /* initialise ctdb */ ctdb = ctdb_init(ev); if (ctdb == NULL) { fprintf(stderr, "Failed to init ctdb\n"); exit(1); } /* tell ctdb the socket address */ socket_name = getenv("CTDB_SOCKET"); if (socket_name != NULL) { ret = ctdb_set_socketname(ctdb, socket_name); if (ret == -1) { printf("ctdb_set_socketname failed - %s\n", ctdb_errstr(ctdb)); exit(1); } } if (ctdb_cmdline.socketname != NULL) { ret = ctdb_set_socketname(ctdb, ctdb_cmdline.socketname); if (ret == -1) { fprintf(stderr, "ctdb_set_socketname failed - %s\n", ctdb_errstr(ctdb)); exit(1); } } /* Set the debug level */ if (!parse_debug(ctdb_cmdline.debuglevel, &DEBUGLEVEL)) { DEBUGLEVEL = DEBUG_ERR; } ret = ctdb_socket_connect(ctdb); if (ret != 0) { fprintf(stderr, __location__ " Failed to connect to daemon\n"); talloc_free(ctdb); return NULL; } /* get our pnn */ ctdb->pnn = ctdb_ctrl_getpnn(ctdb, req_timeout, CTDB_CURRENT_NODE); if (ctdb->pnn == (uint32_t)-1) { DEBUG(DEBUG_CRIT,(__location__ " Failed to get ctdb pnn\n")); talloc_free(ctdb); return NULL; } return ctdb; }
/* startup daemon side of ctdb according to command line options */ struct ctdb_context *ctdb_cmdline_init(struct event_context *ev) { struct ctdb_context *ctdb; int ret; /* initialise ctdb */ ctdb = ctdb_init(ev); if (ctdb == NULL) { printf("Failed to init ctdb\n"); exit(1); } if (ctdb_cmdline.torture) { ctdb_set_flags(ctdb, CTDB_FLAG_TORTURE); } /* command line specified a socket name */ if (ctdb_cmdline.socketname != NULL) { setenv("CTDB_SOCKET", ctdb_cmdline.socketname, 1); ret = ctdb_set_socketname(ctdb, ctdb_cmdline.socketname); if (ret == -1) { printf("ctdb_set_socketname failed - %s\n", ctdb_errstr(ctdb)); exit(1); } } /* Set the debug level */ if (isalpha(ctdb_cmdline.debuglevel[0]) || ctdb_cmdline.debuglevel[0] == '-') { LogLevel = get_debug_by_desc(ctdb_cmdline.debuglevel); } else { LogLevel = strtol(ctdb_cmdline.debuglevel, NULL, 0); } /* set up the tree to store server ids */ ctdb->server_ids = trbt_create(ctdb, 0); return ctdb; }
/* startup daemon side of ctdb according to command line options */ struct ctdb_context *ctdb_cmdline_init(struct event_context *ev) { struct ctdb_context *ctdb; int ret; /* initialise ctdb */ ctdb = ctdb_init(ev); if (ctdb == NULL) { printf("Failed to init ctdb\n"); exit(1); } if (ctdb_cmdline.torture) { ctdb_set_flags(ctdb, CTDB_FLAG_TORTURE); } /* command line specified a socket name */ if (ctdb_cmdline.socketname != NULL) { setenv("CTDB_SOCKET", ctdb_cmdline.socketname, 1); ret = ctdb_set_socketname(ctdb, ctdb_cmdline.socketname); if (ret == -1) { printf("ctdb_set_socketname failed - %s\n", ctdb_errstr(ctdb)); exit(1); } } /* Set the debug level */ if (!parse_debug(ctdb_cmdline.debuglevel, &DEBUGLEVEL)) { DEBUGLEVEL = DEBUG_ERR; } /* set up the tree to store server ids */ ctdb->server_ids = trbt_create(ctdb, 0); return ctdb; }
static int pmda_ctdb_daemon_connect(void) { const char *socket_name; int ret; struct sockaddr_un addr; ev = tevent_context_init(NULL); if (ev == NULL) { fprintf(stderr, "Failed to init event ctx\n"); return -1; } ctdb = ctdb_init(ev); if (ctdb == NULL) { fprintf(stderr, "Failed to init ctdb\n"); goto err_ev; } socket_name = getenv("CTDB_SOCKET"); if (socket_name == NULL) { socket_name = CTDB_SOCKET; } ret = ctdb_set_socketname(ctdb, socket_name); if (ret == -1) { fprintf(stderr, "ctdb_set_socketname failed - %s\n", ctdb_errstr(ctdb)); goto err_ctdb; } /* * ctdb_socket_connect() sets a default queue callback handler that * calls exit() if ctdbd is unavailable on recv, use our own wrapper to * work around this */ memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; strncpy(addr.sun_path, ctdb->daemon.name, sizeof(addr.sun_path)); ctdb->daemon.sd = socket(AF_UNIX, SOCK_STREAM, 0); if (ctdb->daemon.sd == -1) { fprintf(stderr, "Failed to open client socket\n"); goto err_ctdb; } set_nonblocking(ctdb->daemon.sd); set_close_on_exec(ctdb->daemon.sd); if (connect(ctdb->daemon.sd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { fprintf(stderr, "Failed to connect to ctdb daemon via %s\n", ctdb->daemon.name); goto err_sd; } ctdb->daemon.queue = ctdb_queue_setup(ctdb, ctdb, ctdb->daemon.sd, CTDB_DS_ALIGNMENT, pmda_ctdb_q_read_cb, ctdb, "to-ctdbd"); if (ctdb->daemon.queue == NULL) { fprintf(stderr, "Failed to setup queue\n"); goto err_sd; } ctdb->pnn = ctdb_ctrl_getpnn(ctdb, timeval_current_ofs(3, 0), CTDB_CURRENT_NODE); if (ctdb->pnn == (uint32_t)-1) { fprintf(stderr, "Failed to get ctdb pnn\n"); goto err_sd; } return 0; err_sd: close(ctdb->daemon.sd); err_ctdb: talloc_free(ctdb); err_ev: talloc_free(ev); ctdb = NULL; return -1; }