Blob Blame History Raw
commit 0c88fc0aa260dcd50e654275cc9fdd68e27a2617
Author: David Vossel <dvossel@redhat.com>
Date:   Wed Dec 4 17:04:52 2013 -0600

    Fix: Removes unnecessary newlines in crm_resource -O output
    
    Resolves: rhbz#1038155
    (cherry picked from commit cd56faa1c9168811b64be9f7eea73ad600261844)

diff --git a/include/crm/common/util.h b/include/crm/common/util.h
index f0dca36..9092708 100644
--- a/include/crm/common/util.h
+++ b/include/crm/common/util.h
@@ -67,6 +67,8 @@ gboolean decode_transition_key(const char *key, char **uuid, int *action, int *t
 gboolean decode_transition_magic(const char *magic, char **uuid, int *transition_id, int *action_id,
                                  int *op_status, int *op_rc, int *target_rc);
 
+char * crm_strip_trailing_newline(char *str);
+
 #  define safe_str_eq(a, b) crm_str_eq(a, b, FALSE)
 gboolean crm_str_eq(const char *a, const char *b, gboolean use_case);
 gboolean safe_str_neq(const char *a, const char *b);
diff --git a/lib/common/utils.c b/lib/common/utils.c
index 527c9e0..4e18039 100644
--- a/lib/common/utils.c
+++ b/lib/common/utils.c
@@ -1550,6 +1550,22 @@ crm_is_writable(const char *dir, const char *file,
     return pass;
 }
 
+char *
+crm_strip_trailing_newline(char *str)
+{
+    int len;
+
+    if (str == NULL) {
+        return str;
+    }
+
+    for (len = strlen(str) - 1; len >= 0 && str[len] == '\n'; len--) {
+        str[len] = '\0';
+    }
+
+    return str;
+}
+
 gboolean
 crm_str_eq(const char *a, const char *b, gboolean use_case)
 {
diff --git a/tools/crm_resource.c b/tools/crm_resource.c
index c03501d..2f0e282 100644
--- a/tools/crm_resource.c
+++ b/tools/crm_resource.c
@@ -1119,8 +1119,8 @@ list_resource_operations(const char *rsc_id, const char *host_uname, gboolean ac
         if (last) {
             time_t run_at = crm_parse_int(last, "0");
 
-            fprintf(stdout, ", last-rc-change=%s, exec=%sms\n",
-                    ctime(&run_at), crm_element_value(xml_op, XML_RSC_OP_T_EXEC));
+            fprintf(stdout, ", last-rc-change=%s, exec=%sms",
+                    crm_strip_trailing_newline(ctime(&run_at)), crm_element_value(xml_op, XML_RSC_OP_T_EXEC));
         }
         fprintf(stdout, "): %s\n", services_lrm_status_str(status));
     }