Andre Przywara wrote:
> Yu Zhiguo wrote:
>> If error occurs in 'xl info', we'd better output an error message
>> rather than a broken result.
> Do you consider an incomplete output as broken? If I got this right, you
> want to make sure that you output everything or nothing with this patch.
> Wouldn't it be sufficient to just add the missing check for utsname()
> and output the other infos regardless? Was there a scenario where broken
> output was generated? So far I only see missing Xen support or missing
> privileges to cause errors.
It seems that xm will always output all or nothing, so I think we'd better
compatible with xm. But it isn't so important, just add sanity check now.
Regards
Yu Zhiguo
--------------------------------------
Add sanity check for 'xl info'.
Signed-off-by: Yu Zhiguo <yuzg@xxxxxxxxxxxxxx>
diff -r c87ec146229a -r c4a684b35c7b tools/libxl/xl.c
--- a/tools/libxl/xl.c Fri Apr 23 15:04:26 2010 +0100
+++ b/tools/libxl/xl.c Wed Apr 28 19:24:13 2010 +0800
@@ -2647,7 +2647,10 @@
const libxl_version_info *info;
int sched_id;
- info = libxl_get_version_info(&ctx);
+ if (!(info = libxl_get_version_info(&ctx))) {
+ fprintf(stderr, "libxl_get_version_info failed.\n");
+ return;
+ }
if ((sched_id = libxl_get_sched_id(&ctx)) < 0) {
fprintf(stderr, "get_sched_id sysctl failed.\n");
return;
@@ -2677,12 +2680,12 @@
{
struct utsname utsbuf;
- uname(&utsbuf);
-
- printf("host : %s\n", utsbuf.nodename);
- printf("release : %s\n", utsbuf.release);
- printf("version : %s\n", utsbuf.version);
- printf("machine : %s\n", utsbuf.machine);
+ if (uname(&utsbuf) != -1) {
+ printf("host : %s\n", utsbuf.nodename);
+ printf("release : %s\n", utsbuf.release);
+ printf("version : %s\n", utsbuf.version);
+ printf("machine : %s\n", utsbuf.machine);
+ }
return;
}
@@ -2713,9 +2716,11 @@
printf(" hvm_directio");
printf("\n");
vinfo = libxl_get_version_info(&ctx);
- i = (1 << 20) / vinfo->pagesize;
- printf("total_memory : %lu\n", info.total_pages / i);
- printf("free_memory : %lu\n", info.free_pages / i);
+ if (vinfo) {
+ i = (1 << 20) / vinfo->pagesize;
+ printf("total_memory : %lu\n", info.total_pages / i);
+ printf("free_memory : %lu\n", info.free_pages / i);
+ }
return;
}
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|