Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Better modularization of the tesh source code
[simgrid.git] / tools / tesh / signal.c
1 /* $Id$ */
2
3 /* signal -- what TESH needs to know about signals                          */
4
5 /* Copyright (c) 2007 Martin Quinson.                                       */
6 /* All rights reserved.                                                     */
7
8 /* This program is free software; you can redistribute it and/or modify it
9  * under the terms of the license (GNU LGPL) which comes with this package. */
10
11 #include "tesh.h"
12 #include <signal.h>
13
14 typedef struct s_signal_entry {
15   const char* name;
16   int number;
17 } s_signal_entry_t,* signal_entry_t;
18
19 static const s_signal_entry_t signals[] = {
20         {"SIGHUP"       ,SIGHUP},
21         {"SIGINT"       ,SIGINT},
22         {"SIGQUIT"      ,SIGQUIT},
23         {"SIGILL"       ,SIGILL},
24         {"SIGTRAP"      ,SIGTRAP},
25         {"SIGABRT"      ,SIGABRT},
26         {"SIGFPE"       ,SIGFPE},
27         {"SIGKILL"      ,SIGKILL},
28         {"SIGBUS"       ,SIGBUS},
29         {"SIGSEGV"      ,SIGSEGV},
30         {"SIGSYS"       ,SIGSYS},
31         {"SIGPIPE"      ,SIGPIPE},
32         {"SIGALRM"      ,SIGALRM},
33         {"SIGTERM"      ,SIGTERM},
34         {"SIGURG"       ,SIGURG},
35         {"SIGSTOP"      ,SIGSTOP},
36         {"SIGTSTP"      ,SIGTSTP},
37         {"SIGCONT"      ,SIGCONT},
38         {"SIGCHLD"      ,SIGCHLD},
39         {"SIGTTIN"      ,SIGTTIN},
40         {"SIGTTOU"      ,SIGTTOU},
41         {"SIGIO"        ,SIGIO},
42         {"SIGXCPU"      ,SIGXCPU},
43         {"SIGXFSZ"      ,SIGXFSZ},
44         {"SIGVTALRM"    ,SIGVTALRM},
45         {"SIGPROF"      ,SIGPROF},
46         {"SIGWINCH"     ,SIGWINCH},
47         {"SIGUSR1"      ,SIGUSR1},
48         {"SIGUSR2"      ,SIGUSR2},
49         {"SIG UNKNOWN"  ,-1}
50 };
51
52
53 const char* signal_name(unsigned int got, char *expected) {
54   int i;
55
56   /* Make SIGBUS a synonym for SIGSEGV
57      (segfault leads to any of them depending on the system) */
58   if((got == SIGBUS) && !strcmp("SIGSEGV",expected))
59     got = SIGSEGV;
60   
61   for (i=0; signals[i].number != -1; i++)
62     if (signals[i].number == got)
63       return (signals[i].name);
64
65   return "SIG UNKNOWN";  
66 }