From 61be1b2e401b4f25334a935bbf76bbbad3d56ea6 Mon Sep 17 00:00:00 2001 From: Dmitrii Kuvaiskii Date: Sun, 7 Jul 2019 20:30:09 -0700 Subject: [PATCH] [LibOS] Instruct thread_exit() to send IPC_CLD_EXIT only once Previously, when a thread exited via thread_exit(), it could send two identical IPC_CLD_EXIT messages under certain conditions. This commit fixes this bug and forces thread_exit() to send IPC_CLD_EXIT at most once. --- LibOS/shim/src/sys/shim_exit.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/LibOS/shim/src/sys/shim_exit.c b/LibOS/shim/src/sys/shim_exit.c index b71a5638..6ae43464 100644 --- a/LibOS/shim/src/sys/shim_exit.c +++ b/LibOS/shim/src/sys/shim_exit.c @@ -44,10 +44,14 @@ void release_clear_child_id (int * clear_child_tid); int thread_exit(struct shim_thread * self, bool send_ipc) { + bool sent_exit_msg = false; + /* Chia-Che: Broadcast exit message as early as possible, so other process can start early on responding. */ - if (self->in_vm && send_ipc) + if (self->in_vm && send_ipc) { ipc_cld_exit_send(self->ppid, self->tid, self->exit_code, self->term_signal); + sent_exit_msg = true; + } lock(&self->lock); @@ -99,7 +103,7 @@ int thread_exit(struct shim_thread * self, bool send_ipc) unlock(&parent->lock); DkEventSet(parent->child_exit_event); - } else { + } else if (!sent_exit_msg) { debug("parent not here, need to tell another process\n"); ipc_cld_exit_send(self->ppid, self->tid, self->exit_code, self->term_signal); }