Retire ptrace(T_DUMPCORE), dumpcore(1), gcore(1)

The T_DUMPCORE implementation was not only broken - it would currently
produce a coredump of the tracer process rather than the traced
process - but also deeply flawed, and fixing it would require serious
alteration of PM's internal state machine. It should be possible to
implement the same functionality in userland, and that is now the
suggested way forward. For now, also remove the (identical) utilities
using T_DUMPCORE: dumpcore(1) and gcore(1).

Change-Id: I1d51be19c739362b8a5833de949b76382a1edbcc
This commit is contained in:
David van Moolenbroek
2014-02-18 11:25:03 +01:00
committed by sambuc
parent f707937192
commit 4f6b382c41
14 changed files with 11 additions and 218 deletions
+2 -2
View File
@@ -7,10 +7,10 @@ SUBDIR= add_route arp ash at backup btrace \
chmod chown ci cleantmp cmp co \
compress cp crc cron crontab \
dd decomp16 DESCRIBE devmand devsize dhcpd \
dhrystone diff diskctl dumpcore \
dhrystone diff diskctl \
eject factor fbdctl \
find fix format fortune fsck.mfs \
gcore gcov-pull getty grep host \
gcov-pull getty grep host \
hostaddr ifconfig ifdef \
intr ipcrm ipcs irdpd isoread last \
less loadkeys loadramdisk logger look lp \
-5
View File
@@ -1,5 +0,0 @@
PROG= dumpcore
CPPFLAGS+= -I${NETBSDSRCDIR}
MAN=
.include <bsd.prog.mk>
-71
View File
@@ -1,71 +0,0 @@
/* dumpcore - create core file of running process */
#include <fcntl.h>
#include <unistd.h>
#include <minix/config.h>
#include <minix/type.h>
#include <minix/ipc.h>
#include <minix/const.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <signal.h>
#include <timers.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <machine/archtypes.h>
#include "kernel/proc.h"
#define CLICK_WORDS (CLICK_SIZE / sizeof(unsigned long))
int main(int argc, char *argv[])
{
pid_t pid;
int r, status;
if(argc != 2) {
printf("usage: %s <pid>\n", argv[0]);
return 1;
}
pid = atoi(argv[1]);
if (ptrace(T_ATTACH, pid, 0, 0) != 0) {
perror("ptrace(T_ATTACH)");
return 1;
}
if (waitpid(pid, &status, 0) != pid) {
perror("waitpid");
return 1;
}
while (WIFSTOPPED(status) && WSTOPSIG(status) != SIGSTOP) {
/* whatever happens here is fine */
ptrace(T_RESUME, pid, 0, WSTOPSIG(status));
if (waitpid(pid, &status, 0) != pid) {
perror("waitpid");
return 1;
}
}
if (!WIFSTOPPED(status)) {
fprintf(stderr, "process died while attaching\n");
return 1;
}
if (ptrace(T_DUMPCORE, pid, 0, 0) != 0) {
fprintf(stderr, "warning, dumpcore failed (%s)\n",
strerror(errno));
}
if (ptrace(T_DETACH, pid, 0, 0)) {
fprintf(stderr, "warning, detaching failed (%s)\n",
strerror(errno));
}
return r;
}
-4
View File
@@ -1,4 +0,0 @@
PROG= gcore
MAN=
.include <bsd.prog.mk>
-58
View File
@@ -1,58 +0,0 @@
/* gcore - create core file of running process */
#include <sys/types.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <signal.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
pid_t pid;
int status;
if(argc != 2) {
printf("usage: %s <pid>\n", argv[0]);
return 1;
}
pid = atoi(argv[1]);
if (ptrace(T_ATTACH, pid, 0, 0) != 0) {
perror("ptrace(T_ATTACH)");
return 1;
}
if (waitpid(pid, &status, 0) != pid) {
perror("waitpid");
return 1;
}
while (WIFSTOPPED(status) && WSTOPSIG(status) != SIGSTOP) {
/* whatever happens here is fine */
ptrace(T_RESUME, pid, 0, WSTOPSIG(status));
if (waitpid(pid, &status, 0) != pid) {
perror("waitpid");
return 1;
}
}
if (!WIFSTOPPED(status)) {
fprintf(stderr, "process died while attaching\n");
return 1;
}
if (ptrace(T_DUMPCORE, pid, 0, 0)) {
fprintf(stderr, "warning, dumpcore failed (%s)\n", strerror(errno));
}
if (ptrace(T_DETACH, pid, 0, 0)) {
fprintf(stderr, "warning, detaching failed (%s)\n", strerror(errno));
}
return 0;
}