]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/xen.git/commitdiff
xl: close restore file fd when we're done with it
authorWei Liu <wei.liu2@citrix.com>
Thu, 13 Aug 2015 10:09:38 +0000 (11:09 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Sun, 16 Aug 2015 06:48:37 +0000 (07:48 +0100)
And log if close fails.

Reported-by: Andrew Armenia <andrew@asquaredlabs.com>
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
tools/libxl/xl_cmdimpl.c

index 499a05ce875ac20f3ad0f8d2f361f8a73fb50568..c6b0b6827627bb16304595ebb573074de09e0381 100644 (file)
@@ -2627,6 +2627,7 @@ static uint32_t create_domain(struct domain_create *dom_info)
     void *config_data = 0;
     int config_len = 0;
     int restore_fd = -1;
+    int restore_fd_to_close = -1;
     const libxl_asyncprogress_how *autoconnect_console_how;
     struct save_file_header hdr;
 
@@ -2650,6 +2651,7 @@ static uint32_t create_domain(struct domain_create *dom_info)
                 fprintf(stderr, "Can't open restore file: %s\n", strerror(errno));
                 return ERROR_INVAL;
             }
+            restore_fd_to_close = restore_fd;
             rc = libxl_fd_set_cloexec(ctx, restore_fd, 1);
             if (rc) return rc;
         }
@@ -2851,6 +2853,13 @@ start:
 
     release_lock();
 
+    if (restore_fd_to_close >= 0) {
+        if (close(restore_fd_to_close))
+            fprintf(stderr, "Failed to close restoring file, fd %d, errno %d\n",
+                    restore_fd_to_close, errno);
+        restore_fd_to_close = -1;
+    }
+
     if (!paused)
         libxl_domain_unpause(ctx, domid);