19 #include <sys/types.h> 28 static GHashTable *cib_op_callback_table = NULL;
30 #define op_common(cib) do { \ 33 } else if(cib->delegate_fn == NULL) { \ 34 return -EPROTONOSUPPORT; \ 39 cib_client_set_op_callback(
cib_t *cib,
40 void (*callback) (
const xmlNode * msg,
int call_id,
41 int rc, xmlNode * output))
43 if (callback == NULL) {
44 crm_info(
"Un-Setting operation callback");
54 ciblib_GCompareFunc(gconstpointer a, gconstpointer b)
66 crm_trace(
"callbacks for %s are not equal: %p < %p",
70 crm_trace(
"callbacks for %s are not equal: %p > %p",
78 cib_client_add_notify_callback(
cib_t * cib,
const char *event,
79 void (*callback) (
const char *event,
82 GList *list_item = NULL;
86 return -EPROTONOSUPPORT;
89 crm_trace(
"Adding callback for %s events (%d)",
93 new_client->
event = event;
96 list_item = g_list_find_custom(cib->
notify_list, new_client,
99 if (list_item != NULL) {
100 crm_warn(
"Callback already present");
115 get_notify_list_event_count(
cib_t *cib,
const char *event)
119 for (GList *iter = g_list_first(cib->
notify_list); iter != NULL;
123 if (strcmp(client->
event, event) == 0) {
127 crm_trace(
"event(%s) count : %d", event, count);
132 cib_client_del_notify_callback(
cib_t *cib,
const char *event,
133 void (*callback) (
const char *event,
136 GList *list_item = NULL;
140 return -EPROTONOSUPPORT;
143 if (get_notify_list_event_count(cib, event) == 0) {
144 crm_debug(
"The callback of the event does not exist(%s)", event);
148 crm_debug(
"Removing callback for %s events", event);
151 new_client->
event = event;
154 list_item = g_list_find_custom(cib->
notify_list, new_client, ciblib_GCompareFunc);
156 if (list_item != NULL) {
168 if (get_notify_list_event_count(cib, event) == 0) {
178 cib_async_timeout_handler(gpointer
data)
182 crm_debug(
"Async call %d timed out after %ds",
187 return G_SOURCE_CONTINUE;
192 gboolean only_success,
void *user_data,
193 const char *callback_name,
194 void (*callback)(xmlNode *,
int,
int,
196 void (*free_func)(
void *))
201 if (only_success == FALSE) {
206 if (user_data && free_func) {
207 free_func(user_data);
213 blob->
id = callback_name;
222 async_timer = calloc(1,
sizeof(
struct timer_rec_s));
223 blob->
timer = async_timer;
228 async_timer->
ref = g_timeout_add(async_timer->
timeout,
229 cib_async_timeout_handler,
234 pcmk__intkey_table_insert(cib_op_callback_table,
call_id, blob);
241 gboolean only_success,
void *user_data,
242 const char *callback_name,
243 void (*callback) (xmlNode *,
int,
int, xmlNode *,
247 only_success, user_data,
248 callback_name, callback, NULL);
252 cib_client_noop(
cib_t *
cib,
int call_options)
260 cib_client_ping(
cib_t *
cib, xmlNode ** output_data,
int call_options)
267 cib_client_query(
cib_t *
cib,
const char *section, xmlNode ** output_data,
int call_options)
273 cib_client_query_from(
cib_t *
cib,
const char *
host,
const char *section,
274 xmlNode ** output_data,
int call_options)
278 output_data, call_options, NULL);
290 set_secondary(
cib_t *
cib,
int call_options)
294 NULL, call_options, NULL);
298 set_all_secondary(
cib_t *
cib,
int call_options)
300 return -EPROTONOSUPPORT;
304 set_primary(
cib_t *
cib,
int call_options)
307 crm_trace(
"Adding cib_scope_local to options");
313 cib_client_bump_epoch(
cib_t *
cib,
int call_options)
321 cib_client_upgrade(
cib_t *
cib,
int call_options)
325 NULL, call_options, NULL);
329 cib_client_sync(
cib_t *
cib,
const char *section,
int call_options)
335 cib_client_sync_from(
cib_t *
cib,
const char *
host,
const char *section,
int call_options)
339 NULL, NULL, call_options, NULL);
343 cib_client_create(
cib_t *
cib,
const char *section, xmlNode *
data,
int call_options)
347 NULL, call_options, NULL);
351 cib_client_modify(
cib_t *
cib,
const char *section, xmlNode *
data,
int call_options)
355 NULL, call_options, NULL);
359 cib_client_replace(
cib_t *
cib,
const char *section, xmlNode *
data,
int call_options)
363 NULL, call_options, NULL);
367 cib_client_delete(
cib_t *
cib,
const char *section, xmlNode *
data,
int call_options)
371 NULL, call_options, NULL);
375 cib_client_delete_absolute(
cib_t *
cib,
const char *section, xmlNode *
data,
int call_options)
379 data, NULL, call_options, NULL);
383 cib_client_erase(
cib_t *
cib, xmlNode ** output_data,
int call_options)
387 output_data, call_options, NULL);
391 cib_destroy_op_callback(gpointer
data)
408 destroy_op_callback_table(
void)
410 if (cib_op_callback_table != NULL) {
411 g_hash_table_destroy(cib_op_callback_table);
412 cib_op_callback_table = NULL;
419 char *cib_home = NULL;
420 char *fullname = NULL;
422 const char *dir = getenv(
"CIB_shadow_dir");
425 uid_t uid = geteuid();
426 struct passwd *pwent = getpwuid(uid);
427 const char *user = NULL;
430 user = pwent->pw_name;
432 user = getenv(
"USER");
434 "Assuming %s because cannot get user details for user ID %d",
435 (user? user :
"unprivileged user"), uid);
442 const char *home = NULL;
444 if ((home = getenv(
"HOME")) == NULL) {
446 home = pwent->pw_dir;
451 if (home && home[0] ==
'/') {
456 rc = mkdir(cib_home, 0700);
457 if (rc < 0 && errno != EEXIST) {
458 crm_perror(LOG_ERR,
"Couldn't create user-specific shadow directory: %s",
479 cib_t *new_cib = NULL;
480 char *shadow_file = NULL;
506 const char *shadow = getenv(
"CIB_shadow");
509 unsetenv(
"CIB_shadow");
512 if (shadow != NULL) {
513 setenv(
"CIB_shadow", shadow, 1);
537 const char *value = getenv(
"CIB_shadow");
540 if (value && value[0] != 0) {
544 value = getenv(
"CIB_file");
549 value = getenv(
"CIB_port");
551 gboolean encrypted = TRUE;
552 const char *server = getenv(
"CIB_server");
553 const char *user = getenv(
"CIB_user");
554 const char *pass = getenv(
"CIB_passwd");
563 value = getenv(
"CIB_encrypted");
571 crm_info(
"Defaulting to user: %s", user);
574 if (server == NULL) {
575 server =
"localhost";
576 crm_info(
"Defaulting to localhost");
597 cib_t *new_cib = NULL;
599 new_cib = calloc(1,
sizeof(
cib_t));
601 if (new_cib == NULL) {
620 if (new_cib->
cmds == NULL) {
631 new_cib->
cmds->
noop = cib_client_noop;
632 new_cib->
cmds->
ping = cib_client_ping;
634 new_cib->
cmds->
sync = cib_client_sync;
671 while (list != NULL) {
674 list = g_list_remove(list, client);
691 destroy_op_callback_table();
712 destroy_op_callback_table();
713 cib_op_callback_table = pcmk__intkey_table(cib_destroy_op_callback);
715 pcmk__intkey_table_remove(cib_op_callback_table, call_id);
722 if (cib_op_callback_table == NULL) {
725 return g_hash_table_size(cib_op_callback_table);
729 cib_dump_pending_op(gpointer key, gpointer value, gpointer user_data)
731 int call = GPOINTER_TO_INT(key);
734 crm_debug(
"Call %d (%s): pending", call, pcmk__s(blob->
id,
"without ID"));
740 if (cib_op_callback_table == NULL) {
743 return g_hash_table_foreach(cib_op_callback_table, cib_dump_pending_op, NULL);
749 return pcmk__intkey_table_lookup(cib_op_callback_table, call_id);
#define CRM_CHECK(expr, failure_action)
const char * pcmk_strerror(int rc)
gboolean(* register_callback)(cib_t *cib, int call_id, int timeout, gboolean only_success, void *user_data, const char *callback_name, void(*callback)(xmlNode *, int, int, xmlNode *, void *))
cib_t * cib_remote_new(const char *server, const char *user, const char *passwd, int port, gboolean encrypted)
#define PCMK__CIB_REQUEST_PRIMARY
void cib_dump_pending_callbacks(void)
#define PCMK__CIB_REQUEST_CREATE
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
int(* delete_absolute)(cib_t *cib, const char *section, xmlNode *data, int call_options)
gboolean(* register_callback_full)(cib_t *cib, int call_id, int timeout, gboolean only_success, void *user_data, const char *callback_name, void(*callback)(xmlNode *, int, int, xmlNode *, void *), void(*free_func)(void *))
void(* callback)(const char *event, xmlNode *msg)
#define PCMK__CIB_REQUEST_QUERY
void cib_free_callbacks(cib_t *cib)
Free all callbacks for a CIB connection.
cib_t * cib_new(void)
Create a new CIB connection object.
cib_t * cib_shadow_new(const char *shadow)
int(* set_secondary)(cib_t *cib, int call_options)
Set the local CIB manager as a secondary instance.
#define PCMK__CIB_REQUEST_ERASE
int(* set_op_callback)(cib_t *cib, void(*callback)(const xmlNode *msg, int callid, int rc, xmlNode *output))
int(* sync)(cib_t *cib, const char *section, int call_options)
#define PCMK__CIB_REQUEST_ABS_DELETE
#define crm_warn(fmt, args...)
struct timer_rec_s * timer
int(* query_from)(cib_t *cib, const char *host, const char *section, xmlNode **output_data, int call_options)
int pcmk__scan_port(const char *text, int *port)
cib_api_operations_t * cmds
#define crm_debug(fmt, args...)
int num_cib_op_callbacks(void)
int(* set_slave)(cib_t *cib, int call_options)
#define PCMK__CIB_REQUEST_IS_PRIMARY
void(* callback)(xmlNode *, int, int, xmlNode *, void *)
#define crm_trace(fmt, args...)
int setenv(const char *name, const char *value, int why)
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
int(* modify)(cib_t *cib, const char *section, xmlNode *data, int call_options)
void(* op_callback)(const xmlNode *msg, int call_id, int rc, xmlNode *output)
char * get_shadow_file(const char *suffix)
int(* create)(cib_t *cib, const char *section, xmlNode *data, int call_options)
Wrappers for and extensions to libxml2.
int(* query)(cib_t *cib, const char *section, xmlNode **output_data, int call_options)
int(* is_master)(cib_t *cib)
cib_t * cib_new_no_shadow(void)
Create a new CIB connection object, ignoring any active shadow CIB.
cib_t * cib_native_new(void)
int(* replace)(cib_t *cib, const char *section, xmlNode *data, int call_options)
int(* add_notify_callback)(cib_t *cib, const char *event, void(*callback)(const char *event, xmlNode *msg))
int(* sync_from)(cib_t *cib, const char *host, const char *section, int call_options)
int(* register_notification)(cib_t *cib, const char *callback, int enabled)
int(* ping)(cib_t *cib, xmlNode **output_data, int call_options)
int(* update)(cib_t *cib, const char *section, xmlNode *data, int call_options)
#define PCMK__CIB_REQUEST_UPGRADE
cib_t * cib_file_new(const char *filename)
cib_callback_client_t * cib__lookup_id(int call_id)
#define PCMK__CIB_REQUEST_BUMP
int(* set_primary)(cib_t *cib, int call_options)
Set the local CIB manager as the cluster's primary instance.
int(* noop)(cib_t *cib, int call_options)
const char * pcmk__get_tmpdir(void)
int(* set_slave_all)(cib_t *cib, int call_options)
int(* del_notify_callback)(cib_t *cib, const char *event, void(*callback)(const char *event, xmlNode *msg))
#define crm_perror(level, fmt, args...)
Send a system error message to both the log and stderr.
void cib_free_notify(cib_t *cib)
#define PCMK__CIB_REQUEST_REPLACE
int(* set_master)(cib_t *cib, int call_options)
#define PCMK__CIB_REQUEST_SYNC_TO_ALL
#define PCMK__CIB_REQUEST_SECONDARY
#define PCMK__CIB_REQUEST_NOOP
void cib_native_callback(cib_t *cib, xmlNode *msg, int call_id, int rc)
cib_t * cib_new_variant(void)
int(* bump_epoch)(cib_t *cib, int call_options)
gboolean crm_is_true(const char *s)
#define PCMK__CIB_REQUEST_MODIFY
int(* remove)(cib_t *cib, const char *section, xmlNode *data, int call_options)
int cib_internal_op(cib_t *cib, const char *op, const char *host, const char *section, xmlNode *data, xmlNode **output_data, int call_options, const char *user_name)
void cib_delete(cib_t *cib)
Free all memory used by CIB connection.
void(* free_func)(void *)
int(* upgrade)(cib_t *cib, int call_options)
#define crm_info(fmt, args...)
int(* erase)(cib_t *cib, xmlNode **output_data, int call_options)
void remove_cib_op_callback(int call_id, gboolean all_callbacks)
#define PCMK__CIB_REQUEST_DELETE