[1/2] gdbstub: Use qemu_set_cloexec()

Message ID 20180514173044.5025-2-peter.maydell@linaro.org
State Superseded
Headers show
Series
  • gdbstub: fix a couple of coverity nits
Related show

Commit Message

Peter Maydell May 14, 2018, 5:30 p.m.
Use the utility routine qemu_set_cloexec() rather than
manually calling fcntl(). This lets us drop the #ifndef _WIN32
guards and also means Coverity doesn't complain that we're
ignoring the fcntl error return (CID 1005665, CID 1005667).

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

---
 gdbstub.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

-- 
2.17.0

Comments

Philippe Mathieu-Daudé May 14, 2018, 6:57 p.m. | #1
On 05/14/2018 02:30 PM, Peter Maydell wrote:
> Use the utility routine qemu_set_cloexec() rather than

> manually calling fcntl(). This lets us drop the #ifndef _WIN32

> guards and also means Coverity doesn't complain that we're

> ignoring the fcntl error return (CID 1005665, CID 1005667).

> 

> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>


Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


> ---

>  gdbstub.c | 8 ++------

>  1 file changed, 2 insertions(+), 6 deletions(-)

> 

> diff --git a/gdbstub.c b/gdbstub.c

> index 3c3807358c..cc7626c790 100644

> --- a/gdbstub.c

> +++ b/gdbstub.c

> @@ -1818,9 +1818,7 @@ static void gdb_accept(void)

>              perror("accept");

>              return;

>          } else if (fd >= 0) {

> -#ifndef _WIN32

> -            fcntl(fd, F_SETFD, FD_CLOEXEC);

> -#endif

> +            qemu_set_cloexec(fd);

>              break;

>          }

>      }

> @@ -1847,9 +1845,7 @@ static int gdbserver_open(int port)

>          perror("socket");

>          return -1;

>      }

> -#ifndef _WIN32

> -    fcntl(fd, F_SETFD, FD_CLOEXEC);

> -#endif

> +    qemu_set_cloexec(fd);

>  

>      socket_set_fast_reuse(fd);

>  

>
Thomas Huth May 15, 2018, 5:22 a.m. | #2
On 14.05.2018 19:30, Peter Maydell wrote:
> Use the utility routine qemu_set_cloexec() rather than

> manually calling fcntl(). This lets us drop the #ifndef _WIN32

> guards and also means Coverity doesn't complain that we're

> ignoring the fcntl error return (CID 1005665, CID 1005667).

> 

> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

> ---

>  gdbstub.c | 8 ++------

>  1 file changed, 2 insertions(+), 6 deletions(-)


Reviewed-by: Thomas Huth <thuth@redhat.com>

Patch

diff --git a/gdbstub.c b/gdbstub.c
index 3c3807358c..cc7626c790 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1818,9 +1818,7 @@  static void gdb_accept(void)
             perror("accept");
             return;
         } else if (fd >= 0) {
-#ifndef _WIN32
-            fcntl(fd, F_SETFD, FD_CLOEXEC);
-#endif
+            qemu_set_cloexec(fd);
             break;
         }
     }
@@ -1847,9 +1845,7 @@  static int gdbserver_open(int port)
         perror("socket");
         return -1;
     }
-#ifndef _WIN32
-    fcntl(fd, F_SETFD, FD_CLOEXEC);
-#endif
+    qemu_set_cloexec(fd);
 
     socket_set_fast_reuse(fd);