File 0001-Low-libcrmcommon-Fix-problems-with-pcmk__output_and_.patch of Package pacemaker.29737

From c5b6a64cde5d460e1349e952db6a33831009ecd0 Mon Sep 17 00:00:00 2001
From: Chris Lumens <clumens@redhat.com>
Date: Mon, 20 Feb 2023 16:12:19 -0500
Subject: [PATCH] Low: libcrmcommon: Fix problems with
 pcmk__output_and_clear_error.

First, it should take a GError ** so that doing anything in the function
modifies the error object that was passed to it.  Second, the test case
should assert that the error is NULL, not that some element of it is
NULL.
---
 daemons/attrd/pacemaker-attrd.c                      |  2 +-
 daemons/based/pacemaker-based.c                      |  4 ++--
 daemons/controld/pacemaker-controld.c                |  4 ++--
 daemons/execd/cts-exec-helper.c                      |  4 ++--
 daemons/execd/pacemaker-execd.c                      |  2 +-
 daemons/fenced/cts-fence-helper.c                    |  4 ++--
 daemons/fenced/pacemaker-fenced.c                    |  2 +-
 daemons/pacemakerd/pacemakerd.c                      |  4 ++--
 daemons/schedulerd/pacemaker-schedulerd.c            |  4 ++--
 include/crm/common/output_internal.h                 |  2 +-
 lib/common/output.c                                  | 12 ++++++------
 .../tests/output/pcmk__output_and_clear_error_test.c |  6 +++---
 tools/attrd_updater.c                                |  2 +-
 tools/cibadmin.c                                     |  4 ++--
 tools/crm_attribute.c                                |  2 +-
 tools/crm_diff.c                                     |  2 +-
 tools/crm_error.c                                    |  4 ++--
 tools/crm_node.c                                     |  4 ++--
 tools/crm_resource.c                                 |  2 +-
 tools/crm_rule.c                                     |  4 ++--
 tools/crm_shadow.c                                   |  2 +-
 tools/crm_simulate.c                                 |  4 ++--
 tools/crm_ticket.c                                   |  4 ++--
 tools/crm_verify.c                                   |  4 ++--
 tools/crmadmin.c                                     |  4 ++--
 tools/iso8601.c                                      |  4 ++--
 tools/stonith_admin.c                                |  4 ++--
 27 files changed, 50 insertions(+), 50 deletions(-)

Index: pacemaker-2.1.5+20221208.a3f44794f/daemons/attrd/pacemaker-attrd.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/daemons/attrd/pacemaker-attrd.c
+++ pacemaker-2.1.5+20221208.a3f44794f/daemons/attrd/pacemaker-attrd.c
@@ -306,7 +306,7 @@ main(int argc, char **argv)
     g_strfreev(processed_args);
     pcmk__free_arg_context(context);
 
-    pcmk__output_and_clear_error(error, out);
+    pcmk__output_and_clear_error(&error, out);
 
     if (out != NULL) {
         out->finish(out, attrd_exit_status, true, NULL);
Index: pacemaker-2.1.5+20221208.a3f44794f/daemons/execd/cts-exec-helper.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/daemons/execd/cts-exec-helper.c
+++ pacemaker-2.1.5+20221208.a3f44794f/daemons/execd/cts-exec-helper.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012-2022 the Pacemaker project contributors
+ * Copyright 2012-2023 the Pacemaker project contributors
  *
  * The version control history for this file may have further details.
  *
@@ -620,6 +620,6 @@ done:
     free(key);
     free(val);
 
-    pcmk__output_and_clear_error(error, NULL);
+    pcmk__output_and_clear_error(&error, NULL);
     return test_exit(exit_code);
 }
Index: pacemaker-2.1.5+20221208.a3f44794f/daemons/fenced/cts-fence-helper.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/daemons/fenced/cts-fence-helper.c
+++ pacemaker-2.1.5+20221208.a3f44794f/daemons/fenced/cts-fence-helper.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2022 the Pacemaker project contributors
+ * Copyright 2009-2023 the Pacemaker project contributors
  *
  * This source code is licensed under the GNU General Public License version 2
  * or later (GPLv2+) WITHOUT ANY WARRANTY.
@@ -676,6 +676,6 @@ done:
     g_strfreev(processed_args);
     pcmk__free_arg_context(context);
 
