[LEDE-DEV,procd,08/17] utrace: Deliver signals to traced processes

Message ID 20170912111250.31576-11-sojkam1@fel.cvut.cz
State Accepted
Headers show
Series
  • [LEDE-DEV,procd,01/17] utrace: Fix environment initialization
Related show

Commit Message

Michal Sojka Sept. 12, 2017, 11:12 a.m.
Without this change, traced processes do not receive any signal,
because all the signals are "eaten" by the tracer.

Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
---
 trace/trace.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Patch

diff --git a/trace/trace.c b/trace/trace.c
index 4c25a4f..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) {
@@ -174,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 {
@@ -186,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);
 }