This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[patch gdbserver 7.6.1 only] Fix fd leak regression
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Thu, 29 Aug 2013 13:10:53 +0200
- Subject: [patch gdbserver 7.6.1 only] Fix fd leak regression
- Authentication-results: sourceware.org; auth=none
Hi,
in
[commit without 7.6.1] [gdbserver patch] [7.6.1] Fix fd leak regression
https://sourceware.org/ml/gdb-patches/2013-08/msg00845.html
I wrote:
# Although without 7.6.1 - 7.6 does not yet have gdb/common/filestuff.[ch] and
# from various available solutions I think it is just OK to wait for 7.7.
As I found I would like even 7.6.x fixed I wrote this alternative patch.
No regressions on {x86_64,x86_64-m32,i686}-fedora21pre-linux-gnu and in
gdbserver mode.
Thanks,
Jan
gdb/gdbserver/
2013-08-29 Jan Kratochvil <jan.kratochvil@redhat.com>
PR server/15604
* linux-low.c
(linux_create_inferior) <pid == 0 && !remote_connection_is_stdio ()>:
Close LISTEN_DESC.
(lynx_create_inferior) <pid == 0 && !remote_connection_is_stdio ()>:
Close LISTEN_DESC.
* remote-utils.c (listen_desc): Remove static qualifier.
* server.h (listen_desc): New declaration.
* spu-low.c
(spu_create_inferior) <pid == 0 && !remote_connection_is_stdio ()>:
Close LISTEN_DESC.
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 523926d..38d1caa 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -668,6 +668,8 @@ linux_create_inferior (char *program, char **allargs)
/* Errors ignored. */;
}
}
+ else
+ close (listen_desc);
execv (program, allargs);
if (errno == ENOENT)
diff --git a/gdb/gdbserver/lynx-low.c b/gdb/gdbserver/lynx-low.c
index a5f3b6d..78ab6f4 100644
--- a/gdb/gdbserver/lynx-low.c
+++ b/gdb/gdbserver/lynx-low.c
@@ -218,6 +218,8 @@ lynx_create_inferior (char *program, char **allargs)
pgrp = getpid();
setpgid (0, pgrp);
ioctl (0, TIOCSPGRP, &pgrp);
+ if (!remote_connection_is_stdio ())
+ close (listen_desc);
lynx_ptrace (PTRACE_TRACEME, null_ptid, 0, 0, 0);
execv (program, allargs);
fprintf (stderr, "Cannot exec %s: %s.\n", program, strerror (errno));
diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c
index 42c6a54..0738309 100644
--- a/gdb/gdbserver/remote-utils.c
+++ b/gdb/gdbserver/remote-utils.c
@@ -109,7 +109,7 @@ struct ui_file *gdb_stdlog;
static int remote_is_stdio = 0;
static gdb_fildes_t remote_desc = INVALID_DESCRIPTOR;
-static gdb_fildes_t listen_desc = INVALID_DESCRIPTOR;
+gdb_fildes_t listen_desc = INVALID_DESCRIPTOR;
/* FIXME headerize? */
extern int using_threads;
diff --git a/gdb/gdbserver/server.h b/gdb/gdbserver/server.h
index 139cd49..e5dce4e 100644
--- a/gdb/gdbserver/server.h
+++ b/gdb/gdbserver/server.h
@@ -274,6 +274,7 @@ extern void hostio_last_error_from_errno (char *own_buf);
/* From remote-utils.c */
extern int remote_debug;
+extern gdb_fildes_t listen_desc;
extern int noack_mode;
extern int transport_is_reliable;
diff --git a/gdb/gdbserver/spu-low.c b/gdb/gdbserver/spu-low.c
index deaa115..07839ca 100644
--- a/gdb/gdbserver/spu-low.c
+++ b/gdb/gdbserver/spu-low.c
@@ -273,6 +273,8 @@ spu_create_inferior (char *program, char **allargs)
if (pid == 0)
{
+ if (!remote_connection_is_stdio ())
+ close (listen_desc);
ptrace (PTRACE_TRACEME, 0, 0, 0);
setpgid (0, 0);