diff options
author | markj <markj@FreeBSD.org> | 2016-07-20 00:53:21 +0000 |
---|---|---|
committer | markj <markj@FreeBSD.org> | 2016-07-20 00:53:21 +0000 |
commit | 67a09024ed0bf810c4a85dce2342f5efd7349a5f (patch) | |
tree | a77432aec5c61ea35e4548e791da007864aaf3c7 /usr.bin | |
parent | 8ce51e3bdd922bd3660b1fd58646e79b413fb835 (diff) | |
download | FreeBSD-src-67a09024ed0bf810c4a85dce2342f5efd7349a5f.zip FreeBSD-src-67a09024ed0bf810c4a85dce2342f5efd7349a5f.tar.gz |
MFC r302179:
gcore: Forward pending signals when detaching from the target.
Diffstat (limited to 'usr.bin')
-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 5303f66..ad7f052 100644 --- a/usr.bin/gcore/elfcore.c +++ b/usr.bin/gcore/elfcore.c @@ -123,6 +123,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) @@ -156,9 +157,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); + } } /* @@ -184,7 +194,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. */ |