From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yu Zhiguo Subject: [PATCH] xl: sanity check for 'xl info' Date: Wed, 28 Apr 2010 11:35:17 +0800 Message-ID: <4BD7ACF5.1050600@cn.fujitsu.com> References: <4BD559E1.6030102@cn.fujitsu.com> <4BD570D2.2060204@amd.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4BD570D2.2060204@amd.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Andre Przywara Cc: "xen-devel@lists.xensource.com" , Keir Fraser List-Id: xen-devel@lists.xenproject.org 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 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; }