[PATCH] ptrace debug
Cyrill Gorcunov
gorcunov at openvz.org
Tue Mar 26 13:08:50 EDT 2013
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
ptrace.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/ptrace.c b/ptrace.c
index 0140918..cdc9c38 100644
--- a/ptrace.c
+++ b/ptrace.c
@@ -36,6 +36,29 @@ int unseize_task(pid_t pid, int st)
return ptrace(PTRACE_DETACH, pid, NULL, NULL);
}
+static char *task_comm(pid_t pid)
+{
+ static char comm[32];
+ char path[64];
+ int fd;
+
+ snprintf(path, sizeof(path), "/proc/%d/comm", pid);
+
+ fd = open(path, O_RDONLY);
+ if (fd >= 0) {
+ size_t ret;
+
+ ret = read(fd, comm, sizeof(comm) - 1);
+ if (ret < 0)
+ ret = 1;
+ comm[ret - 1] = '\0';
+ close(fd);
+ return comm;
+ }
+
+ return NULL;
+}
+
/*
* This routine seizes task putting it into a special
* state where we can manipulate the task via ptrace
@@ -71,8 +94,8 @@ int seize_task(pid_t pid, pid_t ppid, pid_t *pgid, pid_t *sid)
if (ret < 0) {
if (ps.state != 'Z') {
- pr_err("Unseizeable non-zombie %d found, state %c\n",
- pid, ps.state);
+ pr_err("Unseizeable non-zombie %d (%s) found, state %c\n",
+ pid, task_comm(pid), ps.state);
return -1;
}
--
1.8.1.4
--4Ckj6UjgE2iN1+kY--
More information about the CRIU
mailing list