X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fprocd.git;a=blobdiff_plain;f=trace%2Ftrace.c;h=cad2d370996d1ad179658cd950f00e78be5a575b;hp=f882c2e0d5a14a2d5e110634d9456e87eb3c4daf;hb=b5d53c6c683ee73b5d494b5d0750d1deca7b749f;hpb=8b7d47af206e057437832d08116b497d38683daa diff --git a/trace/trace.c b/trace/trace.c index f882c2e..cad2d37 100644 --- a/trace/trace.c +++ b/trace/trace.c @@ -148,6 +148,7 @@ static void print_syscalls(int policy, const char *json) static void tracer_cb(struct uloop_process *c, int ret) { struct tracee *tracee = container_of(c, struct tracee, proc); + int inject_signal = 0; if (WIFSTOPPED(ret)) { if (WSTOPSIG(ret) & 0x80) { @@ -163,7 +164,9 @@ static void tracer_cb(struct uloop_process *c, int ret) } } tracee->in_syscall = !tracee->in_syscall; - } else if ((ret >> 8) == (SIGTRAP | (PTRACE_EVENT_FORK << 8))) { + } else if ((ret >> 8) == (SIGTRAP | (PTRACE_EVENT_FORK << 8)) || + (ret >> 8) == (SIGTRAP | (PTRACE_EVENT_VFORK << 8)) || + (ret >> 8) == (SIGTRAP | (PTRACE_EVENT_CLONE << 8))) { struct tracee *child = calloc(1, sizeof(struct tracee)); ptrace(PTRACE_GETEVENTMSG, c->pid, 0, &child->proc.pid); @@ -172,8 +175,13 @@ static void tracer_cb(struct uloop_process *c, int ret) uloop_process_add(&child->proc); if (debug) fprintf(stderr, "Tracing new child %d\n", child->proc.pid); + } else { + inject_signal = WSTOPSIG(ret); + if (debug) + fprintf(stderr, "Injecting signal %d into pid %d\n", + inject_signal, tracee->proc.pid); } - } else if (WIFEXITED(ret)) { + } else if (WIFEXITED(ret) || (WIFSIGNALED(ret) && WTERMSIG(ret))) { if (tracee == &tracer) { uloop_end(); /* Main process exit */ } else { @@ -184,7 +192,7 @@ static void tracer_cb(struct uloop_process *c, int ret) return; } - ptrace(PTRACE_SYSCALL, c->pid, 0, 0); + ptrace(PTRACE_SYSCALL, c->pid, 0, inject_signal); uloop_process_add(c); } @@ -254,7 +262,9 @@ int main(int argc, char **argv, char **envp) ptrace(PTRACE_SETOPTIONS, child, 0, PTRACE_O_TRACESYSGOOD | - PTRACE_O_TRACEFORK); + PTRACE_O_TRACEFORK | + PTRACE_O_TRACEVFORK | + PTRACE_O_TRACECLONE); ptrace(PTRACE_SYSCALL, child, 0, 0); uloop_init();