-    pcmk__output_and_clear_error(error, NULL);
+    pcmk__output_and_clear_error(&error, NULL);
     crm_exit(exit_code);
 }
Index: pacemaker-2.1.5+20221208.a3f44794f/daemons/pacemakerd/pacemakerd.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/daemons/pacemakerd/pacemakerd.c
+++ pacemaker-2.1.5+20221208.a3f44794f/daemons/pacemakerd/pacemakerd.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2010-2022 the Pacemaker project contributors
+ * Copyright 2010-2023 the Pacemaker project contributors
  *
  * The version control history for this file may have further details.
  *
@@ -449,7 +449,7 @@ done:
     g_strfreev(processed_args);
     pcmk__free_arg_context(context);
 
-    pcmk__output_and_clear_error(error, out);
+    pcmk__output_and_clear_error(&error, out);
 
     if (out != NULL) {
         out->finish(out, exit_code, true, NULL);
Index: pacemaker-2.1.5+20221208.a3f44794f/daemons/schedulerd/pacemaker-schedulerd.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/daemons/schedulerd/pacemaker-schedulerd.c
+++ pacemaker-2.1.5+20221208.a3f44794f/daemons/schedulerd/pacemaker-schedulerd.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004-2022 the Pacemaker project contributors
+ * Copyright 2004-2023 the Pacemaker project contributors
  *
  * The version control history for this file may have further details.
  *
@@ -150,7 +150,7 @@ done:
     g_strfreev(processed_args);
     pcmk__free_arg_context(context);
 
-    pcmk__output_and_clear_error(error, out);
+    pcmk__output_and_clear_error(&error, out);
     pengine_shutdown(0);
 }
 
Index: pacemaker-2.1.5+20221208.a3f44794f/include/crm/common/output_internal.h
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/include/crm/common/output_internal.h
+++ pacemaker-2.1.5+20221208.a3f44794f/include/crm/common/output_internal.h
@@ -879,7 +879,7 @@ G_GNUC_NULL_TERMINATED;
  * \param[in,out] out   The output functions structure.  If NULL, any errors
  *                      will simply be printed to stderr.
  */
-void pcmk__output_and_clear_error(GError *error, pcmk__output_t *out);
+void pcmk__output_and_clear_error(GError **error, pcmk__output_t *out);
 
 int pcmk__xml_output_new(pcmk__output_t **out, xmlNodePtr *xml);
 void pcmk__xml_output_finish(pcmk__output_t *out, xmlNodePtr *xml);
Index: pacemaker-2.1.5+20221208.a3f44794f/lib/common/output.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/lib/common/output.c
+++ pacemaker-2.1.5+20221208.a3f44794f/lib/common/output.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2019-2022 the Pacemaker project contributors
+ * Copyright 2019-2023 the Pacemaker project contributors
  *
  * The version control history for this file may have further details.
  *
@@ -169,19 +169,19 @@ pcmk__register_messages(pcmk__output_t *
 }
 
 void
