File bug-800323_pacemaker-crm_mon-save-cib.patch of Package pacemaker

commit e97f7eb36e1d2c3a8b241ba52e98b707da1eccf5
Author: Gao,Yan <ygao@suse.com>
Date:   Mon Apr 1 14:19:47 2013 +0800

    Log: tools: crm_mon - Save relevant cib XML into /tmp/cmon.* files if refreshing fails (bnc#800323)

diff --git a/tools/crm_mon.c b/tools/crm_mon.c
index da778de..c6af01b 100644
--- a/tools/crm_mon.c
+++ b/tools/crm_mon.c
@@ -85,6 +85,8 @@ const char *external_recipient = NULL;
 cib_t *cib = NULL;
 stonith_t *st = NULL;
 xmlNode *current_cib = NULL;
+xmlNode *orig_cib = NULL;
+xmlNode *diff_cib = NULL;
 
 gboolean one_shot = FALSE;
 gboolean has_warnings = FALSE;
@@ -2130,10 +2132,12 @@ crm_diff_update(const char *event, xmlNode * msg)
     static bool stale = FALSE;
 
     print_dot();
+    diff_cib = copy_xml(msg);
 
     if (current_cib != NULL) {
         xmlNode *cib_last = current_cib;
 
+        orig_cib = copy_xml(cib_last);
         current_cib = NULL;
 
         rc = cib_apply_patch_event(msg, cib_last, &current_cib, LOG_DEBUG);
@@ -2196,6 +2200,38 @@ mon_refresh_display(gpointer user_data)
     last_refresh = time(NULL);
 
     if (cli_config_update(&cib_copy, NULL, FALSE) == FALSE) {
+        char *tmp_prefix = tempnam("/tmp", "cmon.");
+        char *real_filename = NULL;
+        char *orig_filename = NULL;
+        char *new_filename = NULL;
+        char *diff_filename = NULL;
+        xmlNode *real_cib = get_cib_copy(cib);
+
+        real_filename = g_strdup_printf("%s.real", tmp_prefix);
+        write_xml_file(real_cib, real_filename, FALSE);
+        free(real_filename);
+        free_xml(real_cib);
+        real_cib = NULL;
+
+        orig_filename = g_strdup_printf("%s.orig", tmp_prefix);
+        write_xml_file(orig_cib, orig_filename, FALSE);
+        free(orig_filename);
+        free_xml(orig_cib);
+        orig_cib = NULL;
+
+        new_filename = g_strdup_printf("%s.new", tmp_prefix);
+        write_xml_file(current_cib, new_filename, FALSE);
+        free(new_filename);
+
+        diff_filename = g_strdup_printf("%s.diff", tmp_prefix);
+        write_xml_file(diff_cib, diff_filename, FALSE);
+        free(diff_filename);
+        free_xml(diff_cib);
+        diff_cib = NULL;
+
+        print_as("Saved relevant XML into /tmp/%s* files", tmp_prefix);
+        free(tmp_prefix);
+
         if (cib) {
             cib->cmds->signoff(cib);
         }
@@ -2207,6 +2243,12 @@ mon_refresh_display(gpointer user_data)
         return FALSE;
     }
 
+    free_xml(orig_cib);
+    orig_cib = NULL;
+
+    free_xml(diff_cib);
+    diff_cib = NULL;
+
     set_working_set_defaults(&data_set);
     data_set.input = cib_copy;
     cluster_status(&data_set);
openSUSE Build Service is sponsored by