diff mbox

[v2,3/3] xen: call qemu_set_cloexec instead of fcntl

Message ID 1494356693-13190-3-git-send-email-sstabellini@kernel.org (mailing list archive)
State New, archived
Headers show

Commit Message

Stefano Stabellini May 9, 2017, 7:04 p.m. UTC
Use the common utility function, which contains checks on return values,
instead of manually calling fcntl.

CID: 1374831

Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
CC: anthony.perard@citrix.com
CC: groug@kaod.org
CC: aneesh.kumar@linux.vnet.ibm.com
CC: Eric Blake <eblake@redhat.com>
---
 hw/9pfs/xen-9p-backend.c | 2 +-
 hw/xen/xen_backend.c     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Eric Blake May 9, 2017, 7:21 p.m. UTC | #1
On 05/09/2017 02:04 PM, Stefano Stabellini wrote:
> Use the common utility function, which contains checks on return values,
> instead of manually calling fcntl.
> 
> CID: 1374831
> 
> Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
> CC: anthony.perard@citrix.com
> CC: groug@kaod.org
> CC: aneesh.kumar@linux.vnet.ibm.com
> CC: Eric Blake <eblake@redhat.com>
> ---
>  hw/9pfs/xen-9p-backend.c | 2 +-
>  hw/xen/xen_backend.c     | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>
Greg Kurz May 9, 2017, 8:54 p.m. UTC | #2
On Tue,  9 May 2017 12:04:53 -0700
Stefano Stabellini <sstabellini@kernel.org> wrote:

> Use the common utility function, which contains checks on return values,

... and first calls F_GETFD as recommended by POSIX.1-2001.

http://pubs.opengroup.org/onlinepubs/009695399/functions/fcntl.html

"The arg values to F_GETFD, F_SETFD, F_GETFL, and F_SETFL all represent
flag values to allow for future growth. Applications using these functions
should do a read-modify-write operation on them, rather than assuming that
only the values defined by this volume of IEEE Std 1003.1-2001 are valid.
It is a common error to forget this, particularly in the case of F_SETFD."

> instead of manually calling fcntl.
> 
> CID: 1374831
> 
> Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
> CC: anthony.perard@citrix.com
> CC: groug@kaod.org
> CC: aneesh.kumar@linux.vnet.ibm.com
> CC: Eric Blake <eblake@redhat.com>
> ---
>  hw/9pfs/xen-9p-backend.c | 2 +-
>  hw/xen/xen_backend.c     | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 

Anyway,

Reviewed-by: Greg Kurz <groug@kaod.org>

> diff --git a/hw/9pfs/xen-9p-backend.c b/hw/9pfs/xen-9p-backend.c
> index a1fdede..5df97c9 100644
> --- a/hw/9pfs/xen-9p-backend.c
> +++ b/hw/9pfs/xen-9p-backend.c
> @@ -380,7 +380,7 @@ static int xen_9pfs_connect(struct XenDevice *xendev)
>          if (xen_9pdev->rings[i].evtchndev == NULL) {
>              goto out;
>          }
> -        fcntl(xenevtchn_fd(xen_9pdev->rings[i].evtchndev), F_SETFD,
> FD_CLOEXEC);
> +        qemu_set_cloexec(xenevtchn_fd(xen_9pdev->rings[i].evtchndev));
>          xen_9pdev->rings[i].local_port = xenevtchn_bind_interdomain
>                                              (xen_9pdev->rings[i].evtchndev,
>                                               xendev->dom,
> diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c
> index c85f163..2cac47d 100644
> --- a/hw/xen/xen_backend.c
> +++ b/hw/xen/xen_backend.c
> @@ -147,7 +147,7 @@ static struct XenDevice *xen_be_get_xendev(const char
> *type, int dom, int dev, qdev_unplug(DEVICE(xendev), NULL);
>          return NULL;
>      }
> -    fcntl(xenevtchn_fd(xendev->evtchndev), F_SETFD, FD_CLOEXEC);
> +    qemu_set_cloexec(xenevtchn_fd(xendev->evtchndev));
>  
>      if (ops->flags & DEVOPS_FLAG_NEED_GNTDEV) {
>          xendev->gnttabdev = xengnttab_open(NULL, 0);
diff mbox

Patch

diff --git a/hw/9pfs/xen-9p-backend.c b/hw/9pfs/xen-9p-backend.c
index a1fdede..5df97c9 100644
--- a/hw/9pfs/xen-9p-backend.c
+++ b/hw/9pfs/xen-9p-backend.c
@@ -380,7 +380,7 @@  static int xen_9pfs_connect(struct XenDevice *xendev)
         if (xen_9pdev->rings[i].evtchndev == NULL) {
             goto out;
         }
-        fcntl(xenevtchn_fd(xen_9pdev->rings[i].evtchndev), F_SETFD, FD_CLOEXEC);
+        qemu_set_cloexec(xenevtchn_fd(xen_9pdev->rings[i].evtchndev));
         xen_9pdev->rings[i].local_port = xenevtchn_bind_interdomain
                                             (xen_9pdev->rings[i].evtchndev,
                                              xendev->dom,
diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c
index c85f163..2cac47d 100644
--- a/hw/xen/xen_backend.c
+++ b/hw/xen/xen_backend.c
@@ -147,7 +147,7 @@  static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
         qdev_unplug(DEVICE(xendev), NULL);
         return NULL;
     }
-    fcntl(xenevtchn_fd(xendev->evtchndev), F_SETFD, FD_CLOEXEC);
+    qemu_set_cloexec(xenevtchn_fd(xendev->evtchndev));
 
     if (ops->flags & DEVOPS_FLAG_NEED_GNTDEV) {
         xendev->gnttabdev = xengnttab_open(NULL, 0);