-pcmk__output_and_clear_error(GError *error, pcmk__output_t *out)
+pcmk__output_and_clear_error(GError **error, pcmk__output_t *out)
 {
-    if (error == NULL) {
+    if (error == NULL || *error == NULL) {
         return;
     }
 
     if (out != NULL) {
-        out->err(out, "%s: %s", g_get_prgname(), error->message);
+        out->err(out, "%s: %s", g_get_prgname(), (*error)->message);
     } else {
-        fprintf(stderr, "%s: %s\n", g_get_prgname(), error->message);
+        fprintf(stderr, "%s: %s\n", g_get_prgname(), (*error)->message);
     }
 
-    g_clear_error(&error);
+    g_clear_error(error);
 }
 
 /*!
Index: pacemaker-2.1.5+20221208.a3f44794f/lib/common/tests/output/pcmk__output_and_clear_error_test.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/lib/common/tests/output/pcmk__output_and_clear_error_test.c
+++ pacemaker-2.1.5+20221208.a3f44794f/lib/common/tests/output/pcmk__output_and_clear_error_test.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2022 the Pacemaker project contributors
+ * Copyright 2022-2023 the Pacemaker project contributors
  *
  * The version control history for this file may have further details.
  *
@@ -72,10 +72,10 @@ standard_usage(void **state) {
                 "some error message");
 
     expect_function_call(fake_text_err);
-    pcmk__output_and_clear_error(error, out);
+    pcmk__output_and_clear_error(&error, out);
 
     pcmk__output_free(out);
-    assert_null(error->message);
+    assert_null(error);
 }
 
 PCMK__UNIT_TEST(NULL, NULL,
Index: pacemaker-2.1.5+20221208.a3f44794f/tools/attrd_updater.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/tools/attrd_updater.c
+++ pacemaker-2.1.5+20221208.a3f44794f/tools/attrd_updater.c
@@ -287,7 +287,7 @@ done:
     g_free(options.attr_set);
     free(options.attr_value);
 
-    pcmk__output_and_clear_error(error, out);
+    pcmk__output_and_clear_error(&error, out);
 
     if (out != NULL) {
         out->finish(out, exit_code, true, NULL);
Index: pacemaker-2.1.5+20221208.a3f44794f/tools/crm_attribute.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/tools/crm_attribute.c
+++ pacemaker-2.1.5+20221208.a3f44794f/tools/crm_attribute.c
@@ -919,7 +919,7 @@ done:
 
     cib__clean_up_connection(&the_cib);
 
-    pcmk__output_and_clear_error(error, out);
+    pcmk__output_and_clear_error(&error, out);
 
     if (out != NULL) {
         out->finish(out, exit_code, true, NULL);
Index: pacemaker-2.1.5+20221208.a3f44794f/tools/crm_diff.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/tools/crm_diff.c
+++ pacemaker-2.1.5+20221208.a3f44794f/tools/crm_diff.c
@@ -370,6 +370,6 @@ done:
     free_xml(object_1);
     free_xml(object_2);
 
-    pcmk__output_and_clear_error(error, NULL);
+    pcmk__output_and_clear_error(&error, NULL);
     crm_exit(exit_code);
 }
Index: pacemaker-2.1.5+20221208.a3f44794f/tools/crm_error.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/tools/crm_error.c
+++ pacemaker-2.1.5+20221208.a3f44794f/tools/crm_error.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012-2022 the Pacemaker project contributors
+ * Copyright 2012-2023 the Pacemaker project contributors
  *
  * The version control history for this file may have further details.
  *
@@ -164,7 +164,7 @@ main(int argc, char **argv)
     g_strfreev(processed_args);
     pcmk__free_arg_context(context);
 
-    pcmk__output_and_clear_error(error, out);
+    pcmk__output_and_clear_error(&error, out);
 
     if (out != NULL) {
         out->finish(out, exit_code, true, NULL);
Index: pacemaker-2.1.5+20221208.a3f44794f/tools/crm_node.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/tools/crm_node.c
+++ pacemaker-2.1.5+20221208.a3f44794f/tools/crm_node.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004-2022 the Pacemaker project contributors
+ * Copyright 2004-2023 the Pacemaker project contributors
  *
  * The version control history for this file may have further details.
  *
@@ -590,6 +590,6 @@ done:
     g_strfreev(processed_args);
     pcmk__free_arg_context(context);
 
-    pcmk__output_and_clear_error(error, NULL);
+    pcmk__output_and_clear_error(&error, NULL);
     return crm_exit(exit_code);
 }
Index: pacemaker-2.1.5+20221208.a3f44794f/tools/crm_resource.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/tools/crm_resource.c
+++ pacemaker-2.1.5+20221208.a3f44794f/tools/crm_resource.c
@@ -200,7 +200,7 @@ static pcmk__supported_format_t formats[
 static crm_exit_t
 bye(crm_exit_t ec)
 {
-    pcmk__output_and_clear_error(error, out);
+    pcmk__output_and_clear_error(&error, out);
 
     if (out != NULL) {
         out->finish(out, ec, true, NULL);
Index: pacemaker-2.1.5+20221208.a3f44794f/tools/crm_rule.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/tools/crm_rule.c
+++ pacemaker-2.1.5+20221208.a3f44794f/tools/crm_rule.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2019-2022 the Pacemaker project contributors
+ * Copyright 2019-2023 the Pacemaker project contributors
  *
  * The version control history for this file may have further details.
  *
@@ -215,7 +215,7 @@ done:
     crm_time_free(rule_date);
     free_xml(input);
 
-    pcmk__output_and_clear_error(error, out);
+    pcmk__output_and_clear_error(&error, out);
 
     if (out != NULL) {
         out->finish(out, exit_code, true, NULL);
Index: pacemaker-2.1.5+20221208.a3f44794f/tools/crm_simulate.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/tools/crm_simulate.c
+++ pacemaker-2.1.5+20221208.a3f44794f/tools/crm_simulate.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2022 the Pacemaker project contributors
+ * Copyright 2009-2023 the Pacemaker project contributors
  *
  * The version control history for this file may have further details.
  *
@@ -545,7 +545,7 @@ main(int argc, char **argv)
                         options.dot_file);
 
   done:
-    pcmk__output_and_clear_error(error, NULL);
+    pcmk__output_and_clear_error(&error, NULL);
 
     /* There sure is a lot to free in options. */
     free(options.dot_file);
Index: pacemaker-2.1.5+20221208.a3f44794f/tools/crm_ticket.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/tools/crm_ticket.c
+++ pacemaker-2.1.5+20221208.a3f44794f/tools/crm_ticket.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012-2022 the Pacemaker project contributors
+ * Copyright 2012-2023 the Pacemaker project contributors
  *
  * The version control history for this file may have further details.
  *
@@ -1005,7 +1005,7 @@ main(int argc, char **argv)
     g_free(options.ticket_id);
     g_free(options.xml_file);
 
-    pcmk__output_and_clear_error(error, NULL);
+    pcmk__output_and_clear_error(&error, NULL);
 
     crm_exit(exit_code);
 }
