From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wei Liu Subject: [PATCH] xl: close restore file fd when we're done with it Date: Thu, 13 Aug 2015 11:09:38 +0100 Message-ID: <1439460578-18374-1-git-send-email-wei.liu2@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZPpSA-00018B-6t for xen-devel@lists.xenproject.org; Thu, 13 Aug 2015 10:09:42 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Xen-devel Cc: Ian Jackson , Andrew Armenia , Wei Liu , Ian Campbell List-Id: xen-devel@lists.xenproject.org And log if close fails. Reported-by: Andrew Armenia Signed-off-by: Wei Liu --- Cc: Ian Campbell Cc: Ian Jackson Cc: Andrew Armenia For 4.6, fix leaking fd to avoid holding on to restoring file. This should also be backported to many versions that uses xl. --- tools/libxl/xl_cmdimpl.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 499a05c..c6b0b68 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -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); -- 2.1.4