Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/bsd/libproc/dist Fix the broken detach code and mak...
details: https://anonhg.NetBSD.org/src/rev/d842618ca3b3
branches: trunk
changeset: 810856:d842618ca3b3
user: christos <christos%NetBSD.org@localhost>
date: Fri Sep 25 19:08:32 2015 +0000
description:
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.
diffstat:
external/bsd/libproc/dist/proc_util.c | 42 +++++++++++++++++++---------
external/bsd/libproc/dist/tests/proc_test.c | 10 +++---
2 files changed, 33 insertions(+), 19 deletions(-)
diffs (126 lines):
diff -r b46fe81c46e8 -r d842618ca3b3 external/bsd/libproc/dist/proc_util.c
--- a/external/bsd/libproc/dist/proc_util.c Fri Sep 25 16:07:32 2015 +0000
+++ b/external/bsd/libproc/dist/proc_util.c Fri Sep 25 19:08:32 2015 +0000
@@ -65,7 +65,7 @@
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 @@
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 @@
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 @@
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
diff -r b46fe81c46e8 -r d842618ca3b3 external/bsd/libproc/dist/tests/proc_test.c
--- a/external/bsd/libproc/dist/tests/proc_test.c Fri Sep 25 16:07:32 2015 +0000
+++ b/external/bsd/libproc/dist/tests/proc_test.c Fri Sep 25 19:08:32 2015 +0000
@@ -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 @@
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 @@
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_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 @@
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);
}
Home |
Main Index |
Thread Index |
Old Index