From: "Jan Beulich" Subject: [PATCH v2] libxl: use libxl_fd_set_{cloexec, nonblock} helpers Date: Mon, 28 Jul 2014 08:30:04 +0100 Message-ID: <53D6181C020000780002665E@mail.emea.novell.com> References: <53D28D9F020000780002615D@mail.emea.novell.com> <21458.36567.506481.423244@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartF9CB72EC.1__=" Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XBfNo-0006RM-IM for xen-devel@lists.xenproject.org; Mon, 28 Jul 2014 07:30:08 +0000 In-Reply-To: <21458.36567.506481.423244@mariner.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Ian Campbell , Ian Jackson , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartF9CB72EC.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline ... 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 --- v2: Drop unnecessary logging (and result value corruption in the libxl__xc_domain_restore_done() case). --- 2014-07-25.orig/tools/libxl/libxl_create.c 2014-07-25 10:41:10.0000000= 00 +0200 +++ 2014-07-25/tools/libxl/libxl_create.c 2014-07-28 09:23:18.0000000= 00 +0200 @@ -977,7 +977,7 @@ void libxl__xc_domain_restore_done(libxl libxl_ctx *ctx =3D libxl__gc_owner(gc); char **vments =3D NULL, **localents =3D NULL; struct timeval start_time; - int i, esave, flags; + int i, esave; =20 /* convenience aliases */ const uint32_t domid =3D dcs->guest_domid; @@ -1045,17 +1045,7 @@ out: } =20 esave =3D errno; - - flags =3D fcntl(fd, F_GETFL); - if (flags =3D=3D -1) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "unable to get flags on = restore fd"); - } else { - flags &=3D ~O_NONBLOCK; - if (fcntl(fd, F_SETFL, flags) =3D=3D -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 =3D esave; domcreate_rebuild_done(egc, dcs, ret); } --- 2014-07-25.orig/tools/libxl/libxl_qmp.c 2014-07-25 10:41:10.0000000= 00 +0200 +++ 2014-07-25/tools/libxl/libxl_qmp.c 2014-07-25 16:17:40.000000000 = +0200 @@ -358,19 +358,14 @@ static int qmp_open(libxl__qmp_handler * int timeout) { int ret; - int flags =3D 0; int i =3D 0; =20 qmp->qmp_fd =3D socket(AF_UNIX, SOCK_STREAM, 0); if (qmp->qmp_fd < 0) { return -1; } - if ((flags =3D fcntl(qmp->qmp_fd, F_GETFL)) =3D=3D -1) { - flags =3D 0; - } - if (fcntl(qmp->qmp_fd, F_SETFL, flags | O_NONBLOCK) =3D=3D -1) { - return -1; - } + ret =3D libxl_fd_set_nonblock(qmp->ctx, qmp->qmp_fd, 1); + if (ret) return -1; ret =3D libxl_fd_set_cloexec(qmp->ctx, qmp->qmp_fd, 1); if (ret) return -1; =20 --- 2014-07-25.orig/tools/libxl/libxl_utils.c 2014-07-25 10:41:10.0000000= 00 +0200 +++ 2014-07-25/tools/libxl/libxl_utils.c 2014-07-28 09:24:38.0000000= 00 +0200 @@ -1047,11 +1047,16 @@ int libxl__random_bytes(libxl__gc *gc, u int fd; int ret; =20 - fd =3D open(dev, O_RDONLY | O_CLOEXEC); + fd =3D open(dev, O_RDONLY); if (fd < 0) { LOGE(ERROR, "failed to open \"%s\"", dev); return ERROR_FAIL; } + ret =3D libxl_fd_set_cloexec(CTX, fd, 1); + if (ret) { + close(fd); + return ERROR_FAIL; + } =20 ret =3D libxl_read_exactly(CTX, fd, buf, len, dev, NULL); =20 --=__PartF9CB72EC.1__= Content-Type: text/plain; name="libxl-use-cloexec-nonblock-helpers.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="libxl-use-cloexec-nonblock-helpers.patch" libxl: use libxl_fd_set_{cloexec,nonblock} helpers=0A=0A... instead of = open-coding them or not using them at all. This in=0Aparticular fixes a = build (and presumably also runtime) problem on old=0Aenough libc due to = the recent introduction of a use of O_CLOEXEC. The=0Aother two changes are = only of cleanup kind.=0A=0ASigned-off-by: Jan Beulich = =0A---=0Av2: Drop unnecessary logging (and result value corruption in = the=0A libxl__xc_domain_restore_done() case).=0A=0A--- 2014-07-25.orig/t= ools/libxl/libxl_create.c 2014-07-25 10:41:10.000000000 +0200=0A+++ = 2014-07-25/tools/libxl/libxl_create.c 2014-07-28 09:23:18.000000000 = +0200=0A@@ -977,7 +977,7 @@ void libxl__xc_domain_restore_done(libxl=0A = libxl_ctx *ctx =3D libxl__gc_owner(gc);=0A char **vments =3D NULL, = **localents =3D NULL;=0A struct timeval start_time;=0A- int i, = esave, flags;=0A+ int i, esave;=0A =0A /* convenience aliases */=0A = const uint32_t domid =3D dcs->guest_domid;=0A@@ -1045,17 +1045,7 @@ = out:=0A }=0A =0A esave =3D errno;=0A-=0A- flags =3D fcntl(fd, = F_GETFL);=0A- if (flags =3D=3D -1) {=0A- LIBXL__LOG_ERRNO(ctx, = LIBXL__LOG_ERROR, "unable to get flags on restore fd");=0A- } else = {=0A- flags &=3D ~O_NONBLOCK;=0A- if (fcntl(fd, F_SETFL, = flags) =3D=3D -1)=0A- LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, = "unable to put restore fd"=0A- " back to blocking = mode");=0A- }=0A-=0A+ libxl_fd_set_nonblock(ctx, fd, 0);=0A = errno =3D esave;=0A domcreate_rebuild_done(egc, dcs, ret);=0A }=0A--- = 2014-07-25.orig/tools/libxl/libxl_qmp.c 2014-07-25 10:41:10.000000000 = +0200=0A+++ 2014-07-25/tools/libxl/libxl_qmp.c 2014-07-25 16:17:40.0000000= 00 +0200=0A@@ -358,19 +358,14 @@ static int qmp_open(libxl__qmp_handler = *=0A int timeout)=0A {=0A int ret;=0A- int = flags =3D 0;=0A int i =3D 0;=0A =0A qmp->qmp_fd =3D socket(AF_UNIX,= SOCK_STREAM, 0);=0A if (qmp->qmp_fd < 0) {=0A return -1;=0A = }=0A- if ((flags =3D fcntl(qmp->qmp_fd, F_GETFL)) =3D=3D -1) {=0A- = flags =3D 0;=0A- }=0A- if (fcntl(qmp->qmp_fd, F_SETFL, flags | = O_NONBLOCK) =3D=3D -1) {=0A- return -1;=0A- }=0A+ ret =3D = libxl_fd_set_nonblock(qmp->ctx, qmp->qmp_fd, 1);=0A+ if (ret) return = -1;=0A ret =3D libxl_fd_set_cloexec(qmp->ctx, qmp->qmp_fd, 1);=0A = if (ret) return -1;=0A =0A--- 2014-07-25.orig/tools/libxl/libxl_utils.c = 2014-07-25 10:41:10.000000000 +0200=0A+++ 2014-07-25/tools/libxl/libxl_util= s.c 2014-07-28 09:24:38.000000000 +0200=0A@@ -1047,11 +1047,16 @@ int = libxl__random_bytes(libxl__gc *gc, u=0A int fd;=0A int ret;=0A = =0A- fd =3D open(dev, O_RDONLY | O_CLOEXEC);=0A+ fd =3D open(dev, = O_RDONLY);=0A if (fd < 0) {=0A LOGE(ERROR, "failed to open = \"%s\"", dev);=0A return ERROR_FAIL;=0A }=0A+ ret =3D = libxl_fd_set_cloexec(CTX, fd, 1);=0A+ if (ret) {=0A+ close(fd);= =0A+ return ERROR_FAIL;=0A+ }=0A =0A ret =3D libxl_read_exact= ly(CTX, fd, buf, len, dev, NULL);=0A =0A --=__PartF9CB72EC.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__PartF9CB72EC.1__=--