[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] xl: Apply CLOEXEC to the restore_fd.



# HG changeset patch
# User Anthony Perard <anthony.perard@xxxxxxxxxx>
# Date 1322756931 0
# Node ID 617b56ea3291052f6c5688e3f9693919d3e70d7f
# Parent  7a08053a4c39ecd1bf482641fad0f4fcd7d4441c
xl: Apply CLOEXEC to the restore_fd.

At restore time, the file descriptor opened on the migration state file is
still open in the device model. Let's apply FD_CLOEXEC to it.

This patch provides libxl_fd_set_cloexec to users of libxl, instead of keeping
this function internal.

Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
Committed-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---


diff -r 7a08053a4c39 -r 617b56ea3291 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Thu Dec 01 16:26:36 2011 +0000
+++ b/tools/libxl/libxl.c       Thu Dec 01 16:28:51 2011 +0000
@@ -3330,6 +3330,19 @@
     return 0;
 }
 
+int libxl_fd_set_cloexec(int fd)
+{
+    int flags = 0;
+
+    if ((flags = fcntl(fd, F_GETFD)) == -1) {
+        flags = 0;
+    }
+    if ((flags & FD_CLOEXEC)) {
+        return 0;
+    }
+    return fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
+}
+
 /*
  * Local variables:
  * mode: C
diff -r 7a08053a4c39 -r 617b56ea3291 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Thu Dec 01 16:26:36 2011 +0000
+++ b/tools/libxl/libxl.h       Thu Dec 01 16:28:51 2011 +0000
@@ -635,6 +635,9 @@
 const char *libxl_run_dir_path(void);
 const char *libxl_xenpaging_dir_path(void);
 
+/* misc */
+int libxl_fd_set_cloexec(int fd);
+
 #endif /* LIBXL_H */
 
 /*
diff -r 7a08053a4c39 -r 617b56ea3291 tools/libxl/libxl_internal.c
--- a/tools/libxl/libxl_internal.c      Thu Dec 01 16:26:36 2011 +0000
+++ b/tools/libxl/libxl_internal.c      Thu Dec 01 16:28:51 2011 +0000
@@ -306,19 +306,6 @@
     return 0;
 }
 
-int libxl__fd_set_cloexec(int fd)
-{
-    int flags = 0;
-
-    if ((flags = fcntl(fd, F_GETFD)) == -1) {
-        flags = 0;
-    }
-    if ((flags & FD_CLOEXEC)) {
-        return 0;
-    }
-    return fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
-}
-
 libxl_device_model_version libxl__device_model_version_running(libxl__gc *gc,
                                                                uint32_t domid)
 {
diff -r 7a08053a4c39 -r 617b56ea3291 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Thu Dec 01 16:26:36 2011 +0000
+++ b/tools/libxl/libxl_internal.h      Thu Dec 01 16:28:51 2011 +0000
@@ -503,7 +503,6 @@
 
 _hidden int libxl__file_reference_map(libxl_file_reference *f);
 _hidden int libxl__file_reference_unmap(libxl_file_reference *f);
-_hidden int libxl__fd_set_cloexec(int fd);
 
 _hidden int libxl__e820_alloc(libxl__gc *gc, uint32_t domid, 
libxl_domain_config *d_config);
 
diff -r 7a08053a4c39 -r 617b56ea3291 tools/libxl/libxl_qmp.c
--- a/tools/libxl/libxl_qmp.c   Thu Dec 01 16:26:36 2011 +0000
+++ b/tools/libxl/libxl_qmp.c   Thu Dec 01 16:28:51 2011 +0000
@@ -324,7 +324,7 @@
     if (fcntl(qmp->qmp_fd, F_SETFL, flags | O_NONBLOCK) == -1) {
         return -1;
     }
-    libxl__fd_set_cloexec(qmp->qmp_fd);
+    libxl_fd_set_cloexec(qmp->qmp_fd);
 
     memset(&qmp->addr, 0, sizeof (&qmp->addr));
     qmp->addr.sun_family = AF_UNIX;
diff -r 7a08053a4c39 -r 617b56ea3291 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Thu Dec 01 16:26:36 2011 +0000
+++ b/tools/libxl/xl_cmdimpl.c  Thu Dec 01 16:28:51 2011 +0000
@@ -1459,8 +1459,12 @@
         union { uint32_t u32; char b[4]; } u32buf;
         uint32_t badflags;
 
-        restore_fd = migrate_fd >= 0 ? migrate_fd :
-            open(restore_file, O_RDONLY);
+        if (migrate_fd >= 0) {
+            restore_fd = migrate_fd;
+        } else {
+            restore_fd = open(restore_file, O_RDONLY);
+            libxl_fd_set_cloexec(restore_fd);
+        }
 
         CHK_ERRNO( libxl_read_exactly(ctx, restore_fd, &hdr,
                    sizeof(hdr), restore_file, "header") );

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.