[libvirt] [PATCH 1/2] vsh: use virBufferTrim in vshOutputLogFile

Ján Tomko jtomko at redhat.com
Fri Feb 12 13:59:20 UTC 2016


Use virBufferTrim to strip the extra newline at the end
of the message instead of open-coding it after the buffer's
string is formatted.
---
 tools/vsh.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index 073347a..9dd3ba3 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -2086,6 +2086,7 @@ vshOutputLogFile(vshControl *ctl, int log_level, const char *msg_format,
     }
     virBufferAsprintf(&buf, "%s ", lvl);
     virBufferVasprintf(&buf, msg_format, ap);
+    virBufferTrim(&buf, "\n", -1);
     virBufferAddChar(&buf, '\n');
 
     if (virBufferError(&buf))
@@ -2093,10 +2094,6 @@ vshOutputLogFile(vshControl *ctl, int log_level, const char *msg_format,
 
     str = virBufferContentAndReset(&buf);
     len = strlen(str);
-    if (len > 1 && str[len - 2] == '\n') {
-        str[len - 1] = '\0';
-        len--;
-    }
 
     /* write log */
     if (safewrite(ctl->log_fd, str, len) < 0)
-- 
2.4.10




More information about the libvir-list mailing list