From: Ian Jackson Subject: Re: [PATCH] libxl: use libxl_fd_set_{cloexec, nonblock} helpers Date: Fri, 25 Jul 2014 18:07:35 +0100 Message-ID: <21458.36567.506481.423244@mariner.uk.xensource.com> References: <53D28D9F020000780002615D@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XAiy3-0004d4-Gv for xen-devel@lists.xenproject.org; Fri, 25 Jul 2014 17:07:39 +0000 In-Reply-To: <53D28D9F020000780002615D@mail.emea.novell.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: Jan Beulich Cc: Ian Campbell , xen-devel , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org Jan Beulich writes ("[PATCH] 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. I think most of libxl should probably be using libxl__carefd* not setting cloexec. This is necessary whenever we need cloexec for correctness rather than just out of tidiness. (Search for carefd in libxl_internal.h.) > Signed-off-by: Jan Beulich > > --- 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); ... > + 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"); You do not need to log when libxl_fd_set_nonblock fails - it logs already. > --- 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) ... > qmp->qmp_fd = socket(AF_UNIX, SOCK_STREAM, 0); ... > + ret = libxl_fd_set_nonblock(qmp->ctx, qmp->qmp_fd, 1); > + if (ret) return -1; This change is correct. > ret = libxl_fd_set_cloexec(qmp->ctx, qmp->qmp_fd, 1); > if (ret) return -1; But this (which you haven't touched) needs to be done with libxl__carefd* instead. (Your patch is not unacceptable due to you not making this change, on the basis that we should accept improvements even if they don't leave the code perfect.) > --- a/tools/libxl/libxl_utils.c > +++ b/tools/libxl/libxl_utils.c > @@ -1047,11 +1047,17 @@ int libxl__random_bytes(libxl__gc *gc, u ... > - fd = open(dev, O_RDONLY | O_CLOEXEC); > + fd = open(dev, O_RDONLY); Firstly, I don't understand why we care about cloexec on this fd, but it's harmless to do so. > + 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; > + } Again, no need to log. Thanks, Ian.