2009-12-29 22:34:06 +01:00
|
|
|
/* dumpcore - create core file of running process */
|
2006-08-15 17:59:38 +02:00
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <minix/config.h>
|
|
|
|
#include <minix/type.h>
|
2009-12-29 22:34:06 +01:00
|
|
|
#include <minix/ipc.h>
|
2006-08-15 17:59:38 +02:00
|
|
|
#include <minix/const.h>
|
|
|
|
#include <sys/ptrace.h>
|
2009-12-29 22:34:06 +01:00
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <signal.h>
|
2006-08-15 17:59:38 +02:00
|
|
|
#include <timers.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2010-03-09 10:41:14 +01:00
|
|
|
#include <machine/archtypes.h>
|
2010-05-12 18:28:54 +02:00
|
|
|
#include "kernel/proc.h"
|
2006-08-15 17:59:38 +02:00
|
|
|
|
2009-12-29 22:34:06 +01:00
|
|
|
#define CLICK_WORDS (CLICK_SIZE / sizeof(unsigned long))
|
2006-08-15 17:59:38 +02:00
|
|
|
|
2009-12-29 22:34:06 +01:00
|
|
|
int main(int argc, char *argv[])
|
2006-08-15 17:59:38 +02:00
|
|
|
{
|
2009-12-29 22:34:06 +01:00
|
|
|
pid_t pid;
|
|
|
|
int r, status;
|
|
|
|
|
2006-08-15 17:59:38 +02:00
|
|
|
if(argc != 2) {
|
2009-12-29 22:34:06 +01:00
|
|
|
printf("usage: %s <pid>\n", argv[0]);
|
2006-08-15 17:59:38 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-12-29 22:34:06 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-06-15 02:38:00 +02:00
|
|
|
if (ptrace(T_DUMPCORE, pid, 0, 0) != 0) {
|
|
|
|
fprintf(stderr, "warning, dumpcore failed (%s)\n",
|
|
|
|
strerror(errno));
|
|
|
|
}
|
2009-12-29 22:34:06 +01:00
|
|
|
|
|
|
|
if (ptrace(T_DETACH, pid, 0, 0)) {
|
|
|
|
fprintf(stderr, "warning, detaching failed (%s)\n",
|
|
|
|
strerror(errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|