28 #include <sys/types.h> 40 int rc, xmlNode * output));
43 void (*callback) (
const char *event, xmlNode * msg));
46 void (*callback) (
const char *event, xmlNode * msg));
50 #define op_common(cib) do { \ 53 } else if(cib->delegate_fn == NULL) { \ 54 return -EPROTONOSUPPORT; \ 59 cib_client_noop(
cib_t * cib,
int call_options)
66 cib_client_ping(
cib_t * cib, xmlNode ** output_data,
int call_options)
73 cib_client_query(
cib_t * cib,
const char *section, xmlNode ** output_data,
int call_options)
75 return cib->
cmds->
query_from(cib, NULL, section, output_data, call_options);
79 cib_client_query_from(
cib_t * cib,
const char *
host,
const char *section,
80 xmlNode ** output_data,
int call_options)
87 cib_client_is_master(
cib_t * cib)
95 cib_client_set_slave(
cib_t * cib,
int call_options)
102 cib_client_set_slave_all(
cib_t * cib,
int call_options)
104 return -EPROTONOSUPPORT;
108 cib_client_set_master(
cib_t * cib,
int call_options)
111 crm_trace(
"Adding cib_scope_local to options");
117 cib_client_bump_epoch(
cib_t * cib,
int call_options)
124 cib_client_upgrade(
cib_t * cib,
int call_options)
131 cib_client_sync(
cib_t * cib,
const char *section,
int call_options)
133 return cib->
cmds->
sync_from(cib, NULL, section, call_options);
137 cib_client_sync_from(
cib_t * cib,
const char *host,
const char *section,
int call_options)
144 cib_client_create(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
151 cib_client_modify(
cib_t * cib,
const char *section, xmlNode * data,
int call_options)
158 cib_client_update(
cib_t * cib,
const char *section, xmlNode * data,
int call_options)
165 cib_client_replace(
cib_t * cib,
const char *section, xmlNode * data,
int call_options)
172 cib_client_delete(
cib_t * cib,
const char *section, xmlNode * data,
int call_options)
179 cib_client_delete_absolute(
cib_t * cib,
const char *section, xmlNode * data,
int call_options)
186 cib_client_erase(
cib_t * cib, xmlNode ** output_data,
int call_options)
193 cib_destroy_op_callback(gpointer data)
212 char *cib_home = NULL;
213 char *fullname = NULL;
214 char *name =
crm_concat(
"shadow", suffix,
'.');
215 const char *dir = getenv(
"CIB_shadow_dir");
218 uid_t uid = geteuid();
219 struct passwd *pwent = getpwuid(uid);
220 const char *user = NULL;
223 user = pwent->pw_name;
225 crm_perror(LOG_ERR,
"Cannot get password entry for uid: %d", uid);
226 user = getenv(
"USER");
233 const char *home = NULL;
235 if ((home = getenv(
"HOME")) == NULL) {
237 home = pwent->pw_dir;
241 if ((dir = getenv(
"TMPDIR")) == NULL) {
244 if (home && home[0] ==
'/') {
249 rc = mkdir(cib_home, 0700);
250 if (rc < 0 && errno != EEXIST) {
251 crm_perror(LOG_ERR,
"Couldn't create user-specific shadow directory: %s",
272 cib_t *new_cib = NULL;
273 char *shadow_file = NULL;
287 unsetenv(
"CIB_shadow");
294 const char *value = getenv(
"CIB_shadow");
296 if (value && value[0] != 0) {
300 value = getenv(
"CIB_file");
305 value = getenv(
"CIB_port");
307 gboolean encrypted = TRUE;
309 const char *server = getenv(
"CIB_server");
310 const char *user = getenv(
"CIB_user");
311 const char *pass = getenv(
"CIB_passwd");
313 value = getenv(
"CIB_encrypted");
321 crm_info(
"Defaulting to user: %s", user);
324 if (server == NULL) {
325 server =
"localhost";
326 crm_info(
"Defaulting to localhost");
347 cib_t *new_cib = NULL;
349 new_cib = calloc(1,
sizeof(
cib_t));
357 NULL, cib_destroy_op_callback);
379 new_cib->
cmds->
noop = cib_client_noop;
380 new_cib->
cmds->
ping = cib_client_ping;
382 new_cib->
cmds->
sync = cib_client_sync;
415 while (list != NULL) {
418 list = g_list_remove(list, client);
434 int rc, xmlNode * output))
436 if (callback == NULL) {
437 crm_info(
"Un-Setting operation callback");
448 void (*callback) (
const char *event, xmlNode * msg))
450 GList *list_item = NULL;
454 return -EPROTONOSUPPORT;
460 new_client->
event = event;
465 if (list_item != NULL) {
466 crm_warn(
"Callback already present");
481 get_notify_list_event_count(
cib_t * cib,
const char *event)
486 for (l = g_list_first(cib->
notify_list); l; l = g_list_next(l)) {
489 if (strcmp(client->
event, event) == 0) {
493 crm_trace(
"event(%s) count : %d", event, count);
499 void (*callback) (
const char *event, xmlNode * msg))
501 GList *list_item = NULL;
505 return -EPROTONOSUPPORT;
508 if (get_notify_list_event_count(cib, event) == 0) {
509 crm_debug(
"The callback of the event does not exist(%s)", event);
513 crm_debug(
"Removing callback for %s events", event);
516 new_client->
event = event;
521 if (list_item != NULL) {
533 if (get_notify_list_event_count(cib, event) == 0) {
550 rc = strcmp(a_client->
event, b_client->
event);
555 crm_trace(
"callbacks for %s are not equal: %p < %p",
559 crm_trace(
"callbacks for %s are not equal: %p > %p",
567 cib_async_timeout_handler(gpointer data)
582 void *user_data,
const char *callback_name,
583 void (*callback) (xmlNode *,
int,
int, xmlNode *,
void *))
586 only_success, user_data,
587 callback_name, callback, NULL);
592 gboolean only_success,
void *user_data,
593 const char *callback_name,
594 void (*callback)(xmlNode *,
int,
int,
596 void (*free_func)(
void *))
601 if (only_success == FALSE) {
602 callback(NULL, call_id, call_id, NULL, user_data);
606 if (user_data && free_func) {
607 free_func(user_data);
613 blob->
id = callback_name;
622 async_timer = calloc(1,
sizeof(
struct timer_rec_s));
623 blob->
timer = async_timer;
627 async_timer->
timeout = timeout * 1000;
629 g_timeout_add(async_timer->
timeout, cib_async_timeout_handler, async_timer);
632 crm_trace(
"Adding callback %s for call %d", callback_name, call_id);
647 NULL, cib_destroy_op_callback);
664 cib_dump_pending_op(gpointer key, gpointer value, gpointer user_data)
666 int call = GPOINTER_TO_INT(key);
#define CRM_CHECK(expr, failure_action)
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)
int cib_client_add_notify_callback(cib_t *cib, const char *event, void(*callback)(const char *event, xmlNode *msg))
void cib_dump_pending_callbacks(void)
int(* delete_absolute)(cib_t *cib, const char *section, xmlNode *data, int call_options)
const char * pcmk_strerror(int rc)
int cib_client_del_notify_callback(cib_t *cib, const char *event, void(*callback)(const char *event, xmlNode *msg))
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)
int crm_parse_int(const char *text, const char *default_text)
cib_t * cib_shadow_new(const char *shadow)
GHashTable * cib_op_callback_table
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)
gboolean cib_client_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 *))
#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)
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)
gboolean cib_client_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 *))
void(* callback)(xmlNode *, int, int, xmlNode *, void *)
#define crm_trace(fmt, args...)
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)
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)
cib_t * cib_file_new(const char *filename)
int cib_client_set_op_callback(cib_t *cib, void(*callback)(const xmlNode *msg, int call_id, int rc, xmlNode *output))
int(* noop)(cib_t *cib, int call_options)
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...)
Log a system error message.
int(* set_master)(cib_t *cib, int call_options)
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 CIB_OP_DELETE_ALT
char * crm_concat(const char *prefix, const char *suffix, char join)
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)
#define safe_str_eq(a, b)
void cib_delete(cib_t *cib)
int(* delete)(cib_t *cib, const char *section, xmlNode *data, int call_options)
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)
gint ciblib_GCompareFunc(gconstpointer a, gconstpointer b)