WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [PATCH] [Xend] host.get_log() : clean log of non-printab

To: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: Re: [Xen-devel] [PATCH] [Xend] host.get_log() : clean log of non-printable characters
From: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
Date: Thu, 15 Nov 2007 14:38:37 +0000
Delivery-date: Thu, 15 Nov 2007 06:40:09 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
In-reply-to: <1195097158.18754.3.camel@xxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Newsgroups: chiark.mail.xen.devel
References: <1195097158.18754.3.camel@xxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Stefan Berger writes ("[Xen-devel] [PATCH] [Xend] host.get_log() : clean log of 
non-printable characters"):
> When retrieving the log via host.get_log() the python parser on the
> receiving side gets upset about non-printable characters ("\b"). Those
> stem from libxc/xc_domain_restore:xc_domain_restore().

It is a shame that we are forced into writing a lossy log retrieval
method by braindamage in XMLRPC and XML 1.0.  Perhaps we should in
future think about a get_log_lossless function which uses a binary
encoding.  It'd have to be base64 :-/.

> -        return xen_api_success(log_buffer)
> +        i = 0
> +        res = ""
> +        while i < len(log_buffer):
> +            c = ord(log_buffer[i])
> +            if (c < 32 or c > 126) and (c < 10 or c > 13):
> +                res += " "
> +            else:
> +                res += log_buffer[i]
> +            i += 1
> +        return xen_api_success(res)

This is a strange way of doing things and will be quite slow.
It's also wrong in that it replaces tabs.

In theory it would be best to try to map away all Unicode characters
which are not in XML 1.0's Char.  However, this would involve
explicitly interpreting the logfile as UTF-8 and it's not clear to me
that it always is.  If it isn't, it's probably better to let the
caller get whatever the logfile byte string is and hope they don't
choke - at least until we know under what circumstances this arises.

So it's better just to map away the character we know is causing
problems.  \r will be OK because it's allowed in XML as an encoding of
newline, which will do.  I've chosen below to replace \f as well since
I suspect they may appear at some point.

Ian.

diff -r ba69fe2dce91 tools/python/xen/xend/XendAPI.py
--- a/tools/python/xen/xend/XendAPI.py  Tue Nov 13 20:13:50 2007 +0000
+++ b/tools/python/xen/xend/XendAPI.py  Thu Nov 15 14:32:33 2007 +0000
@@ -994,6 +994,8 @@ class XendAPI(object):
     def host_get_log(self, session, host_ref):
         log_file = open(XendLogging.getLogFilename())
         log_buffer = log_file.read()
+        log_buffer = log_buffer.replace('\b',' ')
+        log_buffer = log_buffer.replace('\f','\n')
         return xen_api_success(log_buffer)
 
     def host_send_debug_keys(self, _, host_ref, keys):

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>