From owner-svn-src-all@freebsd.org Fri Jun 24 20:21:33 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6279BB809B8; Fri, 24 Jun 2016 20:21:33 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 327D912F6; Fri, 24 Jun 2016 20:21:33 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u5OKLWhp064114; Fri, 24 Jun 2016 20:21:32 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u5OKLWRG064113; Fri, 24 Jun 2016 20:21:32 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201606242021.u5OKLWRG064113@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Fri, 24 Jun 2016 20:21:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r302179 - head/usr.bin/gcore X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jun 2016 20:21:33 -0000 Author: markj Date: Fri Jun 24 20:21:32 2016 New Revision: 302179 URL: https://svnweb.freebsd.org/changeset/base/302179 Log: gcore: Forward pending signals when detaching from the target. Otherwise gcore's ptrace attach operation can race with delivery of a signal and cause it to be lost. In collaboration with: Suraj Raju Reviewed by: bdrewery Approved by: re (gjb, kib) MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division Modified: head/usr.bin/gcore/elfcore.c Modified: head/usr.bin/gcore/elfcore.c ============================================================================== --- head/usr.bin/gcore/elfcore.c Fri Jun 24 20:00:39 2016 (r302178) +++ head/usr.bin/gcore/elfcore.c Fri Jun 24 20:21:32 2016 (r302179) @@ -126,6 +126,7 @@ static vm_map_entry_t readmap(pid_t); static void *procstat_sysctl(void *, int, size_t, size_t *sizep); static pid_t g_pid; /* Pid being dumped, global for elf_detach */ +static int g_status; /* proc status after ptrace attach */ static int elf_ident(int efd, pid_t pid __unused, char *binfile __unused) @@ -159,9 +160,18 @@ elf_ident(int efd, pid_t pid __unused, c static void elf_detach(void) { + int sig; - if (g_pid != 0) - ptrace(PT_DETACH, g_pid, (caddr_t)1, 0); + if (g_pid != 0) { + /* + * Forward any pending signals. SIGSTOP is generated by ptrace + * itself, so ignore it. + */ + sig = WIFSTOPPED(g_status) ? WSTOPSIG(g_status) : 0; + if (sig == SIGSTOP) + sig = 0; + ptrace(PT_DETACH, g_pid, (caddr_t)1, sig); + } } /* @@ -187,7 +197,7 @@ elf_coredump(int efd __unused, int fd, p ptrace(PT_ATTACH, pid, NULL, 0); if (errno) err(1, "PT_ATTACH"); - if (waitpid(pid, NULL, 0) == -1) + if (waitpid(pid, &g_status, 0) == -1) err(1, "waitpid"); /* Get the program's memory map. */