[PATCH] Daemon: fix handling of errors from xread.
This caused me to waste about 3 hours looking for a non-existent "data corrupter" bug, which turned out to be the result of not checking the return value of xread ... Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v
On Thu, Sep 17, 2009 at 03:33:24PM +0100, Richard W.M. Jones wrote:
This caused me to waste about 3 hours looking for a non-existent "data corrupter" bug, which turned out to be the result of not checking the return value of xread ...
You might want to add __attribute__((__warn_unused_result__)) to the header file decl of xread/xwrite so that the compiler will warn if any other code areas forget to check the return error code Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
On Thu, Sep 17, 2009 at 03:39:45PM +0100, Daniel P. Berrange wrote:
On Thu, Sep 17, 2009 at 03:33:24PM +0100, Richard W.M. Jones wrote:
This caused me to waste about 3 hours looking for a non-existent "data corrupter" bug, which turned out to be the result of not checking the return value of xread ...
You might want to add
__attribute__((__warn_unused_result__))
to the header file decl of xread/xwrite so that the compiler will warn if any other code areas forget to check the return error code
Good idea. Updated patch attached. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/
Richard W.M. Jones wrote: ..
Subject: [PATCH 1/3] Daemon: fix handling of errors from xread and xwrite.
If xread or xwrite returns -1, that indicates an error and we should exit. Note that xread/xwrite has already printed the error message. ... - (void) xwrite (sock, buf, xdr_getpos (&xdr)); + if (xwrite (sock, buf, xdr_getpos (&xdr)) == -1) + exit (1);
That all looks fine. Barely worth mentioning, but when the API makes it equivalent, I find it slightly more appealing to test " < 0 " rather than " == -1 ", partly because it covers the entire range of negative return values, and partly because it's a little easier to read and shorter.
participants (3)
-
Daniel P. Berrange -
Jim Meyering -
Richard W.M. Jones