Fix the broken detach code and make the proc tests detach instead
of continue, so that we don't get kernel diagnostic messages about detaching traced processes.
This commit is contained in:
parent
9a58287b9b
commit
800ae96385
42
external/bsd/libproc/dist/proc_util.c
vendored
42
external/bsd/libproc/dist/proc_util.c
vendored
@ -65,7 +65,7 @@ proc_continue(struct proc_handle *phdl)
|
||||
|
||||
if (phdl->status == PS_STOP && WSTOPSIG(phdl->wstat) != SIGTRAP)
|
||||
pending = WSTOPSIG(phdl->wstat);
|
||||
if (ptrace(PT_CONTINUE, phdl->pid, (caddr_t)(uintptr_t)1, pending) != 0)
|
||||
if (ptrace(PT_CONTINUE, phdl->pid, (void *)(uintptr_t)1, pending) != 0)
|
||||
return (-1);
|
||||
|
||||
phdl->status = PS_RUN;
|
||||
@ -79,22 +79,36 @@ proc_detach(struct proc_handle *phdl, int reason)
|
||||
int status;
|
||||
|
||||
if (phdl == NULL)
|
||||
return (EINVAL);
|
||||
return EINVAL;
|
||||
if (reason == PRELEASE_KILL) {
|
||||
ptrace(PT_DETACH, phdl->pid, (void *)(uintptr_t)1, 0);
|
||||
kill(phdl->pid, SIGKILL);
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
if (ptrace(PT_DETACH, phdl->pid, 0, 0) != 0 && errno == ESRCH)
|
||||
return (0);
|
||||
if (errno == EBUSY) {
|
||||
kill(phdl->pid, SIGSTOP);
|
||||
waitpid(phdl->pid, &status, WUNTRACED);
|
||||
ptrace(PT_DETACH, phdl->pid, 0, 0);
|
||||
kill(phdl->pid, SIGCONT);
|
||||
return (0);
|
||||
if (ptrace(PT_DETACH, phdl->pid, (void *)(uintptr_t)1, 0) == 0)
|
||||
return 0;
|
||||
|
||||
switch (errno) {
|
||||
case ESRCH:
|
||||
return 0;
|
||||
case EBUSY:
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (0);
|
||||
if (kill(phdl->pid, SIGSTOP) == -1)
|
||||
return -1;
|
||||
|
||||
waitpid(phdl->pid, &status, WUNTRACED);
|
||||
|
||||
if (ptrace(PT_DETACH, phdl->pid, (void *)(uintptr_t)1, 0) == -1)
|
||||
return -1;
|
||||
|
||||
if (kill(phdl->pid, SIGCONT) == -1)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
@ -191,7 +205,7 @@ proc_read(struct proc_handle *phdl, void *buf, size_t size, size_t addr)
|
||||
piod.piod_addr = (void *)buf;
|
||||
piod.piod_offs = (void *)addr;
|
||||
|
||||
if (ptrace(PT_IO, phdl->pid, (caddr_t)&piod, 0) < 0)
|
||||
if (ptrace(PT_IO, phdl->pid, (void *)&piod, 0) < 0)
|
||||
return (-1);
|
||||
return (piod.piod_len);
|
||||
}
|
||||
@ -205,7 +219,7 @@ proc_getlwpstatus(struct proc_handle *phdl)
|
||||
|
||||
if (phdl == NULL)
|
||||
return (NULL);
|
||||
if (ptrace(PT_LWPINFO, phdl->pid, (caddr_t)&lwpinfo,
|
||||
if (ptrace(PT_LWPINFO, phdl->pid, (void *)&lwpinfo,
|
||||
sizeof(lwpinfo)) < 0)
|
||||
return (NULL);
|
||||
#ifdef PL_FLAG_SI
|
||||
|
10
external/bsd/libproc/dist/tests/proc_test.c
vendored
10
external/bsd/libproc/dist/tests/proc_test.c
vendored
@ -28,7 +28,7 @@
|
||||
#ifdef __FBSDID
|
||||
__FBSDID("$FreeBSD: head/lib/libproc/tests/proc_test.c 286863 2015-08-17 23:19:36Z emaste $");
|
||||
#endif
|
||||
__RCSID("$NetBSD: proc_test.c,v 1.4 2015/09/25 16:07:32 christos Exp $");
|
||||
__RCSID("$NetBSD: proc_test.c,v 1.5 2015/09/25 19:08:33 christos Exp $");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
@ -207,7 +207,7 @@ ATF_TC_BODY(map_alias_obj2map, tc)
|
||||
aout_object);
|
||||
ATF_CHECK_EQ(strcmp(map1->pr_mapname, map2->pr_mapname), 0);
|
||||
|
||||
ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");
|
||||
ATF_CHECK_EQ_MSG(proc_detach(phdl, PRELEASE_HANG), 0, "failed to detach");
|
||||
|
||||
proc_free(phdl);
|
||||
}
|
||||
@ -239,7 +239,7 @@ ATF_TC_BODY(map_alias_name2map, tc)
|
||||
aout_object);
|
||||
ATF_CHECK_EQ(strcmp(map1->pr_mapname, map2->pr_mapname), 0);
|
||||
|
||||
ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");
|
||||
ATF_CHECK_EQ_MSG(proc_detach(phdl, PRELEASE_HANG), 0, "failed to detach");
|
||||
|
||||
proc_free(phdl);
|
||||
}
|
||||
@ -278,7 +278,7 @@ ATF_TC_BODY(map_alias_name2sym, tc)
|
||||
ATF_CHECK_EQ(memcmp(&sym1, &sym2, sizeof(sym1)), 0);
|
||||
ATF_CHECK_EQ(si1.prs_id, si2.prs_id);
|
||||
|
||||
ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");
|
||||
ATF_CHECK_EQ_MSG(proc_detach(phdl, PRELEASE_HANG), 0, "failed to detach");
|
||||
|
||||
proc_free(phdl);
|
||||
}
|
||||
@ -319,7 +319,7 @@ ATF_TC_BODY(symbol_lookup, tc)
|
||||
verify_bkpt(phdl, &main_sym, "main", target_prog_file);
|
||||
remove_bkpt(phdl, (uintptr_t)main_sym.st_value, &saved);
|
||||
|
||||
ATF_CHECK_EQ_MSG(proc_continue(phdl), 0, "failed to resume execution");
|
||||
ATF_CHECK_EQ_MSG(proc_detach(phdl, PRELEASE_HANG), 0, "failed to detach");
|
||||
|
||||
proc_free(phdl);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user