detecting write failure [Re: [Libguestfs] [PATCH] virt-cat: Remove some unused Perl module includes.
Jim Meyering
jim at meyering.net
Wed Sep 23 11:51:14 UTC 2009
Richard W.M. Jones wrote:
> On Wed, Sep 23, 2009 at 01:18:06PM +0200, Jim Meyering wrote:
>> Unrelated to this particular change, you may want to
>> add these lines to virt-cat:
>>
>> END { # use File::Coda; # http://meyering.net/code/Coda/
>> defined fileno STDOUT or return;
>> close STDOUT and return;
>> warn "$ME: failed to close standard output: $!\n";
>> $? ||= 1;
>> }
>>
>> Otherwise, virt-cat could fail to detect/report write errors.
>>
>> Try this:
>>
>> virt-cat /some/file > /dev/full
>>
>> It should fail.
>
> It turns out that virt-cat does catch this error already, or more
> precisely guestfs_download catches the error in the write to
> /dev/stdout and does the right thing:
>
> $ sudo ./cat/run-cat-locally /dev/vg_trick/F11x64 /boot/grub/grub.conf > /dev/full
> download: /dev/stdout: write: No space left on device at /home/rjones/d/libguestfs/cat/virt-cat.pl line 162.
> $ echo $?
> 28
>
> I'm not entirely sure where code 28 comes from.
Actually adding the above would help in *some* cases.
It's not as if --help and --version being robust is a big deal,
but try this:
$ ./virt-cat.pl --version > /dev/full && echo oops :
oops
$ ./virt-cat.pl --help > /dev/full
$
Note that that always exits with status of 1 (aka EXIT_FAILURE),
while the convention (at least for most GNU tools) is that PROG --help
exits with status 0, unless it fails, as above.
$ cat --help > /dev/full :
cat: write error: No space left on device
[Exit 1]
More information about the Libguestfs
mailing list