I am trying to get a signal name to print when getting a signal number. I actually have :
char* getsig(int sig){
switch (sig)
{
case SIGKILL:
return "SIGKILL";
case SIGSTOP:
return "SIGSTOP";
case SIGTERM:
return "SIGTERM";
case SIGTRAP:
return "SIGTRAP";
case SIGABRT:
return "SIGABRT";
case SIGALRM:
return "SIGALARM";
case SIGSEGV:
return "SIGSEGV";
case SIGQUIT:
return "SIGQUIT";
case SIGINT:
return "SIGINT";
case SIGCHLD:
return "SIGCHLD";
case SIGCONT:
return "SIGCONT";
case SIGPIPE:
return "SIGPIPE";
case SIGFPE:
return "SIGFPE";
case SIGILL:
return "SIGILL";
case 0:
return "[NO SIGNAL TO DELIVER]";
default:
return "UNKN";
}
}
I can see that this is wrong : I have no certitude that those char* names will be stored in data section on every compiler. I am certain that there is a clean way of doing such a thing, but I cannot find it on the internet. Do anyone has an idea of how I could do this task the beautiful way?
Edit
The final aim is to print a potential signal delivered by a ptrace(PTRACE_CONT, ...);
call, e.g:
printf("ptrace(PTRACE_CONT); [delivered %s]\n", getsig(data));