From 0caa94955018d3e2d61c8af404cfa3ba459dae96 Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Sat, 25 Sep 2021 07:16:47 +0900 Subject: [PATCH] ptrace: Inform non-parent tracer when tracee exits --- kernel/sys/process.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kernel/sys/process.c b/kernel/sys/process.c index 2e692dae..e03ec199 100644 --- a/kernel/sys/process.c +++ b/kernel/sys/process.c @@ -1000,7 +1000,7 @@ int waitpid(int pid, int * status, int options) { process_t * child = node->value; if (wait_candidate(proc,pid,options,child)) { has_children = 1; - if (child->flags & PROC_FLAG_SUSPENDED) { + if (child->flags & (PROC_FLAG_SUSPENDED | PROC_FLAG_FINISHED)) { candidate = child; break; } @@ -1257,12 +1257,22 @@ void task_exit(int retval) { process_t * parent = process_get_parent((process_t *)this_core->current_process); __sync_or_and_fetch(&this_core->current_process->flags, PROC_FLAG_FINISHED); + if (this_core->current_process->tracer) { + process_t * tracer = process_from_pid(this_core->current_process->tracer); + if (tracer && tracer != parent) { + spin_lock(tracer->wait_lock); + wakeup_queue(tracer->wait_queue); + spin_unlock(tracer->wait_lock); + } + } + if (parent && !(parent->flags & PROC_FLAG_FINISHED)) { spin_lock(parent->wait_lock); send_signal(parent->group, SIGCHLD, 1); wakeup_queue(parent->wait_queue); spin_unlock(parent->wait_lock); } + switch_next(); }