From 8c6d7420ed4538f4754ab82115f3aac7e20dcada Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Thu, 22 Mar 2018 06:25:31 +0100 Subject: [PATCH] signal_handler: Implementing specific messages per context As per bug #23320, regarding the signal we receive, it could be interesting providing a specific message. If we get a SI_USER we almost print the actual message except we don't print the PID which have no meaning when set to 0. In all other cases, we do print the full structure to help debuggers understanding the received signal. This patch is offering a better way to get specific messages based on various si_code values. It could be expanded later based on debugging feedbacks. Fixes: #23320 Signed-off-by: Erwan Velu --- src/global/signal_handler.cc | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/global/signal_handler.cc b/src/global/signal_handler.cc index 5764fb3e8f759..ae860e214560c 100644 --- a/src/global/signal_handler.cc +++ b/src/global/signal_handler.cc @@ -313,13 +313,33 @@ struct SignalHandler : public Thread { r = read(handlers[signum]->pipefd[0], &v, 1); if (r == 1) { siginfo_t * siginfo = &handlers[signum]->info_t; - string task_name = get_name_by_pid(siginfo->si_pid); - derr << "received signal: " << sig_str(signum) - << " from " << " PID: " << siginfo->si_pid - << " task name: " << task_name - << " UID: " << siginfo->si_uid - << dendl; - handlers[signum]->handler(signum); + ostringstream message; + message << "received signal: " << sig_str(signum); + switch (siginfo->si_code) { + case SI_USER: + message << " from " << get_name_by_pid(siginfo->si_pid); + // If PID is undefined, it doesn't have a meaning to be displayed + if (siginfo->si_pid) { + message << " (PID: " << siginfo->si_pid << ")"; + } else { + message << " ( Could be generated by pthread_kill(), raise(), abort(), alarm() )"; + } + message << " UID: " << siginfo->si_uid; + break; + default: + /* As we have a not expected signal, let's report the structure to help debugging */ + message << ", si_code : " << siginfo->si_code; + message << ", si_value (int): " << siginfo->si_value.sival_int; + message << ", si_value (ptr): " << siginfo->si_value.sival_ptr; + message << ", si_errno: " << siginfo->si_errno; + message << ", si_pid : " << siginfo->si_pid; + message << ", si_uid : " << siginfo->si_uid; + message << ", si_addr" << siginfo->si_addr; + message << ", si_status" << siginfo->si_status; + break; + } + derr << message.str() << dendl; + handlers[signum]->handler(signum); } } }