]> xenbits.xensource.com Git - libvirt.git/commitdiff
rpc: remove trailing whitespace character in error string
authorGuannan Ren <gren@redhat.com>
Wed, 18 Jul 2012 15:02:02 +0000 (23:02 +0800)
committerGuannan Ren <gren@redhat.com>
Thu, 19 Jul 2012 03:22:52 +0000 (11:22 +0800)
Instead of only removing the ending newline character, it is
better to remove all of standard whitespace character for the
sake of log format.

One example that we have to do this is:
After three times incorrect password input, virsh command
virsh -c qemu://remoteserver/system will report error like:

: Connection reset by peerey,gssapi-keyex,gssapi-with-mic,password).

But it should be:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
: Connection reset by peer

The reason is that we dropped the newline, but have a '\r' left.
The terminal interprets it as "move the cursor back to the start
of the current line", so the error string is messed up.

src/rpc/virnetsocket.c

index 3ddf37d198e05a35911ca9d70e0bc4a7e0001aa9..aee3c19e32c562eb075d159d57d4b3e08c35754d 100644 (file)
@@ -35,6 +35,7 @@
 # include <netinet/tcp.h>
 #endif
 
+#include "c-ctype.h"
 #include "virnetsocket.h"
 #include "util.h"
 #include "memory.h"
@@ -981,8 +982,9 @@ reread:
         virFileReadLimFD(sock->errfd, 1024, &errout) >= 0 &&
         errout != NULL) {
         size_t elen = strlen(errout);
-        if (elen && errout[elen-1] == '\n')
-            errout[elen-1] = '\0';
+        /* remove trailing whitespace */
+        while (elen && c_isspace(errout[elen - 1]))
+            errout[--elen] = '\0';
     }
 
     if (ret < 0) {