19 #include <sys/types.h> 28 static GHashTable *cib_op_callback_table = NULL;
31 int rc, xmlNode * output));
34 void (*callback) (
const char *event, xmlNode * msg));
37 void (*callback) (
const char *event, xmlNode * msg));
41 #define op_common(cib) do { \ 44 } else if(cib->delegate_fn == NULL) { \ 45 return -EPROTONOSUPPORT; \ 50 cib_client_noop(
cib_t * cib,
int call_options)
57 cib_client_ping(
cib_t * cib, xmlNode ** output_data,
int call_options)
64 cib_client_query(
cib_t * cib,
const char *section, xmlNode ** output_data,
int call_options)
66 return cib->
cmds->
query_from(cib, NULL, section, output_data, call_options);
70 cib_client_query_from(
cib_t * cib,
const char *
host,
const char *section,
71 xmlNode ** output_data,
int call_options)
78 cib_client_is_master(
cib_t * cib)
86 cib_client_set_slave(
cib_t * cib,
int call_options)
93 cib_client_set_slave_all(
cib_t * cib,
int call_options)
95 return -EPROTONOSUPPORT;
99 cib_client_set_master(
cib_t * cib,
int call_options)
102 crm_trace(
"Adding cib_scope_local to options");
108 cib_client_bump_epoch(
cib_t * cib,
int call_options)
115 cib_client_upgrade(
cib_t * cib,
int call_options)
122 cib_client_sync(
cib_t * cib,
const char *section,
int call_options)
124 return cib->
cmds->
sync_from(cib, NULL, section, call_options);
128 cib_client_sync_from(
cib_t * cib,
const char *
host,
const char *section,
int call_options)
135 cib_client_create(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
142 cib_client_modify(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
149 cib_client_update(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
156 cib_client_replace(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
163 cib_client_delete(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
170 cib_client_delete_absolute(
cib_t * cib,
const char *section, xmlNode *
data,
int call_options)
177 cib_client_erase(
cib_t * cib, xmlNode ** output_data,
int call_options)
184 cib_destroy_op_callback(gpointer
data)
201 destroy_op_callback_table(
void)
203 if (cib_op_callback_table != NULL) {
204 g_hash_table_destroy(cib_op_callback_table);
205 cib_op_callback_table = NULL;
212 char *cib_home = NULL;
213 char *fullname = NULL;
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 user = getenv(
"USER");
227 "Assuming %s because cannot get user details for user ID %d",
228 (user? user :
"unprivileged user"), uid);
235 const char *home = NULL;
237 if ((home = getenv(
"HOME")) == NULL) {
239 home = pwent->pw_dir;
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");
297 if (value && value[0] != 0) {
301 value = getenv(
"CIB_file");
306 value = getenv(
"CIB_port");
308 gboolean encrypted = TRUE;
309 const char *server = getenv(
"CIB_server");
310 const char *user = getenv(
"CIB_user");
311 const char *pass = getenv(
"CIB_passwd");
320 value = getenv(
"CIB_encrypted");
328 crm_info(
"Defaulting to user: %s", user);
331 if (server == NULL) {
332 server =
"localhost";
333 crm_info(
"Defaulting to localhost");
354 cib_t *new_cib = NULL;
356 new_cib = calloc(1,
sizeof(
cib_t));
358 if (new_cib == NULL) {
377 if (new_cib->
cmds == NULL) {
388 new_cib->
cmds->
noop = cib_client_noop;
389 new_cib->
cmds->
ping = cib_client_ping;
391 new_cib->
cmds->
sync = cib_client_sync;
423 while (list != NULL) {
426 list = g_list_remove(list, client);
442 destroy_op_callback_table();
461 int rc, xmlNode * output))
463 if (callback == NULL) {
464 crm_info(
"Un-Setting operation callback");
475 void (*callback) (
const char *event, xmlNode * msg))
477 GList *list_item = NULL;
481 return -EPROTONOSUPPORT;
487 new_client->
event = event;
492 if (list_item != NULL) {
493 crm_warn(
"Callback already present");
508 get_notify_list_event_count(
cib_t * cib,
const char *event)
513 for (l = g_list_first(cib->
notify_list); l; l = g_list_next(l)) {
516 if (strcmp(client->
event, event) == 0) {
520 crm_trace(
"event(%s) count : %d", event, count);
526 void (*callback) (
const char *event, xmlNode * msg))
528 GList *list_item = NULL;
532 return -EPROTONOSUPPORT;
535 if (get_notify_list_event_count(cib, event) == 0) {
536 crm_debug(
"The callback of the event does not exist(%s)", event);
540 crm_debug(
"Removing callback for %s events", event);
543 new_client->
event = event;
548 if (list_item != NULL) {
560 if (get_notify_list_event_count(cib, event) == 0) {
577 rc = strcmp(a_client->
event, b_client->
event);
582 crm_trace(
"callbacks for %s are not equal: %p < %p",
586 crm_trace(
"callbacks for %s are not equal: %p > %p",
594 cib_async_timeout_handler(gpointer
data)
609 void *user_data,
const char *callback_name,
610 void (*callback) (xmlNode *,
int,
int, xmlNode *,
void *))
613 only_success, user_data,
614 callback_name, callback, NULL);
619 gboolean only_success,
void *user_data,
620 const char *callback_name,
621 void (*callback)(xmlNode *,
int,
int,
623 void (*free_func)(
void *))
628 if (only_success == FALSE) {
633 if (user_data && free_func) {
634 free_func(user_data);
640 blob->
id = callback_name;
649 async_timer = calloc(1,
sizeof(
struct timer_rec_s));
650 blob->
timer = async_timer;
656 g_timeout_add(async_timer->
timeout, cib_async_timeout_handler, async_timer);
660 pcmk__intkey_table_insert(cib_op_callback_table,
call_id, blob);
669 destroy_op_callback_table();
670 cib_op_callback_table = pcmk__intkey_table(cib_destroy_op_callback);
672 pcmk__intkey_table_remove(cib_op_callback_table,
call_id);
679 if (cib_op_callback_table == NULL) {
682 return g_hash_table_size(cib_op_callback_table);
686 cib_dump_pending_op(gpointer key, gpointer value, gpointer user_data)
688 int call = GPOINTER_TO_INT(key);
697 if (cib_op_callback_table == NULL) {
700 return g_hash_table_foreach(cib_op_callback_table, cib_dump_pending_op, NULL);
706 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)
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)
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)
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)
void cib_free_callbacks(cib_t *cib)
Free all callbacks for a CIB connection.
cib_t * cib_shadow_new(const char *shadow)
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)
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)
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...)
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)
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)
cib_callback_client_t * cib__lookup_id(int call_id)
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...)
Send a system error message to both the log and stderr.
void cib_free_notify(cib_t *cib)
const char * pcmk__get_tmpdir(void)
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)
int(* remove)(cib_t *cib, const char *section, xmlNode *data, int call_options)
#define CIB_OP_DELETE_ALT
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)
gint ciblib_GCompareFunc(gconstpointer a, gconstpointer b)