File pacemaker-attrd-CIB-connection-function-self-contained.patch of Package pacemaker.14737
commit 03402b332d8d50cee749d9819d680de0ebdc4542
Author: Ken Gaillot <kgaillot@redhat.com>
Date: Tue Aug 15 12:01:19 2017 -0500
Refactor: attrd: make CIB connection function self-contained
more consistent with cluster connection function, and logically grouped
Index: pacemaker/attrd/main.c
===================================================================
--- pacemaker.orig/attrd/main.c
+++ pacemaker/attrd/main.c
@@ -133,15 +133,16 @@ attrd_cib_destroy_cb(gpointer user_data)
return;
}
-static cib_t *
+static int
attrd_cib_connect(int max_retry)
{
- int rc = -ENOTCONN;
static int attempts = 0;
- cib_t *connection = cib_new();
- if(connection == NULL) {
- return NULL;
+ int rc = -ENOTCONN;
+
+ the_cib = cib_new();
+ if (the_cib == NULL) {
+ return DAEMON_RESPAWN_STOP;
}
do {
@@ -151,7 +152,7 @@ attrd_cib_connect(int max_retry)
attempts++;
crm_debug("CIB signon attempt %d", attempts);
- rc = connection->cmds->signon(connection, T_ATTRD, cib_command);
+ rc = the_cib->cmds->signon(the_cib, T_ATTRD, cib_command);
} while(rc != pcmk_ok && attempts < max_retry);
@@ -162,24 +163,25 @@ attrd_cib_connect(int max_retry)
crm_debug("Connected to the CIB after %d attempts", attempts);
- rc = connection->cmds->set_connection_dnotify(connection, attrd_cib_destroy_cb);
+ rc = the_cib->cmds->set_connection_dnotify(the_cib, attrd_cib_destroy_cb);
if (rc != pcmk_ok) {
crm_err("Could not set disconnection callback");
goto cleanup;
}
- rc = connection->cmds->add_notify_callback(connection, T_CIB_REPLACE_NOTIFY, attrd_cib_replaced_cb);
+ rc = the_cib->cmds->add_notify_callback(the_cib, T_CIB_REPLACE_NOTIFY, attrd_cib_replaced_cb);
if(rc != pcmk_ok) {
crm_err("Could not set CIB notification callback");
goto cleanup;
}
- return connection;
+ return pcmk_ok;
cleanup:
- connection->cmds->signoff(connection);
- cib_delete(connection);
- return NULL;
+ the_cib->cmds->signoff(the_cib);
+ cib_delete(the_cib);
+ the_cib = NULL;
+ return DAEMON_RESPAWN_STOP;
}
static int32_t
@@ -368,9 +370,8 @@ main(int argc, char **argv)
attrd_ipc_server_init(&ipcs, &ipc_callbacks);
crm_info("Accepting attribute updates");
- the_cib = attrd_cib_connect(10);
- if (the_cib == NULL) {
- rc = DAEMON_RESPAWN_STOP;
+ rc = attrd_cib_connect(10);
+ if (rc != pcmk_ok) {
goto done;
}