]> xenbits.xensource.com Git - people/iwj/ring3-xl-test.git/commitdiff
Stop leaking the suspend image FD
authorEuan Harris <euan.harris@citrix.com>
Thu, 18 Jun 2015 14:52:19 +0000 (14:52 +0000)
committerEuan Harris <euan.harris@citrix.com>
Thu, 18 Jun 2015 14:52:19 +0000 (14:52 +0000)
Signed-off-by: Euan Harris <euan.harris@citrix.com>
test_domain_suspend.c
testcase_utils.c
testcase_utils.h

index 499661acf02e9f66c2db95791d6babf21c828b40..6d0ce998db85f040a40685821e9bb52ee28f8cbe 100644 (file)
@@ -1,6 +1,8 @@
 #include <assert.h>
 #include <libxl.h>
 #include <libxl_event.h>
+#include <stdlib.h>
+#include <unistd.h>
 #include "testcase_runner.h"
 #include "eventloop_runner.h"
 #include "testcase_utils.h"
@@ -48,15 +50,23 @@ void *testcase(struct test *tc)
        least the next fd event on a different fd */
     for (count = 1; count < 100; count++) {
         int rc;
+        int fd;
+        char template[] = "/tmp/xltest-XXXXXX";
 
         printf("\n****** Will cancel after %d events ******\n", count);
 
-        do_domain_suspend(tc, domid);
+        fd = mkstemp(template);
+        if (fd < 0) {
+            perror("mkstemp");
+            break;
+        }
+        do_domain_suspend(tc, domid, fd);
 
         if (wait_until_n(tc, EV_LIBXL_CALLBACK, count, &ev)) {
             /* The API call returned before we could cancel it.
                It should have returned successfully.
              */
+            close(fd);
             printf("libxl_domain_suspend returned %d\n",
                    ev.u.callback_event.rc);
             assert(ev.u.callback_event.rc == 0);
@@ -79,6 +89,7 @@ void *testcase(struct test *tc)
 
         /* The API call's return code should indicate that it was cancelled */
         wait_for(tc, EV_LIBXL_CALLBACK, &ev);
+        close(fd);
         printf("libxl_domain_suspend returned %d\n",
                ev.u.callback_event.rc);
         assert(ev.u.callback_event.rc == ERROR_CANCELLED
index 74c974b2af4b4ca087b0a6c79376efee14e10d3c..98dd2797e9e5531175dce9cfb4d7315643ea7b4a 100644 (file)
@@ -1,5 +1,3 @@
-#include <fcntl.h>
-#include <libxl.h>
 #include <stdlib.h>
 
 #include "testcase_utils.h"
@@ -70,12 +68,10 @@ do_domain_create(struct test *t, libxl_domain_config * dc,
     return libxl_domain_create_new(t->ctx, dc, domid_out, &t->ao_how, 0);
 }
 
-int do_domain_suspend(struct test *t, uint32_t domid)
+int do_domain_suspend(struct test *t, uint32_t domid, int fd)
 {
-    int fd = open("/tmp/suspend", O_RDWR | O_CREAT | O_TRUNC, 0644);  /* XXX leaked */
-
     t->ao_how.callback = generic_callback;
     t->ao_how.u.for_callback = t;
 
-    return libxl_domain_suspend(t->ctx, domid, fd, 0, &t->ao_how);
+    return libxl_domain_suspend(t->ctx, domid, fd, LIBXL_SUSPEND_LIVE, &t->ao_how);
 }
index 8be9502b55720c2474d640ad0e5c33a79d092832..23748b7c02eb3d10483869594f6b87622d5a2a85 100644 (file)
@@ -10,6 +10,6 @@ void init_domain_config(libxl_domain_config * dc,
                         char *hdd, char *cdrom);
 int do_domain_create(struct test *t, libxl_domain_config * dc,
                      uint32_t * domid_out);
-int do_domain_suspend(struct test *t, uint32_t domid);
+int do_domain_suspend(struct test *t, uint32_t domid, int fd);
 
 #endif                          /* __TESTCASE_UTILS */