Logo AND Algorithmique Numérique Distribuée

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