diff options
author | Mark Johnston <markj@FreeBSD.org> | 2016-06-24 20:21:32 +0000 |
---|---|---|
committer | Mark Johnston <markj@FreeBSD.org> | 2016-06-24 20:21:32 +0000 |
commit | 0367ff567c974ce6286e304bd676555204c7640f (patch) | |
tree | 3ca0d2a50c3cebd344e5b58baf5217223b3d87f8 /usr.bin/gcore | |
parent | 8095b3c249d87e3f0f5fdb1b2486295f77c4c460 (diff) | |
download | src-test2-0367ff567c974ce6286e304bd676555204c7640f.tar.gz src-test2-0367ff567c974ce6286e304bd676555204c7640f.zip |
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 <sraju@isilon.com>
Reviewed by: bdrewery
Approved by: re (gjb, kib)
MFC after: 2 weeks
Sponsored by: EMC / Isilon Storage Division
Notes
Notes:
svn path=/head/; revision=302179
Diffstat (limited to 'usr.bin/gcore')
-rw-r--r-- | usr.bin/gcore/elfcore.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/usr.bin/gcore/elfcore.c b/usr.bin/gcore/elfcore.c index c96e3ae81232..98c90243375c 100644 --- a/usr.bin/gcore/elfcore.c +++ b/usr.bin/gcore/elfcore.c @@ -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, char *binfile __unused) 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, pid_t pid) 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. */ |