From: "Jan Beulich" <JBeulich@suse.com>
To: xen-devel <xen-devel@lists.xenproject.org>
Cc: Ian Campbell <Ian.Campbell@eu.citrix.com>,
Ian Jackson <Ian.Jackson@eu.citrix.com>,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH] libxl: use libxl_fd_set_{cloexec, nonblock} helpers
Date: Fri, 25 Jul 2014 16:02:23 +0100 [thread overview]
Message-ID: <53D28D9F020000780002615D@mail.emea.novell.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2653 bytes --]
... 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@suse.com>
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -977,7 +977,7 @@ void libxl__xc_domain_restore_done(libxl
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;
@@ -1046,15 +1046,10 @@ 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"
+ ret = libxl_fd_set_nonblock(ctx, fd, 0);
+ if (ret)
+ LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "unable to put restore fd"
" back to blocking mode");
- }
errno = esave;
domcreate_rebuild_done(egc, dcs, ret);
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -358,19 +358,14 @@ static int qmp_open(libxl__qmp_handler *
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;
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -1047,11 +1047,17 @@ int libxl__random_bytes(libxl__gc *gc, u
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);
+ LOGE(ERROR, "failed to set close-on-exec on handle to \"%s\"", dev);
+ return ERROR_FAIL;
+ }
ret = libxl_read_exactly(CTX, fd, buf, len, dev, NULL);
[-- Attachment #2: libxl-use-cloexec-nonblock-helpers.patch --]
[-- Type: text/plain, Size: 2701 bytes --]
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@suse.com>
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -977,7 +977,7 @@ void libxl__xc_domain_restore_done(libxl
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;
@@ -1046,15 +1046,10 @@ 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"
+ ret = libxl_fd_set_nonblock(ctx, fd, 0);
+ if (ret)
+ LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "unable to put restore fd"
" back to blocking mode");
- }
errno = esave;
domcreate_rebuild_done(egc, dcs, ret);
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -358,19 +358,14 @@ static int qmp_open(libxl__qmp_handler *
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;
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -1047,11 +1047,17 @@ int libxl__random_bytes(libxl__gc *gc, u
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);
+ LOGE(ERROR, "failed to set close-on-exec on handle to \"%s\"", dev);
+ return ERROR_FAIL;
+ }
ret = libxl_read_exactly(CTX, fd, buf, len, dev, NULL);
[-- Attachment #3: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next reply other threads:[~2014-07-25 15:02 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-25 15:02 Jan Beulich [this message]
2014-07-25 17:07 ` [PATCH] libxl: use libxl_fd_set_{cloexec, nonblock} helpers Ian Jackson
2014-07-28 6:32 ` Jan Beulich
2014-07-28 14:51 ` David Vrabel
2014-07-29 9:15 ` Ian Campbell
2014-08-01 13:43 ` Don Slutz
2014-07-28 7:30 ` [PATCH v2] " Jan Beulich
2014-07-29 14:29 ` Ian Jackson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53D28D9F020000780002615D@mail.emea.novell.com \
--to=jbeulich@suse.com \
--cc=Ian.Campbell@eu.citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).