]> xenbits.xensource.com Git - people/iwj/ring3-xl-test.git/commitdiff
test_domain_suspend: Switch from mkstemp to tmpfile
authorEuan Harris <euan.harris@citrix.com>
Fri, 19 Jun 2015 14:07:28 +0000 (14:07 +0000)
committerEuan Harris <euan.harris@citrix.com>
Fri, 19 Jun 2015 14:07:28 +0000 (14:07 +0000)
Temporary files created by tmpfile are cleaned up automatically
when they are closed or at exit.

Signed-off-by: Euan Harris <euan.harris@citrix.com>
test_domain_suspend.c

index 63444a7de043ca8171735b909ea9a42db92c378a..344c4f39ef0dd1f4a36a9e97cbfe7141cefc9151 100644 (file)
@@ -50,24 +50,24 @@ 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";
+        FILE *suspend_file;
+        int suspend_fd;
 
         printf("\n****** Will cancel after %d events ******\n", count);
 
-        fd = mkstemp(template);
-        if (fd < 0) {
-            perror("mkstemp");
+        suspend_file = tmpfile();
+        if (!suspend_file) {
+            perror("tmpfile");
             break;
         }
-        do_domain_suspend(tc, domid, fd);
+        suspend_fd = fileno(suspend_file);
+        do_domain_suspend(tc, domid, suspend_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);
-            unlink(template);
+            fclose(suspend_file);
             printf("libxl_domain_suspend returned %d\n",
                    ev.u.callback_event.rc);
             assert(ev.u.callback_event.rc == 0);
@@ -90,9 +90,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("Removing %s\n", template);
-        unlink(template);
+        fclose(suspend_file);
         printf("libxl_domain_suspend returned %d\n",
                ev.u.callback_event.rc);
         assert(ev.u.callback_event.rc == ERROR_CANCELLED