]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
xl: Apply CLOEXEC to the restore_fd.
authorAnthony Perard <anthony.perard@citrix.com>
Thu, 1 Dec 2011 16:28:51 +0000 (16:28 +0000)
committerAnthony Perard <anthony.perard@citrix.com>
Thu, 1 Dec 2011 16:28:51 +0000 (16:28 +0000)
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@citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/libxl.c
tools/libxl/libxl.h
tools/libxl/libxl_internal.c
tools/libxl/libxl_internal.h
tools/libxl/libxl_qmp.c
tools/libxl/xl_cmdimpl.c

index a171142b89aadc6c6833cf397175b183a4c6a785..de35adf2d0ba1322541eecb294b98b3bb806836a 100644 (file)
@@ -3330,6 +3330,19 @@ int libxl_cpupool_movedomain(libxl_ctx *ctx, uint32_t poolid, uint32_t domid)
     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
index 289dc85b7b998410b0a167098f40130c4fab864a..8e428227b8265a46ebb851146664e70412ebbd6e 100644 (file)
@@ -635,6 +635,9 @@ const char *libxl_lock_dir_path(void);
 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 */
 
 /*
index 34edaf384dd499104f4c7888db7d8aa3f61a21d9..028f90f74ba807346c0318b840255668df5ada47 100644 (file)
@@ -306,19 +306,6 @@ _hidden int libxl__compare_macs(libxl_mac *a, libxl_mac *b)
     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)
 {
index 84da6b1cb7a28106742523bc290556aad36c5c22..6ce34fd67aef4db3322f0ccac36a2a7421959239 100644 (file)
@@ -503,7 +503,6 @@ _hidden int libxl__error_set(libxl__gc *gc, int code);
 
 _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);
 
index f749e011baa4c22c753bd2f3e9023c7411f5d32a..66a013435e13dab9f6bf77894c44a193809e03fd 100644 (file)
@@ -324,7 +324,7 @@ static int qmp_open(libxl__qmp_handler *qmp, const char *qmp_socket_path,
     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;
index f1e729c6a2df7bf6e4a97a8b3a5ac9befcf4096f..97141d192d590994e0d9f7c0456d82dd7d4a47dc 100644 (file)
@@ -1459,8 +1459,12 @@ static int create_domain(struct domain_create *dom_info)
         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") );