Index: pacemaker-2.1.5+20221208.a3f44794f/tools/crm_verify.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/tools/crm_verify.c
+++ pacemaker-2.1.5+20221208.a3f44794f/tools/crm_verify.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004-2022 the Pacemaker project contributors
+ * Copyright 2004-2023 the Pacemaker project contributors
  *
  * The version control history for this file may have further details.
  *
@@ -273,7 +273,7 @@ main(int argc, char **argv)
         exit_code = pcmk_rc2exitc(rc);
     }
 
-    pcmk__output_and_clear_error(error, NULL);
+    pcmk__output_and_clear_error(&error, NULL);
 
     if (out != NULL) {
         out->finish(out, exit_code, true, NULL);
Index: pacemaker-2.1.5+20221208.a3f44794f/tools/crmadmin.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/tools/crmadmin.c
+++ pacemaker-2.1.5+20221208.a3f44794f/tools/crmadmin.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004-2022 the Pacemaker project contributors
+ * Copyright 2004-2023 the Pacemaker project contributors
  *
  * The version control history for this file may have further details.
  *
@@ -262,7 +262,7 @@ done:
     g_strfreev(processed_args);
     pcmk__free_arg_context(context);
 
-    pcmk__output_and_clear_error(error, out);
+    pcmk__output_and_clear_error(&error, out);
 
     if (out != NULL) {
         out->finish(out, exit_code, true, NULL);
Index: pacemaker-2.1.5+20221208.a3f44794f/tools/iso8601.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/tools/iso8601.c
+++ pacemaker-2.1.5+20221208.a3f44794f/tools/iso8601.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2022 the Pacemaker project contributors
+ * Copyright 2005-2023 the Pacemaker project contributors
  *
  * The version control history for this file may have further details.
  *
@@ -277,6 +277,6 @@ done:
     g_free(options.expected_s);
     g_free(options.period_s);
 
-    pcmk__output_and_clear_error(error, NULL);
+    pcmk__output_and_clear_error(&error, NULL);
     crm_exit(exit_code);
 }
Index: pacemaker-2.1.5+20221208.a3f44794f/tools/stonith_admin.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/tools/stonith_admin.c
+++ pacemaker-2.1.5+20221208.a3f44794f/tools/stonith_admin.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2009-2022 the Pacemaker project contributors
+ * Copyright 2009-2023 the Pacemaker project contributors
  *
  * The version control history for this file may have further details.
  *
@@ -655,7 +655,7 @@ main(int argc, char **argv)
     g_strfreev(processed_args);
     pcmk__free_arg_context(context);
 
-    pcmk__output_and_clear_error(error, out);
+    pcmk__output_and_clear_error(&error, out);
 
     if (out != NULL) {
         out->finish(out, exit_code, true, NULL);
openSUSE Build Service is sponsored by