From a045a72a7ea122c10c4ceacb0cf15ff7ecd125c0 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Wed, 7 Feb 2024 16:13:44 -0600
Subject: [PATCH 11/16] Refactor: pacemaker-attrd: use variable for whether to
 write

... for readability and to reduce code duplication
---
 daemons/attrd/attrd_cib.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/daemons/attrd/attrd_cib.c b/daemons/attrd/attrd_cib.c
index e7eeaa96d9..193b06739e 100644
--- a/daemons/attrd/attrd_cib.c
+++ b/daemons/attrd/attrd_cib.c
@@ -492,13 +492,19 @@ write_attribute(attribute_t *a, bool ignore_delay)
     GHashTableIter iter;
     GHashTable *alert_attribute_value = NULL;
     int rc = pcmk_ok;
+    bool should_write = true;
 
     if (a == NULL) {
         return;
     }
 
+    // Private attributes (or any in standalone mode) are not written to the CIB
+    if (stand_alone || pcmk_is_set(a->flags, attrd_attr_is_private)) {
+        should_write = false;
+    }
+
     /* If this attribute will be written to the CIB ... */
-    if (!stand_alone && !pcmk_is_set(a->flags, attrd_attr_is_private)) {
+    if (should_write) {
         /* Defer the write if now's not a good time */
         if (a->update && (a->update < last_cib_op_done)) {
             crm_info("Write out of '%s' continuing: update %d considered lost",
@@ -549,8 +555,7 @@ write_attribute(attribute_t *a, bool ignore_delay)
     while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &v)) {
         const char *node_xml_id = NULL;
 
-        // Private attributes (or any in standalone mode) are not written to CIB
-        if (stand_alone || pcmk_is_set(a->flags, attrd_attr_is_private)) {
+        if (!should_write) {
             private_updates++;
             continue;
         }
-- 
2.43.0

