Revision 8363,
2.4 KB
checked in by ghudson, 28 years ago
(diff) |
Include config.h to determine if const is okay.
|
Line | |
---|
1 | /* |
---|
2 | * signals.c -- deal with concerting signal names to numbers and back. |
---|
3 | * |
---|
4 | * $Source: /afs/dev.mit.edu/source/repository/athena/etc/newsyslog/signames.c,v $ |
---|
5 | * $Author: ghudson $ |
---|
6 | */ |
---|
7 | |
---|
8 | #ifndef lint |
---|
9 | static char *rcsid = "$Header: /afs/dev.mit.edu/source/repository/athena/etc/newsyslog/signames.c,v 1.2 1996-05-07 19:55:17 ghudson Exp $"; |
---|
10 | #endif |
---|
11 | |
---|
12 | #include <string.h> |
---|
13 | #include <sys/signal.h> |
---|
14 | #include "config.h" |
---|
15 | #include "signames.h" |
---|
16 | |
---|
17 | struct signal_map { |
---|
18 | char *name; |
---|
19 | int number; |
---|
20 | }; |
---|
21 | |
---|
22 | /* Note: this contains only the signals described in the POSIX.1 |
---|
23 | * programmer's guide, because right now I don't care about any others. |
---|
24 | * If someone else decides they do, they can add them themselves. =) |
---|
25 | */ |
---|
26 | |
---|
27 | static const |
---|
28 | struct signal_map signals[] = { |
---|
29 | #ifdef SIGHUP |
---|
30 | {"HUP", SIGHUP}, |
---|
31 | #endif |
---|
32 | #ifdef SIGINT |
---|
33 | {"INT", SIGINT}, |
---|
34 | #endif |
---|
35 | #ifdef SIGQUIT |
---|
36 | {"QUIT", SIGQUIT}, |
---|
37 | #endif |
---|
38 | #ifdef SIGILL |
---|
39 | {"ILL", SIGILL}, |
---|
40 | #endif |
---|
41 | #ifdef SIGABRT |
---|
42 | {"ABRT", SIGABRT}, |
---|
43 | #endif |
---|
44 | #ifdef SIGFPE |
---|
45 | {"FPE", SIGFPE}, |
---|
46 | #endif |
---|
47 | #ifdef SIGKILL |
---|
48 | {"KILL", SIGKILL}, |
---|
49 | #endif |
---|
50 | #ifdef SIGBUS |
---|
51 | {"BUS", SIGBUS}, |
---|
52 | #endif |
---|
53 | #ifdef SIGSEGV |
---|
54 | {"SEGV", SIGSEGV}, |
---|
55 | #endif |
---|
56 | #ifdef SIGPIPE |
---|
57 | {"PIPE", SIGPIPE}, |
---|
58 | #endif |
---|
59 | #ifdef SIGALRM |
---|
60 | {"ALRM", SIGALRM}, |
---|
61 | #endif |
---|
62 | #ifdef SIGTERM |
---|
63 | {"TERM", SIGTERM}, |
---|
64 | #endif |
---|
65 | #ifdef SIGUSR1 |
---|
66 | {"USR1", SIGUSR1}, |
---|
67 | #endif |
---|
68 | #ifdef SIGUSR2 |
---|
69 | {"USR2", SIGUSR2}, |
---|
70 | #endif |
---|
71 | #ifdef SIGCHLD |
---|
72 | {"CHLD", SIGCHLD}, |
---|
73 | #endif |
---|
74 | #ifdef SIGPWR |
---|
75 | {"PWR", SIGPWR}, /* this is not POSIX.1, but I like it. =) */ |
---|
76 | #endif |
---|
77 | #ifdef SIGSTOP |
---|
78 | {"STOP", SIGSTOP}, |
---|
79 | #endif |
---|
80 | #ifdef SIGTSTP |
---|
81 | {"TSTP", SIGTSTP}, |
---|
82 | #endif |
---|
83 | #ifdef SIGCONT |
---|
84 | {"CONT", SIGCONT}, |
---|
85 | #endif |
---|
86 | #ifdef SIGTTIN |
---|
87 | {"TTIN", SIGTTIN}, |
---|
88 | #endif |
---|
89 | #ifdef SIGTTOU |
---|
90 | {"TTOU", SIGTTOU}, |
---|
91 | #endif |
---|
92 | {NULL, 0} |
---|
93 | }; |
---|
94 | |
---|
95 | /* signal_name() returns the name for a given signal, or NULL if unknown. */ |
---|
96 | char* signal_name (int signum) |
---|
97 | { |
---|
98 | int i; |
---|
99 | |
---|
100 | for (i=0; signals[i].name; i++) { |
---|
101 | if (signum == signals[i].number) |
---|
102 | return signals[i].name; |
---|
103 | } |
---|
104 | return NULL; |
---|
105 | } |
---|
106 | |
---|
107 | /* signal_number() returns the number for a given signal, or 0 if unknown. */ |
---|
108 | int signal_number (char* name) |
---|
109 | { |
---|
110 | int i; |
---|
111 | |
---|
112 | for (i=0; signals[i].name; i++) { |
---|
113 | if (!strcasecmp(name, signals[i].name)) |
---|
114 | return signals[i].number; |
---|
115 | } |
---|
116 | return 0; |
---|
117 | } |
---|
118 | |
---|
119 | /* fprint_signal_name() prints out the signal name, or "signal ##". */ |
---|
120 | void fprint_signal_name(FILE *f, int signum) |
---|
121 | { |
---|
122 | char *name = signal_name(signum); |
---|
123 | |
---|
124 | if (name) |
---|
125 | fprintf(f, name); |
---|
126 | else |
---|
127 | fprintf(f, "signal %d", signum); |
---|
128 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.