]> xenbits.xensource.com Git - libvirt.git/commitdiff
vsh: use virBufferTrim in vshOutputLogFile
authorJán Tomko <jtomko@redhat.com>
Fri, 12 Feb 2016 12:49:18 +0000 (13:49 +0100)
committerJán Tomko <jtomko@redhat.com>
Thu, 18 Feb 2016 15:18:22 +0000 (16:18 +0100)
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

index 44674451f0c44a4b53827d8049566af079150c81..4ce17279bb75cc546619b990f8e1b8f13a982ff2 100644 (file)
@@ -2110,6 +2110,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))
@@ -2117,10 +2118,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)