WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] libxl: Compilation and other small fixes

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] libxl: Compilation and other small fixes
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 19 May 2010 05:16:15 -0700
Delivery-date: Wed, 19 May 2010 05:22:17 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1274253646 -3600
# Node ID eb4ecc037b7a53647f0ac89c7067d11ea622ab00
# Parent  165116a220d9912c29a56aaa32c1a6652cdd1988
libxl: Compilation and other small fixes

* Some of the library functions such as fscanf, system, and asprintf
are declared with warn_unused_result (ubuntu server 9.10), causing
compilation errors in libxl.
* When using asprintf, the caller is responsible for freeing the
memory.
* memset takes wrong size argument in one of the places (caught by
a builtin gcc check).

Signed-off-by: Dulloor Rao <dulloor@xxxxxxxxx>
---
 tools/libxl/libxl.c      |   15 ++++++-----
 tools/libxl/xl_cmdimpl.c |   59 +++++++++++++++++++++++++++++++----------------
 2 files changed, 47 insertions(+), 27 deletions(-)

diff -r 165116a220d9 -r eb4ecc037b7a tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Wed May 19 08:18:51 2010 +0100
+++ b/tools/libxl/libxl.c       Wed May 19 08:20:46 2010 +0100
@@ -1262,7 +1262,8 @@ static char *get_blktap2_device(struct l
 
     
     while (!feof(f)) {
-        fscanf(f, "%d %s", &devnum, buf);
+        if (fscanf(f, "%d %s", &devnum, buf) != 2)
+            continue;
         p = strchr(buf, ':');
         if (p == NULL)
             continue;
@@ -2276,7 +2277,8 @@ int libxl_device_pci_add(struct libxl_ct
             return -1;
         }
         for (i = 0; i < PROC_PCI_NUM_RESOURCES; i++) {
-            fscanf(f, "0x%x 0x%x 0x%x", &start, &end, &flags);
+            if (fscanf(f, "0x%x 0x%x 0x%x", &start, &end, &flags) != 3)
+                continue;
             size = end - start + 1;
             if (start) {
                 if (flags & PCI_BAR_IO) {
@@ -2299,8 +2301,7 @@ int libxl_device_pci_add(struct libxl_ct
             XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "Couldn't open %s", sysfs_path);
             goto out;
         }
-        fscanf(f, "%u", &irq);
-        if (irq) {
+        if ((fscanf(f, "%u", &irq) == 1) && irq) {
             rc = xc_physdev_map_pirq(ctx->xch, domid, irq, &irq);
             if (rc < 0) {
                 XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, "Error: 
xc_physdev_map_pirq irq=%d", irq);
@@ -2364,7 +2365,8 @@ int libxl_device_pci_remove(struct libxl
             goto skip1;
         }
         for (i = 0; i < PROC_PCI_NUM_RESOURCES; i++) {
-            fscanf(f, "0x%x 0x%x 0x%x\n", &start, &end, &flags);
+            if (fscanf(f, "0x%x 0x%x 0x%x\n", &start, &end, &flags) != 3)
+                continue;
             size = end - start + 1;
             if (start) {
                 if (flags & PCI_BAR_IO) {
@@ -2388,8 +2390,7 @@ skip1:
             XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "Couldn't open %s", sysfs_path);
             goto out;
         }
-        fscanf(f, "%u", &irq);
-        if (irq) {
+        if ((fscanf(f, "%u", &irq) == 1) && irq) {
             rc = xc_physdev_unmap_pirq(ctx->xch, domid, irq);
             if (rc < 0) {
                 XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, "xc_physdev_map_pirq 
irq=%d", irq);
diff -r 165116a220d9 -r eb4ecc037b7a tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Wed May 19 08:18:51 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Wed May 19 08:20:46 2010 +0100
@@ -1141,7 +1141,7 @@ start:
         xc_domaininfo_t info;
         libxl_event event;
         libxl_device_disk disk;
-        memset(&info, 0x00, sizeof(xc_dominfo_t));
+        memset(&info, 0x00, sizeof(xc_domaininfo_t));
 
         FD_ZERO(&rfds);
         FD_SET(fd, &rfds);
@@ -3227,9 +3227,7 @@ int main_top(int argc, char **argv)
         }
     }
 
-    system("xentop");
-
-    exit(0);
+    exit(system("xentop"));
 }
 
 int main_networkattach(int argc, char **argv)
@@ -3560,6 +3558,7 @@ static char *uptime_to_string(unsigned l
 {
     int sec, min, hour, day;
     char *time_string;
+    int ret;
 
     day = (int)(time / 86400);
     time -= (day * 86400);
@@ -3571,19 +3570,21 @@ static char *uptime_to_string(unsigned l
 
     if (short_mode)
         if (day > 1)
-            asprintf(&time_string, "%d days, %2d:%02d", day, hour, min);
+            ret = asprintf(&time_string, "%d days, %2d:%02d", day, hour, min);
         else if (day == 1)
-            asprintf(&time_string, "%d day, %2d:%02d", day, hour, min);
+            ret = asprintf(&time_string, "%d day, %2d:%02d", day, hour, min);
         else
-            asprintf(&time_string, "%2d:%02d", hour, min);
+            ret = asprintf(&time_string, "%2d:%02d", hour, min);
     else
         if (day > 1)
-            asprintf(&time_string, "%d days, %2d:%02d:%02d", day, hour, min, 
sec);
+            ret = asprintf(&time_string, "%d days, %2d:%02d:%02d", day, hour, 
min, sec);
         else if (day == 1)
-            asprintf(&time_string, "%d day, %2d:%02d:%02d", day, hour, min, 
sec);
+            ret = asprintf(&time_string, "%d day, %2d:%02d:%02d", day, hour, 
min, sec);
         else
-            asprintf(&time_string, "%2d:%02d:%02d", hour, min, sec);
-
+            ret = asprintf(&time_string, "%2d:%02d:%02d", hour, min, sec);
+
+    if (ret < 0)
+        return NULL;
     return time_string;
 }
 
@@ -3609,8 +3610,9 @@ static void print_dom0_uptime(int short_
     int fd;
     char buf[512];
     uint32_t uptime = 0;
-
-    fd = open("/proc/uptime", 'r');
+    char *uptime_str = 0;
+
+    fd = open("/proc/uptime", O_RDONLY);
     if (fd == -1)
         goto err;
 
@@ -3624,12 +3626,20 @@ static void print_dom0_uptime(int short_
     uptime = strtoul(buf, NULL, 10);
 
     if (short_mode)
+    {
+        uptime_str = uptime_to_string(uptime, 1);
         printf(" %s up %s, %s (%d)\n", current_time_to_string(now),
-               uptime_to_string(uptime, 1), libxl_domid_to_name(&ctx, 0), 0);
+               uptime_str, libxl_domid_to_name(&ctx, 0), 0);
+    }
     else
+    {
+        uptime_str = uptime_to_string(uptime, 0);
         printf("%-33s %4d %s\n", libxl_domid_to_name(&ctx, 0),
-               0, uptime_to_string(uptime, 0));
-
+               0, uptime_str);
+    }
+
+    if (uptime_str)
+        free(uptime_str);
     return;
 err:
     fprintf(stderr, "Can not get Dom0 uptime.\n");
@@ -3640,19 +3650,28 @@ static void print_domU_uptime(uint32_t d
 {
     uint32_t s_time = 0;
     uint32_t uptime = 0;
+    char *uptime_str = 0;
 
     s_time = libxl_vm_get_start_time(&ctx, domuid);
     if (s_time == -1)
         return;
     uptime = now - s_time;
     if (short_mode)
+    {
+        uptime_str = uptime_to_string(uptime, 1);
         printf(" %s up %s, %s (%d)\n", current_time_to_string(now),
-               uptime_to_string(uptime, 1),
-               libxl_domid_to_name(&ctx, domuid),
-               domuid);
+               uptime_str, libxl_domid_to_name(&ctx, domuid), domuid);
+    }
     else
+    {
+        uptime_str = uptime_to_string(uptime, 0);
         printf("%-33s %4d %s\n", libxl_domid_to_name(&ctx, domuid),
-               domuid, uptime_to_string(uptime, 0));
+               domuid, uptime_str);
+    }
+
+    if (uptime_str)
+        free(uptime_str);
+    return;
 }
 
 static void print_uptime(int short_mode, uint32_t doms[], int nb_doms)

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] libxl: Compilation and other small fixes, Xen patchbot-unstable <=