From 79ba247fe64a602aa6af8d65a189ecea913ba61f Mon Sep 17 00:00:00 2001 From: Michael Cook <michael@episci.com> Date: Sun, 11 Oct 2020 10:22:24 -0400 Subject: [PATCH] Catch SIGTERM and attempt to exit cleanly This change is to enable use of gprof which requires the process call `exit` to write out the collected data. The UE (lte-uesoftmodem) exits cleanly, but the eNB (lte-softmodem) crashes as it tries to shut down... --- common/utils/ocp_itti/intertask_interface.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/common/utils/ocp_itti/intertask_interface.cpp b/common/utils/ocp_itti/intertask_interface.cpp index 4c752838943..3776dc41067 100644 --- a/common/utils/ocp_itti/intertask_interface.cpp +++ b/common/utils/ocp_itti/intertask_interface.cpp @@ -416,9 +416,22 @@ task_list_t tasks[TASK_MAX]; void itti_send_terminate_message(task_id_t task_id) { } + static volatile bool shutting_down; + + static void catch_sigterm(int) { + static const char msg[] = "\n** Caught SIGTERM, shutting down\n"; + __attribute__((unused)) + int unused = write(STDOUT_FILENO, msg, sizeof(msg) - 1); + shutting_down = true; + } + void itti_wait_tasks_end(void) { - while(1) - sleep(24*3600); + shutting_down = false; + signal(SIGTERM, catch_sigterm); + while (! shutting_down) + { + sleep(24 * 3600); + } } void itti_update_lte_time(uint32_t frame, uint8_t slot) {} -- GitLab