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

[Xen-devel] Re: [Xen-changelog] use format printf style to write to trac

To: Vincent Hanquez <vincent.hanquez@xxxxxxxxxxxx>
Subject: [Xen-devel] Re: [Xen-changelog] use format printf style to write to tracefd instead of using write syscall.
From: Muli Ben-Yehuda <mulix@xxxxxxxxx>
Date: Tue, 24 Jan 2006 20:14:40 +0200
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx
Delivery-date: Tue, 24 Jan 2006 18:23:05 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <E1F1Pzk-0007L4-QX@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>
References: <E1F1Pzk-0007L4-QX@xxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.11
On Tue, Jan 24, 2006 at 03:22:08PM +0000, Xen patchbot -unstable wrote:
> +void trace(const char *fmt, ...)
> +{
> +     va_list arglist;
> +     char *str;
> +     char sbuf[1024];
> +     int ret;
>  
>       if (tracefd < 0)
>               return;
>  
> +     /* try to use a static buffer */

sbuf isn't static here...

> +     va_start(arglist, fmt);
> +     ret = vsnprintf(sbuf, 1024, fmt, arglist);
> +     va_end(arglist);
> +
> +     if (ret <= 1024) {
> +             write(tracefd, sbuf, ret);
>               return;

vsnprintf can return a negative error value on output failure, in
which case calling write is not a good idea. Also, a return value of
1024 (sizeof(sbuf) instead?) or more means the output was truncated,
not sure if we want to do anything about it.

Also also, do we care if write() failed or did a short write?

> -                     write(tracefd, "\n***\n", strlen("\n***\n"));
> +                     trace("\n***\n");

trace("%s", "\n***\n")? it's slightly slower but more future proof.

Cheers,
Muli
-- 
Muli Ben-Yehuda
http://www.mulix.org | http://mulix.livejournal.com/


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

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