xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] compilation and other small fixes to libxl
@ 2010-05-19  1:25 Dulloor
  2010-05-19  1:40 ` Yang Hongyang
  0 siblings, 1 reply; 2+ messages in thread
From: Dulloor @ 2010-05-19  1:25 UTC (permalink / raw)
  To: xen-devel

[-- Attachment #1: Type: text/plain, Size: 426 bytes --]

Patch fixes the following problems :

* 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 an
a builtin gcc check).

-dulloor

Signed-off-by: Dulloor Rao <dulloor@gmail.com>

[-- Attachment #2: libxl-fixes.patch --]
[-- Type: text/x-diff, Size: 5923 bytes --]

diff -r baccadfd9418 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri May 14 08:05:05 2010 +0100
+++ b/tools/libxl/libxl.c	Tue May 18 11:16:24 2010 -0700
@@ -1248,7 +1248,8 @@
 
     
     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;
@@ -2262,7 +2263,8 @@
             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) {
@@ -2285,8 +2287,7 @@
             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);
@@ -2350,7 +2351,8 @@
             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) {
@@ -2374,8 +2376,7 @@
             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 baccadfd9418 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Fri May 14 08:05:05 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c	Tue May 18 11:16:24 2010 -0700
@@ -1125,7 +1125,7 @@
         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);
@@ -3182,9 +3182,7 @@
         }
     }
 
-    system("xentop");
-
-    exit(0);
+    exit(system("xentop"));
 }
 
 int main_networkattach(int argc, char **argv)
@@ -3515,6 +3513,7 @@
 {
     int sec, min, hour, day;
     char *time_string;
+    int ret;
 
     day = (int)(time / 86400);
     time -= (day * 86400);
@@ -3526,19 +3525,21 @@
 
     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;
 }
 
@@ -3564,8 +3565,9 @@
     int fd;
     char buf[512];
     uint32_t uptime = 0;
+    char *uptime_str = 0;
 
-    fd = open("/proc/uptime", 'r');
+    fd = open("/proc/uptime", O_RDONLY);
     if (fd == -1)
         goto err;
 
@@ -3579,12 +3581,20 @@
     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");
@@ -3595,19 +3605,28 @@
 {
     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)
-        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 = uptime_to_string(uptime, 1);
+       	printf(" %s up %s, %s (%d)\n", current_time_to_string(now),
+               	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)

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-05-19  1:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-19  1:25 [PATCH] compilation and other small fixes to libxl Dulloor
2010-05-19  1:40 ` Yang Hongyang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).