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

[Xen-changelog] [xen master] libxl: use libxl_fd_set_{cloexec, nonblock} helpers



commit 216236c58740cc7683fe4338ebb1915236d39a43
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Tue Jul 29 16:51:26 2014 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Tue Jul 29 16:51:26 2014 +0200

    libxl: use libxl_fd_set_{cloexec,nonblock} helpers
    
    ... instead of open-coding them or not using them at all. This in
    particular fixes a build (and presumably also runtime) problem on old
    enough libc due to the recent introduction of a use of O_CLOEXEC. The
    other two changes are only of cleanup kind.
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 tools/libxl/libxl_create.c |   14 ++------------
 tools/libxl/libxl_qmp.c    |    9 ++-------
 tools/libxl/libxl_utils.c  |    7 ++++++-
 3 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 0686f96..5bc8286 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -977,7 +977,7 @@ void libxl__xc_domain_restore_done(libxl__egc *egc, void 
*dcs_void,
     libxl_ctx *ctx = libxl__gc_owner(gc);
     char **vments = NULL, **localents = NULL;
     struct timeval start_time;
-    int i, esave, flags;
+    int i, esave;
 
     /* convenience aliases */
     const uint32_t domid = dcs->guest_domid;
@@ -1045,17 +1045,7 @@ out:
     }
 
     esave = errno;
-
-    flags = fcntl(fd, F_GETFL);
-    if (flags == -1) {
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "unable to get flags on 
restore fd");
-    } else {
-        flags &= ~O_NONBLOCK;
-        if (fcntl(fd, F_SETFL, flags) == -1)
-            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "unable to put restore fd"
-                         " back to blocking mode");
-    }
-
+    libxl_fd_set_nonblock(ctx, fd, 0);
     errno = esave;
     domcreate_rebuild_done(egc, dcs, ret);
 }
diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
index 5cc56b1..c7324e6 100644
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -358,19 +358,14 @@ static int qmp_open(libxl__qmp_handler *qmp, const char 
*qmp_socket_path,
                     int timeout)
 {
     int ret;
-    int flags = 0;
     int i = 0;
 
     qmp->qmp_fd = socket(AF_UNIX, SOCK_STREAM, 0);
     if (qmp->qmp_fd < 0) {
         return -1;
     }
-    if ((flags = fcntl(qmp->qmp_fd, F_GETFL)) == -1) {
-        flags = 0;
-    }
-    if (fcntl(qmp->qmp_fd, F_SETFL, flags | O_NONBLOCK) == -1) {
-        return -1;
-    }
+    ret = libxl_fd_set_nonblock(qmp->ctx, qmp->qmp_fd, 1);
+    if (ret) return -1;
     ret = libxl_fd_set_cloexec(qmp->ctx, qmp->qmp_fd, 1);
     if (ret) return -1;
 
diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index 1fdf5ea..58df4f3 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -1047,11 +1047,16 @@ int libxl__random_bytes(libxl__gc *gc, uint8_t *buf, 
size_t len)
     int fd;
     int ret;
 
-    fd = open(dev, O_RDONLY | O_CLOEXEC);
+    fd = open(dev, O_RDONLY);
     if (fd < 0) {
         LOGE(ERROR, "failed to open \"%s\"", dev);
         return ERROR_FAIL;
     }
+    ret = libxl_fd_set_cloexec(CTX, fd, 1);
+    if (ret) {
+        close(fd);
+        return ERROR_FAIL;
+    }
 
     ret = libxl_read_exactly(CTX, fd, buf, len, dev, NULL);
 
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
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®.