aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert2012-12-07 18:30:51 -0800
committerPaul Eggert2012-12-07 18:30:51 -0800
commitd983a10b9a070fd8f6d4f48ec44e5514b62feaa6 (patch)
tree1b7353b39c508615eb0d2cf4475fdfabf8ef6ce0 /lib
parent9cdde1e2dfdd7b1a4e52294bca1467dc7a48c77a (diff)
downloademacs-d983a10b9a070fd8f6d4f48ec44e5514b62feaa6.tar.gz
emacs-d983a10b9a070fd8f6d4f48ec44e5514b62feaa6.zip
Assume POSIX 1003.1-1988 or later for signal.h.
Exceptions: do not assume SIGCONT, SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU, SIGUSR1, SIGUSR2, as Microsoft platforms lack these. * admin/CPP-DEFINES (SIGALRM, SIGCHLD, SIGHUP, SIGKILL, SIGPIPE, SIGQUIT): Remove. (SIGTRAP): Remove this one too, as config.h no longer defines it. * admin/merge-gnulib (GNULIB_MODULES): Add sig2str. * configure.ac (PTY_OPEN, PTY_TTY_NAME_SPRINTF): Use SIGCHLD rather than SIGCLD. * lib/sig2str.c, lib/sig2str.h, m4/sig2str.m4: New files, from gnulib. * lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate. * lib/makefile.w32-in (GNULIBOBJS): Add $(BUILD)/sig2str.$(O). * src/process.c [subprocesses]: Include <c-ctype.h>, <sig2str.h>. (deleted_pid_list, Fdelete_process, create_process) (record_child_status_change, handle_child_signal, deliver_child_signal) (init_process_emacs, syms_of_process): Assume SIGCHLD is defined. (parse_signal): Remove. All uses removed. (abbr_to_signal): New static function. (Fsignal_process): Use it to convert signal names to ints. * src/sysdep.c (sys_suspend) [!DOS_NT]: Use kill (0, ...) rather than kill (getpgrp (), ...). (emacs_sigaction_init): Assume SIGCHLD is defined. (init_signals): Assume SIGALRM, SIGCHLD, SIGHUP, SIGKILL, SIGPIPE, and SIGQUIT are defined. Do not worry about SIGCLD any more. * src/syssignal.h (EMACS_KILLPG): Remove. All uses replaced by 'kill' with a negative pid. (SIGCHLD): Remove definition, as we now assume SIGCHLD. * src/w32proc.c (sys_kill): Support negative pids compatibly with POSIX. Fixes: debbugs:13026
Diffstat (limited to 'lib')
-rw-r--r--lib/gnulib.mk11
-rw-r--r--lib/makefile.w32-in4
-rw-r--r--lib/sig2str.c345
-rw-r--r--lib/sig2str.h43
4 files changed, 400 insertions, 3 deletions
diff --git a/lib/gnulib.mk b/lib/gnulib.mk
index 9d7cb281564..1335c80dae5 100644
--- a/lib/gnulib.mk
+++ b/lib/gnulib.mk
@@ -21,7 +21,7 @@
21# the same distribution terms as the rest of that program. 21# the same distribution terms as the rest of that program.
22# 22#
23# Generated by gnulib-tool. 23# Generated by gnulib-tool.
24# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=at-internal --avoid=errno --avoid=fchdir --avoid=fcntl --avoid=fstat --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow --avoid=openat-die --avoid=openat-h --avoid=raise --avoid=save-cwd --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt c-ctype c-strcase careadlinkat close-stream crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 environ execinfo faccessat fcntl-h filemode getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings mktime pselect pthread_sigmask readlink socklen stat-time stdalign stdarg stdbool stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timer-time timespec-add timespec-sub utimens warnings 24# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=at-internal --avoid=errno --avoid=fchdir --avoid=fcntl --avoid=fstat --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow --avoid=openat-die --avoid=openat-h --avoid=raise --avoid=save-cwd --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt c-ctype c-strcase careadlinkat close-stream crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 environ execinfo faccessat fcntl-h filemode getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings mktime pselect pthread_sigmask readlink sig2str socklen stat-time stdalign stdarg stdbool stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timer-time timespec-add timespec-sub utimens warnings
25 25
26 26
27MOSTLYCLEANFILES += core *.stackdump 27MOSTLYCLEANFILES += core *.stackdump
@@ -457,6 +457,15 @@ EXTRA_DIST += root-uid.h
457 457
458## end gnulib module root-uid 458## end gnulib module root-uid
459 459
460## begin gnulib module sig2str
461
462
463EXTRA_DIST += sig2str.c sig2str.h
464
465EXTRA_libgnu_a_SOURCES += sig2str.c
466
467## end gnulib module sig2str
468
460## begin gnulib module signal-h 469## begin gnulib module signal-h
461 470
462BUILT_SOURCES += signal.h 471BUILT_SOURCES += signal.h
diff --git a/lib/makefile.w32-in b/lib/makefile.w32-in
index 67171e07900..348fe911a2a 100644
--- a/lib/makefile.w32-in
+++ b/lib/makefile.w32-in
@@ -1,4 +1,4 @@
1# -*- Makefile -*- for GNU Emacs on the Microsoft Windows API. 12# -*- Makefile -*- for GNU Emacs on the Microsoft Windows API.
2# Copyright (C) 2011-2012 Free Software Foundation, Inc. 2# Copyright (C) 2011-2012 Free Software Foundation, Inc.
3 3
4# This file is part of GNU Emacs. 4# This file is part of GNU Emacs.
@@ -42,6 +42,7 @@ GNULIBOBJS = $(BLD)/c-ctype.$(O) \
42 $(BLD)/sha1.$(O) \ 42 $(BLD)/sha1.$(O) \
43 $(BLD)/sha256.$(O) \ 43 $(BLD)/sha256.$(O) \
44 $(BLD)/sha512.$(O) \ 44 $(BLD)/sha512.$(O) \
45 $(BLD)/sig2str.$(O) \
45 $(BLD)/stat-time.$(O) \ 46 $(BLD)/stat-time.$(O) \
46 $(BLD)/timespec.$(O) \ 47 $(BLD)/timespec.$(O) \
47 $(BLD)/u64.$(O) \ 48 $(BLD)/u64.$(O) \
@@ -322,4 +323,3 @@ getopt_h:
322 323
323execinfo.h: execinfo.in.h 324execinfo.h: execinfo.in.h
324 $(CP) execinfo.in.h $@ 325 $(CP) execinfo.in.h $@
325
diff --git a/lib/sig2str.c b/lib/sig2str.c
new file mode 100644
index 00000000000..2f5b21cc36f
--- /dev/null
+++ b/lib/sig2str.c
@@ -0,0 +1,345 @@
1/* sig2str.c -- convert between signal names and numbers
2
3 Copyright (C) 2002, 2004, 2006, 2009-2012 Free Software Foundation, Inc.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18/* Written by Paul Eggert. */
19
20#include <config.h>
21
22#include <limits.h>
23#include <signal.h>
24#include <stdlib.h>
25#include <stdio.h>
26#include <string.h>
27
28#include "sig2str.h"
29
30#ifndef SIGRTMIN
31# define SIGRTMIN 0
32# undef SIGRTMAX
33#endif
34#ifndef SIGRTMAX
35# define SIGRTMAX (SIGRTMIN - 1)
36#endif
37
38#define NUMNAME(name) { SIG##name, #name }
39
40/* Signal names and numbers. Put the preferred name first. */
41static struct numname { int num; char const name[8]; } numname_table[] =
42 {
43 /* Signals required by POSIX 1003.1-2001 base, listed in
44 traditional numeric order where possible. */
45#ifdef SIGHUP
46 NUMNAME (HUP),
47#endif
48#ifdef SIGINT
49 NUMNAME (INT),
50#endif
51#ifdef SIGQUIT
52 NUMNAME (QUIT),
53#endif
54#ifdef SIGILL
55 NUMNAME (ILL),
56#endif
57#ifdef SIGTRAP
58 NUMNAME (TRAP),
59#endif
60#ifdef SIGABRT
61 NUMNAME (ABRT),
62#endif
63#ifdef SIGFPE
64 NUMNAME (FPE),
65#endif
66#ifdef SIGKILL
67 NUMNAME (KILL),
68#endif
69#ifdef SIGSEGV
70 NUMNAME (SEGV),
71#endif
72 /* On Haiku, SIGSEGV == SIGBUS, but we prefer SIGSEGV to match
73 strsignal.c output, so SIGBUS must be listed second. */
74#ifdef SIGBUS
75 NUMNAME (BUS),
76#endif
77#ifdef SIGPIPE
78 NUMNAME (PIPE),
79#endif
80#ifdef SIGALRM
81 NUMNAME (ALRM),
82#endif
83#ifdef SIGTERM
84 NUMNAME (TERM),
85#endif
86#ifdef SIGUSR1
87 NUMNAME (USR1),
88#endif
89#ifdef SIGUSR2
90 NUMNAME (USR2),
91#endif
92#ifdef SIGCHLD
93 NUMNAME (CHLD),
94#endif
95#ifdef SIGURG
96 NUMNAME (URG),
97#endif
98#ifdef SIGSTOP
99 NUMNAME (STOP),
100#endif
101#ifdef SIGTSTP
102 NUMNAME (TSTP),
103#endif
104#ifdef SIGCONT
105 NUMNAME (CONT),
106#endif
107#ifdef SIGTTIN
108 NUMNAME (TTIN),
109#endif
110#ifdef SIGTTOU
111 NUMNAME (TTOU),
112#endif
113
114 /* Signals required by POSIX 1003.1-2001 with the XSI extension. */
115#ifdef SIGSYS
116 NUMNAME (SYS),
117#endif
118#ifdef SIGPOLL
119 NUMNAME (POLL),
120#endif
121#ifdef SIGVTALRM
122 NUMNAME (VTALRM),
123#endif
124#ifdef SIGPROF
125 NUMNAME (PROF),
126#endif
127#ifdef SIGXCPU
128 NUMNAME (XCPU),
129#endif
130#ifdef SIGXFSZ
131 NUMNAME (XFSZ),
132#endif
133
134 /* Unix Version 7. */
135#ifdef SIGIOT
136 NUMNAME (IOT), /* Older name for ABRT. */
137#endif
138#ifdef SIGEMT
139 NUMNAME (EMT),
140#endif
141
142 /* USG Unix. */
143#ifdef SIGPHONE
144 NUMNAME (PHONE),
145#endif
146#ifdef SIGWIND
147 NUMNAME (WIND),
148#endif
149
150 /* Unix System V. */
151#ifdef SIGCLD
152 NUMNAME (CLD),
153#endif
154#ifdef SIGPWR
155 NUMNAME (PWR),
156#endif
157
158 /* GNU/Linux 2.2 and Solaris 8. */
159#ifdef SIGCANCEL
160 NUMNAME (CANCEL),
161#endif
162#ifdef SIGLWP
163 NUMNAME (LWP),
164#endif
165#ifdef SIGWAITING
166 NUMNAME (WAITING),
167#endif
168#ifdef SIGFREEZE
169 NUMNAME (FREEZE),
170#endif
171#ifdef SIGTHAW
172 NUMNAME (THAW),
173#endif
174#ifdef SIGLOST
175 NUMNAME (LOST),
176#endif
177#ifdef SIGWINCH
178 NUMNAME (WINCH),
179#endif
180
181 /* GNU/Linux 2.2. */
182#ifdef SIGINFO
183 NUMNAME (INFO),
184#endif
185#ifdef SIGIO
186 NUMNAME (IO),
187#endif
188#ifdef SIGSTKFLT
189 NUMNAME (STKFLT),
190#endif
191
192 /* AIX 5L. */
193#ifdef SIGDANGER
194 NUMNAME (DANGER),
195#endif
196#ifdef SIGGRANT
197 NUMNAME (GRANT),
198#endif
199#ifdef SIGMIGRATE
200 NUMNAME (MIGRATE),
201#endif
202#ifdef SIGMSG
203 NUMNAME (MSG),
204#endif
205#ifdef SIGPRE
206 NUMNAME (PRE),
207#endif
208#ifdef SIGRETRACT
209 NUMNAME (RETRACT),
210#endif
211#ifdef SIGSAK
212 NUMNAME (SAK),
213#endif
214#ifdef SIGSOUND
215 NUMNAME (SOUND),
216#endif
217
218 /* Older AIX versions. */
219#ifdef SIGALRM1
220 NUMNAME (ALRM1), /* unknown; taken from Bash 2.05 */
221#endif
222#ifdef SIGKAP
223 NUMNAME (KAP), /* Older name for SIGGRANT. */
224#endif
225#ifdef SIGVIRT
226 NUMNAME (VIRT), /* unknown; taken from Bash 2.05 */
227#endif
228#ifdef SIGWINDOW
229 NUMNAME (WINDOW), /* Older name for SIGWINCH. */
230#endif
231
232 /* BeOS */
233#ifdef SIGKILLTHR
234 NUMNAME (KILLTHR),
235#endif
236
237 /* Older HP-UX versions. */
238#ifdef SIGDIL
239 NUMNAME (DIL),
240#endif
241
242 /* Korn shell and Bash, of uncertain vintage. */
243 { 0, "EXIT" }
244 };
245
246#define NUMNAME_ENTRIES (sizeof numname_table / sizeof numname_table[0])
247
248/* ISDIGIT differs from isdigit, as follows:
249 - Its arg may be any int or unsigned int; it need not be an unsigned char
250 or EOF.
251 - It's typically faster.
252 POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
253 isdigit unless it's important to use the locale's definition
254 of "digit" even when the host does not conform to POSIX. */
255#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
256
257/* Convert the signal name SIGNAME to a signal number. Return the
258 signal number if successful, -1 otherwise. */
259
260static int
261str2signum (char const *signame)
262{
263 if (ISDIGIT (*signame))
264 {
265 char *endp;
266 long int n = strtol (signame, &endp, 10);
267 if (! *endp && n <= SIGNUM_BOUND)
268 return n;
269 }
270 else
271 {
272 unsigned int i;
273 for (i = 0; i < NUMNAME_ENTRIES; i++)
274 if (strcmp (numname_table[i].name, signame) == 0)
275 return numname_table[i].num;
276
277 {
278 char *endp;
279 int rtmin = SIGRTMIN;
280 int rtmax = SIGRTMAX;
281
282 if (0 < rtmin && strncmp (signame, "RTMIN", 5) == 0)
283 {
284 long int n = strtol (signame + 5, &endp, 10);
285 if (! *endp && 0 <= n && n <= rtmax - rtmin)
286 return rtmin + n;
287 }
288 else if (0 < rtmax && strncmp (signame, "RTMAX", 5) == 0)
289 {
290 long int n = strtol (signame + 5, &endp, 10);
291 if (! *endp && rtmin - rtmax <= n && n <= 0)
292 return rtmax + n;
293 }
294 }
295 }
296
297 return -1;
298}
299
300/* Convert the signal name SIGNAME to the signal number *SIGNUM.
301 Return 0 if successful, -1 otherwise. */
302
303int
304str2sig (char const *signame, int *signum)
305{
306 *signum = str2signum (signame);
307 return *signum < 0 ? -1 : 0;
308}
309
310/* Convert SIGNUM to a signal name in SIGNAME. SIGNAME must point to
311 a buffer of at least SIG2STR_MAX bytes. Return 0 if successful, -1
312 otherwise. */
313
314int
315sig2str (int signum, char *signame)
316{
317 unsigned int i;
318 for (i = 0; i < NUMNAME_ENTRIES; i++)
319 if (numname_table[i].num == signum)
320 {
321 strcpy (signame, numname_table[i].name);
322 return 0;
323 }
324
325 {
326 int rtmin = SIGRTMIN;
327 int rtmax = SIGRTMAX;
328
329 if (! (rtmin <= signum && signum <= rtmax))
330 return -1;
331
332 if (signum <= rtmin + (rtmax - rtmin) / 2)
333 {
334 int delta = signum - rtmin;
335 sprintf (signame, delta ? "RTMIN+%d" : "RTMIN", delta);
336 }
337 else
338 {
339 int delta = rtmax - signum;
340 sprintf (signame, delta ? "RTMAX-%d" : "RTMAX", delta);
341 }
342
343 return 0;
344 }
345}
diff --git a/lib/sig2str.h b/lib/sig2str.h
new file mode 100644
index 00000000000..75eff7d7c1a
--- /dev/null
+++ b/lib/sig2str.h
@@ -0,0 +1,43 @@
1/* sig2str.h -- convert between signal names and numbers
2
3 Copyright (C) 2002, 2005, 2009-2012 Free Software Foundation, Inc.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18/* Written by Paul Eggert. */
19
20#include <signal.h>
21
22/* Don't override system declarations of SIG2STR_MAX, sig2str, str2sig. */
23#ifndef SIG2STR_MAX
24
25# include "intprops.h"
26
27/* Size of a buffer needed to hold a signal name like "HUP". */
28# define SIG2STR_MAX (sizeof "SIGRTMAX" + INT_STRLEN_BOUND (int) - 1)
29
30int sig2str (int, char *);
31int str2sig (char const *, int *);
32
33#endif
34
35/* An upper bound on signal numbers allowed by the system. */
36
37#if defined _sys_nsig
38# define SIGNUM_BOUND (_sys_nsig - 1)
39#elif defined NSIG
40# define SIGNUM_BOUND (NSIG - 1)
41#else
42# define SIGNUM_BOUND 64
43#endif