Skip to content

Commit

Permalink
signal_handler: Implementing specific messages per context
Browse files Browse the repository at this point in the history
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 <erwan@redhat.com>
  • Loading branch information
Erwan Velu committed Apr 4, 2018
1 parent 82ab412 commit 8c6d742
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/global/signal_handler.cc
Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 8c6d742

Please sign in to comment.