From 843a8e6cc96f137819fb5f4e1d45abce58c05ca3 Mon Sep 17 00:00:00 2001
From: "Gao,Yan" <ygao@suse.com>
Date: Tue, 2 Jul 2024 10:20:24 +0200
Subject: [PATCH 2/2] Fix: tools: CIB clients retry signon upon an EAGAIN error

... up to 5 times.

Previously CIB clients wouldn't retry signon upon an EAGAIN and directly
return a connection error, which made them not resilient enough.
---
 tools/cibadmin.c      | 2 +-
 tools/crm_attribute.c | 2 +-
 tools/crm_node.c      | 2 +-
 tools/crm_resource.c  | 2 +-
 tools/crm_shadow.c    | 2 +-
 tools/crm_ticket.c    | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)

Index: pacemaker-2.0.4+20200616.2deceaa3a/tools/cibadmin.c
===================================================================
--- pacemaker-2.0.4+20200616.2deceaa3a.orig/tools/cibadmin.c
+++ pacemaker-2.0.4+20200616.2deceaa3a/tools/cibadmin.c
@@ -727,7 +727,7 @@ do_init(void)
     int rc = pcmk_ok;
 
     the_cib = cib_new();
-    rc = the_cib->cmds->signon(the_cib, crm_system_name, cib_command);
+    rc = cib__signon_attempts(the_cib, crm_system_name, cib_command, 5);
     if (rc != pcmk_ok) {
         crm_err("Could not connect to the CIB: %s", pcmk_strerror(rc));
         fprintf(stderr, "Could not connect to the CIB: %s\n",
Index: pacemaker-2.0.4+20200616.2deceaa3a/tools/crm_attribute.c
===================================================================
--- pacemaker-2.0.4+20200616.2deceaa3a.orig/tools/crm_attribute.c
+++ pacemaker-2.0.4+20200616.2deceaa3a/tools/crm_attribute.c
@@ -359,7 +359,7 @@ main(int argc, char **argv)
     }
 
     the_cib = cib_new();
-    rc = the_cib->cmds->signon(the_cib, crm_system_name, cib_command);
+    rc = cib__signon_attempts(the_cib, crm_system_name, cib_command, 5);
 
     if (rc != pcmk_ok) {
         fprintf(stderr, "Could not connect to the CIB: %s\n",
Index: pacemaker-2.0.4+20200616.2deceaa3a/tools/crm_node.c
===================================================================
--- pacemaker-2.0.4+20200616.2deceaa3a.orig/tools/crm_node.c
+++ pacemaker-2.0.4+20200616.2deceaa3a/tools/crm_node.c
@@ -372,7 +372,7 @@ cib_remove_node(long id, const char *nam
     }
 
     cib = cib_new();
-    cib->cmds->signon(cib, crm_system_name, cib_command);
+    cib__signon_attempts(cib, crm_system_name, cib_command, 5);
 
     rc = cib->cmds->remove(cib, XML_CIB_TAG_NODES, node, cib_sync_call);
     if (rc != pcmk_ok) {
Index: pacemaker-2.0.4+20200616.2deceaa3a/tools/crm_resource.c
===================================================================
--- pacemaker-2.0.4+20200616.2deceaa3a.orig/tools/crm_resource.c
+++ pacemaker-2.0.4+20200616.2deceaa3a/tools/crm_resource.c
@@ -1118,7 +1118,7 @@ main(int argc, char **argv)
         CMD_ERR("Could not create CIB connection: %s", pcmk_strerror(rc));
         goto bail;
     }
-    rc = cib_conn->cmds->signon(cib_conn, crm_system_name, cib_command);
+    rc = cib__signon_attempts(cib_conn, crm_system_name, cib_command, 5);
     if (rc != pcmk_ok) {
         CMD_ERR("Could not connect to the CIB: %s", pcmk_strerror(rc));
         goto bail;
Index: pacemaker-2.0.4+20200616.2deceaa3a/tools/crm_shadow.c
===================================================================
--- pacemaker-2.0.4+20200616.2deceaa3a.orig/tools/crm_shadow.c
+++ pacemaker-2.0.4+20200616.2deceaa3a/tools/crm_shadow.c
@@ -412,7 +412,7 @@ main(int argc, char **argv)
 
     if (command == 'd' || command == 'r' || command == 'c' || command == 'C') {
         real_cib = cib_new_no_shadow();
-        rc = real_cib->cmds->signon(real_cib, crm_system_name, cib_command);
+        rc = cib__signon_attempts(real_cib, crm_system_name, cib_command, 5);
         if (rc != pcmk_ok) {
             fprintf(stderr, "Could not connect to CIB: %s\n",
                     pcmk_strerror(rc));
Index: pacemaker-2.0.4+20200616.2deceaa3a/tools/crm_ticket.c
===================================================================
--- pacemaker-2.0.4+20200616.2deceaa3a.orig/tools/crm_ticket.c
+++ pacemaker-2.0.4+20200616.2deceaa3a/tools/crm_ticket.c
@@ -860,7 +860,7 @@ main(int argc, char **argv)
         goto bail;
     }
 
-    rc = cib_conn->cmds->signon(cib_conn, crm_system_name, cib_command);
+    rc = cib__signon_attempts(cib_conn, crm_system_name, cib_command, 5);
     if (rc != pcmk_ok) {
         CMD_ERR("Could not connect to CIB: %s", pcmk_strerror(rc));
         exit_code = crm_errno2exit(rc);
