aboutsummaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
authorPetr Machata <pmachata@redhat.com>2012-03-02 00:10:37 +0100
committerPetr Machata <pmachata@redhat.com>2012-04-19 01:12:50 +0200
commitc805c624d4cd23674bbc18f9d0f97c5d8dcdff7c (patch)
tree8560d40ada7f1e5fb5c7caa17696c1b2474f876b /sysdeps
parent29add4fdf852b10ddd22cac0d1390f6d01577bc2 (diff)
downloadltrace-c805c624d4cd23674bbc18f9d0f97c5d8dcdff7c.tar.gz
wait_for_proc may fail, and should simply waitpid instead of ptracing
- which means that we need to continue the process after starting it, the same as we do when attaching
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/linux-gnu/trace.c36
1 files changed, 11 insertions, 25 deletions
diff --git a/sysdeps/linux-gnu/trace.c b/sysdeps/linux-gnu/trace.c
index 9613271..20c42a8 100644
--- a/sysdeps/linux-gnu/trace.c
+++ b/sysdeps/linux-gnu/trace.c
@@ -108,26 +108,21 @@ trace_me(void)
}
/* There's a (hopefully) brief period of time after the child process
- * exec's when we can't trace it yet. Here we wait for kernel to
+ * forks when we can't trace it yet. Here we wait for kernel to
* prepare the process. */
-void
+int
wait_for_proc(pid_t pid)
{
- size_t i;
- for (i = 0; i < 100; ++i) {
- /* We read from memory address 0, but that shouldn't
- * be a problem: the reading will just fail. We are
- * looking for a particular reason of failure. */
- if (ptrace(PTRACE_PEEKTEXT, pid, 0, 0) != -1
- || errno != ESRCH)
- return;
-
- usleep(1000);
+ /* man ptrace: PTRACE_ATTACH attaches to the process specified
+ in pid. The child is sent a SIGSTOP, but will not
+ necessarily have stopped by the completion of this call;
+ use wait() to wait for the child to stop. */
+ if (waitpid(pid, NULL, __WALL) != pid) {
+ perror ("trace_pid: waitpid");
+ return -1;
}
- fprintf(stderr, "\
-I consistently fail to read a word from the freshly launched process.\n\
-I'll now try to proceed with tracing, but this shouldn't be happening.\n");
+ return 0;
}
int
@@ -140,16 +135,7 @@ trace_pid(pid_t pid)
if (ptrace(PTRACE_ATTACH, pid, 1, 0) < 0)
return -1;
- /* man ptrace: PTRACE_ATTACH attaches to the process specified
- in pid. The child is sent a SIGSTOP, but will not
- necessarily have stopped by the completion of this call;
- use wait() to wait for the child to stop. */
- if (waitpid (pid, NULL, __WALL) != pid) {
- perror ("trace_pid: waitpid");
- return -1;
- }
-
- return 0;
+ return wait_for_proc(pid);
}
void