xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xl: close restore file fd when we're done with it
@ 2015-08-13 10:09 Wei Liu
  2015-08-13 10:10 ` Wei Liu
  2015-08-13 10:15 ` Ian Campbell
  0 siblings, 2 replies; 4+ messages in thread
From: Wei Liu @ 2015-08-13 10:09 UTC (permalink / raw)
  To: Xen-devel; +Cc: Ian Jackson, Andrew Armenia, Wei Liu, Ian Campbell

And log if close fails.

Reported-by: Andrew Armenia <andrew@asquaredlabs.com>
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Andrew Armenia <andrew@asquaredlabs.com>

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

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

* Re: [PATCH] xl: close restore file fd when we're done with it
  2015-08-13 10:09 [PATCH] xl: close restore file fd when we're done with it Wei Liu
@ 2015-08-13 10:10 ` Wei Liu
  2015-08-13 10:15 ` Ian Campbell
  1 sibling, 0 replies; 4+ messages in thread
From: Wei Liu @ 2015-08-13 10:10 UTC (permalink / raw)
  To: Xen-devel; +Cc: Ian Jackson, Andrew Armenia, Wei Liu, Ian Campbell

This patch is for 4.6. Forgot to extend the tag in subject line.

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

* Re: [PATCH] xl: close restore file fd when we're done with it
  2015-08-13 10:09 [PATCH] xl: close restore file fd when we're done with it Wei Liu
  2015-08-13 10:10 ` Wei Liu
@ 2015-08-13 10:15 ` Ian Campbell
  2015-08-16  8:01   ` Ian Campbell
  1 sibling, 1 reply; 4+ messages in thread
From: Ian Campbell @ 2015-08-13 10:15 UTC (permalink / raw)
  To: Wei Liu, Xen-devel; +Cc: Andrew Armenia, Ian Jackson

On Thu, 2015-08-13 at 11:09 +0100, Wei Liu wrote:
> 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>

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

* Re: [PATCH] xl: close restore file fd when we're done with it
  2015-08-13 10:15 ` Ian Campbell
@ 2015-08-16  8:01   ` Ian Campbell
  0 siblings, 0 replies; 4+ messages in thread
From: Ian Campbell @ 2015-08-16  8:01 UTC (permalink / raw)
  To: Wei Liu, Xen-devel; +Cc: Andrew Armenia, Ian Jackson

On Thu, 2015-08-13 at 11:15 +0100, Ian Campbell wrote:
> On Thu, 2015-08-13 at 11:09 +0100, Wei Liu wrote:
> > 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>

Applied.

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

end of thread, other threads:[~2015-08-16  8:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-13 10:09 [PATCH] xl: close restore file fd when we're done with it Wei Liu
2015-08-13 10:10 ` Wei Liu
2015-08-13 10:15 ` Ian Campbell
2015-08-16  8:01   ` Ian Campbell

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).