From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2062 invoked by alias); 29 Aug 2013 17:22:19 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 2051 invoked by uid 89); 29 Aug 2013 17:22:19 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 29 Aug 2013 17:22:19 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.5 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r7THMGtq011974 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 29 Aug 2013 13:22:16 -0400 Received: from barimba (ovpn-113-142.phx2.redhat.com [10.3.113.142]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r7THMEo2026381 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 29 Aug 2013 13:22:15 -0400 From: Tom Tromey To: Pedro Alves Cc: Jan Kratochvil , gdb-patches@sourceware.org Subject: Re: [patch gdbserver 7.6.1 only] Fix fd leak regression References: <20130829111053.GA25662@host2.jankratochvil.net> <521F3B71.1010007@redhat.com> <20130829130359.GA31063@host2.jankratochvil.net> <521F5804.1080604@redhat.com> <87a9k0sgpf.fsf@fleche.redhat.com> <521F5FD1.8020107@redhat.com> <871u5csfrv.fsf@fleche.redhat.com> Date: Thu, 29 Aug 2013 17:22:00 -0000 In-Reply-To: <871u5csfrv.fsf@fleche.redhat.com> (Tom Tromey's message of "Thu, 29 Aug 2013 09:00:52 -0600") Message-ID: <87li3kqunt.fsf@fleche.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2013-08/txt/msg00882.txt.bz2 Tom> Yeah, I meant the other filestuff.h code, like gdb_socket_cloexec and Tom> gdb_pipe_cloexec. Like this. I haven't tested it using native-gdbserver yet. Tom commit d190e7c809a8dba4768cb67b9c46610e8e8e1d07 Author: Tom Tromey Date: Thu Aug 29 10:13:50 2013 -0600 use _cloexec functions in gdbserver This changes gdbserver to use the various _cloexec functions defined in common/filestuff.c. Two wrinkles here: first, I couldn't compile the NTO and SPU changes; second, the in process agent can't use gdb_socket_cloexec -- too bad, since the setting would be useful there. * hostio.c (handle_open): Use gdb_open_cloexec. * linux-low.c (elf_64_file_p, linux_create_inferior) (linux_read_memory, linux_read_auxv): Use gdb_open_cloexec. (linux_async): Use gdb_pipe_cloexec. (linux_qxfer_spu, get_phdr_phnum_from_proc_auxv): Use gdb_open_cloexec. * nto-low.c (do_attach): Use gdb_open_cloexec. * remote-utils.c (remote_prepare): Use gdb_socket_cloexec. (remote_open): Use gdb_open_cloexec. * spu-low.c (spu_proc_xfer_spu): Use gdb_open_cloexec. * tracepointc. (gdb_socket_cloexec): Define in IPA mode. (init_named_socket): Use gdb_socket_cloexec. diff --git a/gdb/gdbserver/hostio.c b/gdb/gdbserver/hostio.c index a74c2f8..edef7bc 100644 --- a/gdb/gdbserver/hostio.c +++ b/gdb/gdbserver/hostio.c @@ -20,6 +20,7 @@ #include "server.h" #include "gdb/fileio.h" +#include "filestuff.h" #include #include @@ -295,7 +296,7 @@ handle_open (char *own_buf) /* We do not need to convert MODE, since the fileio protocol uses the standard values. */ - fd = open (filename, flags, mode); + fd = gdb_open_cloexec (filename, flags, mode); if (fd == -1) { diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index 7db1fc8..3fa3bf1 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -315,7 +315,7 @@ elf_64_file_p (const char *file, unsigned int *machine) Elf64_Ehdr header; int fd; - fd = open (file, O_RDONLY); + fd = gdb_open_cloexec (file, O_RDONLY, 0); if (fd < 0) return -1; @@ -596,7 +596,7 @@ linux_create_inferior (char *program, char **allargs) if (remote_connection_is_stdio ()) { close (0); - open ("/dev/null", O_RDONLY); + gdb_open_cloexec ("/dev/null", O_RDONLY, 0); dup2 (2, 1); if (write (2, "stdin/stdout redirected\n", sizeof ("stdin/stdout redirected\n") - 1) < 0) @@ -4426,7 +4426,7 @@ linux_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len) /* We could keep this file open and cache it - possibly one per thread. That requires some juggling, but is even faster. */ sprintf (filename, "/proc/%d/mem", pid); - fd = open (filename, O_RDONLY | O_LARGEFILE); + fd = gdb_open_cloexec (filename, O_RDONLY | O_LARGEFILE, 0); if (fd == -1) goto no_proc; @@ -4626,7 +4626,7 @@ linux_read_auxv (CORE_ADDR offset, unsigned char *myaddr, unsigned int len) xsnprintf (filename, sizeof filename, "/proc/%d/auxv", pid); - fd = open (filename, O_RDONLY); + fd = gdb_open_cloexec (filename, O_RDONLY, 0); if (fd < 0) return -1; @@ -4859,7 +4859,7 @@ linux_async (int enable) if (enable) { - if (pipe (linux_event_pipe) == -1) + if (gdb_pipe_cloexec (linux_event_pipe) == -1) fatal ("creating event pipe failed."); fcntl (linux_event_pipe[0], F_SETFL, O_NONBLOCK); @@ -5000,7 +5000,7 @@ linux_qxfer_spu (const char *annex, unsigned char *readbuf, } sprintf (buf, "/proc/%ld/fd/%s", pid, annex); - fd = open (buf, writebuf? O_WRONLY : O_RDONLY); + fd = gdb_open_cloexec (buf, writebuf? O_WRONLY : O_RDONLY, 0); if (fd <= 0) return -1; @@ -5224,7 +5224,7 @@ get_phdr_phnum_from_proc_auxv (const int pid, const int is_elf64, xsnprintf (filename, sizeof filename, "/proc/%d/auxv", pid); - fd = open (filename, O_RDONLY); + fd = gdb_open_cloexec (filename, O_RDONLY, 0); if (fd < 0) return 1; diff --git a/gdb/gdbserver/nto-low.c b/gdb/gdbserver/nto-low.c index 3670133..91fffbc 100644 --- a/gdb/gdbserver/nto-low.c +++ b/gdb/gdbserver/nto-low.c @@ -21,6 +21,7 @@ #include "server.h" #include "gdbthread.h" #include "nto-low.h" +#include "filestuff.h" #include #include @@ -178,7 +179,8 @@ do_attach (pid_t pid) init_nto_inferior (&nto_inferior); } xsnprintf (nto_inferior.nto_procfs_path, PATH_MAX - 1, "/proc/%d/as", pid); - nto_inferior.ctl_fd = open (nto_inferior.nto_procfs_path, O_RDWR); + nto_inferior.ctl_fd = gdb_open_cloexec (nto_inferior.nto_procfs_path, + O_RDWR, 0); if (nto_inferior.ctl_fd == -1) { TRACE ("Failed to open %s\n", nto_inferior.nto_procfs_path); diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c index 5cd6fa1..25f5302 100644 --- a/gdb/gdbserver/remote-utils.c +++ b/gdb/gdbserver/remote-utils.c @@ -68,6 +68,8 @@ #include #endif /* __QNX__ */ +#include "filestuff.h" + #ifndef HAVE_SOCKLEN_T typedef int socklen_t; #endif @@ -262,7 +264,7 @@ remote_prepare (char *name) } #endif - listen_desc = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP); + listen_desc = gdb_socket_cloexec (PF_INET, SOCK_STREAM, IPPROTO_TCP); if (listen_desc == -1) perror_with_name ("Can't open socket"); @@ -316,7 +318,7 @@ remote_open (char *name) if (stat (name, &statbuf) == 0 && (S_ISCHR (statbuf.st_mode) || S_ISFIFO (statbuf.st_mode))) - remote_desc = open (name, O_RDWR); + remote_desc = gdb_open_cloexec (name, O_RDWR, 0); else { errno = EINVAL; diff --git a/gdb/gdbserver/spu-low.c b/gdb/gdbserver/spu-low.c index e604b9f..63a2efc 100644 --- a/gdb/gdbserver/spu-low.c +++ b/gdb/gdbserver/spu-low.c @@ -239,7 +239,7 @@ spu_proc_xfer_spu (const char *annex, unsigned char *readbuf, return 0; sprintf (buf, "/proc/%ld/fd/%s", ptid_get_lwp (current_ptid), annex); - fd = open (buf, writebuf? O_WRONLY : O_RDONLY); + fd = gdb_open_cloexec (buf, writebuf? O_WRONLY : O_RDONLY, 0); if (fd <= 0) return -1; diff --git a/gdb/gdbserver/tracepoint.c b/gdb/gdbserver/tracepoint.c index 5c0dec7..4c4a751 100644 --- a/gdb/gdbserver/tracepoint.c +++ b/gdb/gdbserver/tracepoint.c @@ -19,6 +19,7 @@ #include "server.h" #include "gdbthread.h" #include "agent.h" +#include "filestuff.h" #include #include @@ -147,6 +148,9 @@ trace_vdebug (const char *fmt, ...) # define ust_loaded gdb_agent_ust_loaded # define helper_thread_id gdb_agent_helper_thread_id # define cmd_buf gdb_agent_cmd_buf + +/* We don't want to use this one in IPA. */ +# define gdb_socket_cloexec socket #endif #ifndef IN_PROCESS_AGENT @@ -6787,7 +6791,7 @@ init_named_socket (const char *name) int result, fd; struct sockaddr_un addr; - result = fd = socket (PF_UNIX, SOCK_STREAM, 0); + result = fd = gdb_socket_cloexec (PF_UNIX, SOCK_STREAM, 0); if (result == -1) { warning ("socket creation failed: %s", strerror (errno));