From: Erwan Velu Date: Thu, 22 Mar 2018 05:25:31 +0000 (+0100) Subject: signal_handler: Implementing specific messages per context X-Git-Tag: v13.1.0~141^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b1037f93bfb356971fe31f9d2fef69d981e28e81;p=ceph.git 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: http://tracker.ceph.com/issues/23320 Signed-off-by: Erwan Velu --- diff --git a/src/global/signal_handler.cc b/src/global/signal_handler.cc index 5764fb3e8f75..ae860e214560 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); } } }