[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] Re: [Xen-changelog] use format printf style to write to tracefd instead of using write syscall.



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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.