Module Name: src
Committed By: christos
Date: Fri Sep 25 19:08:33 UTC 2015
Modified Files:
src/external/bsd/libproc/dist: proc_util.c
src/external/bsd/libproc/dist/tests: proc_test.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/external/bsd/libproc/dist/proc_util.c
cvs rdiff -u -r1.4 -r1.5 src/external/bsd/libproc/dist/tests/proc_test.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/external/bsd/libproc/dist/proc_util.c
diff -u src/external/bsd/libproc/dist/proc_util.c:1.2 src/external/bsd/libproc/dist/proc_util.c:1.3
--- src/external/bsd/libproc/dist/proc_util.c:1.2 Thu Sep 24 10:12:48 2015
+++ src/external/bsd/libproc/dist/proc_util.c Fri Sep 25 15:08:32 2015
@@ -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, in
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
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 *ph
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
Index: src/external/bsd/libproc/dist/tests/proc_test.c
diff -u src/external/bsd/libproc/dist/tests/proc_test.c:1.4 src/external/bsd/libproc/dist/tests/proc_test.c:1.5
--- src/external/bsd/libproc/dist/tests/proc_test.c:1.4 Fri Sep 25 12:07:32 2015
+++ src/external/bsd/libproc/dist/tests/proc_test.c Fri Sep 25 15:08:33 2015
@@ -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);
}