Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 1132 lines (1028 sloc) 23.816 kb
655e96f 2000-05-09
matz authored
1 /**********************************************************************
3db12e8 Initial revision
matz authored
2
3 signal.c -
4
5 $Author$
6 created at: Tue Dec 20 10:13:44 JST 1994
7
a25fbe3 * encoding.c: provide basic features for M17N.
matz authored
8 Copyright (C) 1993-2007 Yukihiro Matsumoto
fedf489 2000-05-01
matz authored
9 Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
655e96f 2000-05-09
matz authored
10 Copyright (C) 2000 Information-technology Promotion Agency, Japan
fedf489 2000-05-01
matz authored
11
655e96f 2000-05-09
matz authored
12 **********************************************************************/
3db12e8 Initial revision
matz authored
13
2b59258 @nobu * include/ruby: moved public headers.
nobu authored
14 #include "ruby/ruby.h"
6b6bf4d @ko1 * blockinlining.c: remove "yarv" prefix.
ko1 authored
15 #include "vm_core.h"
3db12e8 Initial revision
matz authored
16 #include <signal.h>
17 #include <stdio.h>
782576a * ext/curses/curses.c (window_getch): avoid ISPRINT() macro which
matz authored
18 #include <errno.h>
9d4e471 @kosaki * vm_core.h (RUBY_VM_SET_TIMER_INTERRUPT, RUBY_VM_SET_INTERRUPT,
kosaki authored
19 #include "atomic.h"
20
76bc2d1 @yugui Imports Ruby's port to NativeClient (a.k.a NaCl).
yugui authored
21 #if defined(__native_client__) && defined(NACL_NEWLIB)
22 # include "nacl/signal.h"
23 #endif
24
c96c193 @nobu * atomic.h (ATOMIC_INC, ATOMIC_DEC): return old values.
nobu authored
25 #ifdef NEED_RUBY_ATOMIC_EXCHANGE
e6f4c92 @sorah * signal.c(ruby_atomic_exchange): Fix definement style.
sorah authored
26 rb_atomic_t
27 ruby_atomic_exchange(rb_atomic_t *ptr, rb_atomic_t val)
9d4e471 @kosaki * vm_core.h (RUBY_VM_SET_TIMER_INTERRUPT, RUBY_VM_SET_INTERRUPT,
kosaki authored
28 {
29 rb_atomic_t old = *ptr;
30 *ptr = val;
31 return old;
32 }
204929a @ko1 * include/ruby/signal.h: removed.
ko1 authored
33 #endif
34
d5b0c4b @nurse * dln.c, file.c, io.c, signal.c: add __HAIKU__.
nurse authored
35 #if defined(__BEOS__) || defined(__HAIKU__)
210367e This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
36 #undef SIGBUS
37 #endif
38
0148d41 @kosaki * signal.c: Now, USE_TRAP_SIGMASK depend on HAVE_PTHREAD_SIGMASK.
kosaki authored
39 #ifdef HAVE_PTHREAD_SIGMASK
82f631a @nobu * configure.in (sigsetmask): check when signal semantics is not POSIX.
nobu authored
40 #define USE_TRAP_MASK 1
41 #else
42 #define USE_TRAP_MASK 0
43 #endif
44
3db12e8 Initial revision
matz authored
45 #ifndef NSIG
8dd118c @yugui * djgpp/GNUmakefile.in: removed. Ruby no longer supports djgpp.
yugui authored
46 # define NSIG (_SIGMAX + 1) /* For QNX */
3db12e8 Initial revision
matz authored
47 #endif
210367e This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
48
e615e3c @nobu * error.c (builtin_types), signal.c (siglist), st.c (primes),
nobu authored
49 static const struct signals {
59ffb8a * intern.h, eval.c (rb_thread_signal_raise): costified.
ocean authored
50 const char *signm;
3db12e8 Initial revision
matz authored
51 int signo;
52 } siglist [] = {
8db3dc3 * signal.c (sigexit): call rb_thread_signal_exit() instead of
matz authored
53 {"EXIT", 0},
3db12e8 Initial revision
matz authored
54 #ifdef SIGHUP
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
55 {"HUP", SIGHUP},
3db12e8 Initial revision
matz authored
56 #endif
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
57 {"INT", SIGINT},
3db12e8 Initial revision
matz authored
58 #ifdef SIGQUIT
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
59 {"QUIT", SIGQUIT},
3db12e8 Initial revision
matz authored
60 #endif
61 #ifdef SIGILL
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
62 {"ILL", SIGILL},
3db12e8 Initial revision
matz authored
63 #endif
64 #ifdef SIGTRAP
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
65 {"TRAP", SIGTRAP},
3db12e8 Initial revision
matz authored
66 #endif
67 #ifdef SIGIOT
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
68 {"IOT", SIGIOT},
3db12e8 Initial revision
matz authored
69 #endif
70 #ifdef SIGABRT
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
71 {"ABRT", SIGABRT},
3db12e8 Initial revision
matz authored
72 #endif
73 #ifdef SIGEMT
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
74 {"EMT", SIGEMT},
3db12e8 Initial revision
matz authored
75 #endif
76 #ifdef SIGFPE
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
77 {"FPE", SIGFPE},
3db12e8 Initial revision
matz authored
78 #endif
79 #ifdef SIGKILL
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
80 {"KILL", SIGKILL},
3db12e8 Initial revision
matz authored
81 #endif
82 #ifdef SIGBUS
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
83 {"BUS", SIGBUS},
3db12e8 Initial revision
matz authored
84 #endif
85 #ifdef SIGSEGV
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
86 {"SEGV", SIGSEGV},
3db12e8 Initial revision
matz authored
87 #endif
88 #ifdef SIGSYS
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
89 {"SYS", SIGSYS},
3db12e8 Initial revision
matz authored
90 #endif
91 #ifdef SIGPIPE
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
92 {"PIPE", SIGPIPE},
3db12e8 Initial revision
matz authored
93 #endif
94 #ifdef SIGALRM
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
95 {"ALRM", SIGALRM},
3db12e8 Initial revision
matz authored
96 #endif
97 #ifdef SIGTERM
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
98 {"TERM", SIGTERM},
3db12e8 Initial revision
matz authored
99 #endif
100 #ifdef SIGURG
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
101 {"URG", SIGURG},
3db12e8 Initial revision
matz authored
102 #endif
103 #ifdef SIGSTOP
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
104 {"STOP", SIGSTOP},
3db12e8 Initial revision
matz authored
105 #endif
106 #ifdef SIGTSTP
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
107 {"TSTP", SIGTSTP},
3db12e8 Initial revision
matz authored
108 #endif
109 #ifdef SIGCONT
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
110 {"CONT", SIGCONT},
3db12e8 Initial revision
matz authored
111 #endif
112 #ifdef SIGCHLD
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
113 {"CHLD", SIGCHLD},
3db12e8 Initial revision
matz authored
114 #endif
115 #ifdef SIGCLD
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
116 {"CLD", SIGCLD},
3db12e8 Initial revision
matz authored
117 #else
118 # ifdef SIGCHLD
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
119 {"CLD", SIGCHLD},
3db12e8 Initial revision
matz authored
120 # endif
121 #endif
122 #ifdef SIGTTIN
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
123 {"TTIN", SIGTTIN},
3db12e8 Initial revision
matz authored
124 #endif
125 #ifdef SIGTTOU
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
126 {"TTOU", SIGTTOU},
3db12e8 Initial revision
matz authored
127 #endif
128 #ifdef SIGIO
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
129 {"IO", SIGIO},
3db12e8 Initial revision
matz authored
130 #endif
131 #ifdef SIGXCPU
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
132 {"XCPU", SIGXCPU},
3db12e8 Initial revision
matz authored
133 #endif
134 #ifdef SIGXFSZ
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
135 {"XFSZ", SIGXFSZ},
3db12e8 Initial revision
matz authored
136 #endif
137 #ifdef SIGVTALRM
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
138 {"VTALRM", SIGVTALRM},
3db12e8 Initial revision
matz authored
139 #endif
140 #ifdef SIGPROF
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
141 {"PROF", SIGPROF},
3db12e8 Initial revision
matz authored
142 #endif
143 #ifdef SIGWINCH
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
144 {"WINCH", SIGWINCH},
3db12e8 Initial revision
matz authored
145 #endif
146 #ifdef SIGUSR1
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
147 {"USR1", SIGUSR1},
3db12e8 Initial revision
matz authored
148 #endif
149 #ifdef SIGUSR2
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
150 {"USR2", SIGUSR2},
3db12e8 Initial revision
matz authored
151 #endif
152 #ifdef SIGLOST
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
153 {"LOST", SIGLOST},
3db12e8 Initial revision
matz authored
154 #endif
155 #ifdef SIGMSG
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
156 {"MSG", SIGMSG},
3db12e8 Initial revision
matz authored
157 #endif
158 #ifdef SIGPWR
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
159 {"PWR", SIGPWR},
3db12e8 Initial revision
matz authored
160 #endif
161 #ifdef SIGPOLL
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
162 {"POLL", SIGPOLL},
3db12e8 Initial revision
matz authored
163 #endif
164 #ifdef SIGDANGER
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
165 {"DANGER", SIGDANGER},
3db12e8 Initial revision
matz authored
166 #endif
167 #ifdef SIGMIGRATE
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
168 {"MIGRATE", SIGMIGRATE},
3db12e8 Initial revision
matz authored
169 #endif
170 #ifdef SIGPRE
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
171 {"PRE", SIGPRE},
3db12e8 Initial revision
matz authored
172 #endif
173 #ifdef SIGGRANT
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
174 {"GRANT", SIGGRANT},
3db12e8 Initial revision
matz authored
175 #endif
176 #ifdef SIGRETRACT
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
177 {"RETRACT", SIGRETRACT},
3db12e8 Initial revision
matz authored
178 #endif
179 #ifdef SIGSOUND
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
180 {"SOUND", SIGSOUND},
3db12e8 Initial revision
matz authored
181 #endif
f84f4aa * array.c (rb_ary_and): should not push frozen key string.
matz authored
182 #ifdef SIGINFO
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
183 {"INFO", SIGINFO},
f84f4aa * array.c (rb_ary_and): should not push frozen key string.
matz authored
184 #endif
e3a8c62 * io.c (rb_io_mode_flags): both 'r+b' and 'rb+' should be allowed.
matz authored
185 {NULL, 0}
3db12e8 Initial revision
matz authored
186 };
187
188 static int
59ffb8a * intern.h, eval.c (rb_thread_signal_raise): costified.
ocean authored
189 signm2signo(const char *nm)
3db12e8 Initial revision
matz authored
190 {
e615e3c @nobu * error.c (builtin_types), signal.c (siglist), st.c (primes),
nobu authored
191 const struct signals *sigs;
3db12e8 Initial revision
matz authored
192
193 for (sigs = siglist; sigs->signm; sigs++)
194 if (strcmp(sigs->signm, nm) == 0)
195 return sigs->signo;
196 return 0;
197 }
198
59ffb8a * intern.h, eval.c (rb_thread_signal_raise): costified.
ocean authored
199 static const char*
dda5dc0 * array.c: moved to ANSI function style from K&R function style.
ocean authored
200 signo2signm(int no)
65a5162 1.4.0
matz authored
201 {
e615e3c @nobu * error.c (builtin_types), signal.c (siglist), st.c (primes),
nobu authored
202 const struct signals *sigs;
65a5162 1.4.0
matz authored
203
204 for (sigs = siglist; sigs->signm; sigs++)
205 if (sigs->signo == no)
206 return sigs->signm;
207 return 0;
208 }
209
5c547fd @nobu * signal.c (ruby_signal_name): adjust to the prototype.
nobu authored
210 const char *
dda5dc0 * array.c: moved to ANSI function style from K&R function style.
ocean authored
211 ruby_signal_name(int no)
4699b4a * eval.c (rb_thread_atfork): wrong format specifier.
matz authored
212 {
213 return signo2signm(no);
214 }
215
88c127c Finish documenting internal stuff. See Changelog for other details
dave authored
216 /*
3fc37d7 @nobu * eval.c (ruby_cleanup): re-send signal. [ruby-dev:30516]
nobu authored
217 * call-seq:
7729de4 @marcandre * array.c: Documentation: change => in call-seq to ->.
marcandre authored
218 * SignalException.new(sig_name) -> signal_exception
219 * SignalException.new(sig_number [, name]) -> signal_exception
3fc37d7 @nobu * eval.c (ruby_cleanup): re-send signal. [ruby-dev:30516]
nobu authored
220 *
4d3f877 @marcandre * signal.c (ruby_signal_name): rdoc fix for undocumented parameter
marcandre authored
221 * Construct a new SignalException object. +sig_name+ should be a known
222 * signal name.
3fc37d7 @nobu * eval.c (ruby_cleanup): re-send signal. [ruby-dev:30516]
nobu authored
223 */
224
225 static VALUE
226 esignal_init(int argc, VALUE *argv, VALUE self)
227 {
228 int argnum = 1;
229 VALUE sig = Qnil;
230 int signo;
231 const char *signm;
232
233 if (argc > 0) {
234 sig = rb_check_to_integer(argv[0], "to_int");
235 if (!NIL_P(sig)) argnum = 2;
9df1210 @mame * signal.c (esignal_init): handle a non-integer argument correctly,
mame authored
236 else sig = argv[0];
3fc37d7 @nobu * eval.c (ruby_cleanup): re-send signal. [ruby-dev:30516]
nobu authored
237 }
7316302 @marcandre * include/ruby/intern.h: Add rb_check_arity, rb_error_arity [#6085]
marcandre authored
238 rb_check_arity(argc, 1, argnum);
3fc37d7 @nobu * eval.c (ruby_cleanup): re-send signal. [ruby-dev:30516]
nobu authored
239 if (argnum == 2) {
240 signo = NUM2INT(sig);
241 if (signo < 0 || signo > NSIG) {
242 rb_raise(rb_eArgError, "invalid signal number (%d)", signo);
243 }
244 if (argc > 1) {
245 sig = argv[1];
246 }
247 else {
248 signm = signo2signm(signo);
249 if (signm) {
250 sig = rb_sprintf("SIG%s", signm);
251 }
252 else {
253 sig = rb_sprintf("SIG%u", signo);
254 }
255 }
256 }
257 else {
258 signm = SYMBOL_P(sig) ? rb_id2name(SYM2ID(sig)) : StringValuePtr(sig);
259 if (strncmp(signm, "SIG", 3) == 0) signm += 3;
260 signo = signm2signo(signm);
261 if (!signo) {
262 rb_raise(rb_eArgError, "unsupported name `SIG%s'", signm);
263 }
bd90304 @mame * signal.c (esignal_signo): fix SignalException#signo which returned
mame authored
264 sig = rb_sprintf("SIG%s", signm);
3fc37d7 @nobu * eval.c (ruby_cleanup): re-send signal. [ruby-dev:30516]
nobu authored
265 }
266 rb_call_super(1, &sig);
267 rb_iv_set(self, "signo", INT2NUM(signo));
268
269 return self;
270 }
271
bd90304 @mame * signal.c (esignal_signo): fix SignalException#signo which returned
mame authored
272 /*
273 * call-seq:
7729de4 @marcandre * array.c: Documentation: change => in call-seq to ->.
marcandre authored
274 * signal_exception.signo -> num
bd90304 @mame * signal.c (esignal_signo): fix SignalException#signo which returned
mame authored
275 *
276 * Returns a signal number.
277 */
278
279 static VALUE
280 esignal_signo(VALUE self)
281 {
282 return rb_iv_get(self, "signo");
283 }
284
04d1998 @nobu * signal.c (interrupt_init): nodoc.
nobu authored
285 /* :nodoc: */
3fc37d7 @nobu * eval.c (ruby_cleanup): re-send signal. [ruby-dev:30516]
nobu authored
286 static VALUE
287 interrupt_init(int argc, VALUE *argv, VALUE self)
288 {
289 VALUE args[2];
290
291 args[0] = INT2FIX(SIGINT);
06eeec8 @nobu * signal.c (interrupt_init): needs to pass nil for Interrupt.
nobu authored
292 rb_scan_args(argc, argv, "01", &args[1]);
293 return rb_call_super(2, args);
3fc37d7 @nobu * eval.c (ruby_cleanup): re-send signal. [ruby-dev:30516]
nobu authored
294 }
295
296 void
297 ruby_default_signal(int sig)
298 {
299 signal(sig, SIG_DFL);
300 raise(sig);
301 }
302
303 /*
88c127c Finish documenting internal stuff. See Changelog for other details
dave authored
304 * call-seq:
7729de4 @marcandre * array.c: Documentation: change => in call-seq to ->.
marcandre authored
305 * Process.kill(signal, pid, ...) -> fixnum
12d2c8b @nobu stripped trailing spaces.
nobu authored
306 *
88c127c Finish documenting internal stuff. See Changelog for other details
dave authored
307 * Sends the given signal to the specified process id(s), or to the
308 * current process if _pid_ is zero. _signal_ may be an
309 * integer signal number or a POSIX signal name (either with or without
310 * a +SIG+ prefix). If _signal_ is negative (or starts
311 * with a minus sign), kills process groups instead of
312 * processes. Not all signals are available on all platforms.
12d2c8b @nobu stripped trailing spaces.
nobu authored
313 *
88c127c Finish documenting internal stuff. See Changelog for other details
dave authored
314 * pid = fork do
315 * Signal.trap("HUP") { puts "Ouch!"; exit }
316 * # ... do some work ...
317 * end
318 * # ...
319 * Process.kill("HUP", pid)
320 * Process.wait
12d2c8b @nobu stripped trailing spaces.
nobu authored
321 *
88c127c Finish documenting internal stuff. See Changelog for other details
dave authored
322 * <em>produces:</em>
12d2c8b @nobu stripped trailing spaces.
nobu authored
323 *
88c127c Finish documenting internal stuff. See Changelog for other details
dave authored
324 * Ouch!
6b60792 @nobu * signal.c (rb_f_kill): added rdoc about exceptions.
nobu authored
325 *
326 * If _signal_ is an integer but wrong for signal,
327 * <code>Errno::EINVAL</code> or +RangeError+ will be raised.
328 * Otherwise unless _signal_ is a +String+ or a +Symbol+, and a known
b9e0294 @akr fix typos.
akr authored
329 * signal name, +ArgumentError+ will be raised.
6b60792 @nobu * signal.c (rb_f_kill): added rdoc about exceptions.
nobu authored
330 *
331 * Also, <code>Errno::ESRCH</code> or +RangeError+ for invalid _pid_,
332 * <code>Errno::EPERM</code> when failed because of no privilege,
333 * will be raised. In these cases, signals may have been sent to
334 * preceding processes.
88c127c Finish documenting internal stuff. See Changelog for other details
dave authored
335 */
336
3db12e8 Initial revision
matz authored
337 VALUE
dda5dc0 * array.c: moved to ANSI function style from K&R function style.
ocean authored
338 rb_f_kill(int argc, VALUE *argv)
3db12e8 Initial revision
matz authored
339 {
3fc37d7 @nobu * eval.c (ruby_cleanup): re-send signal. [ruby-dev:30516]
nobu authored
340 #ifndef HAS_KILLPG
fc38c70 @akr * signal.c: parenthesize macro arguments.
akr authored
341 #define killpg(pg, sig) kill(-(pg), (sig))
3fc37d7 @nobu * eval.c (ruby_cleanup): re-send signal. [ruby-dev:30516]
nobu authored
342 #endif
210367e This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
343 int negative = 0;
3db12e8 Initial revision
matz authored
344 int sig;
345 int i;
29c2876 @nagachika * signal.c (rb_f_kill): accept '-SIGXXX' style signal with Symbol or
nagachika authored
346 volatile VALUE str;
9b383bd * sprintf.c (rb_str_format): allow %c to print one character
matz authored
347 const char *s;
3db12e8 Initial revision
matz authored
348
349 rb_secure(2);
7316302 @marcandre * include/ruby/intern.h: Add rb_check_arity, rb_error_arity [#6085]
marcandre authored
350 rb_check_arity(argc, 2, UNLIMITED_ARGUMENTS);
351
3db12e8 Initial revision
matz authored
352 switch (TYPE(argv[0])) {
353 case T_FIXNUM:
f1bb1f5 000919
matz authored
354 sig = FIX2INT(argv[0]);
3db12e8 Initial revision
matz authored
355 break;
356
31c5530 2000-03-13
matz authored
357 case T_SYMBOL:
358 s = rb_id2name(SYM2ID(argv[0]));
359 if (!s) rb_raise(rb_eArgError, "bad signal");
360 goto str_signal;
361
3db12e8 Initial revision
matz authored
362 case T_STRING:
54af808 * ruby.h (struct RString): embed small strings.
matz authored
363 s = RSTRING_PTR(argv[0]);
29c2876 @nagachika * signal.c (rb_f_kill): accept '-SIGXXX' style signal with Symbol or
nagachika authored
364 str_signal:
86c6af5 * marshal.c (w_object): module inclusion using extend() should
matz authored
365 if (s[0] == '-') {
366 negative++;
367 s++;
3db12e8 Initial revision
matz authored
368 }
86c6af5 * marshal.c (w_object): module inclusion using extend() should
matz authored
369 if (strncmp("SIG", s, 3) == 0)
370 s += 3;
371 if((sig = signm2signo(s)) == 0)
372 rb_raise(rb_eArgError, "unsupported name `SIG%s'", s);
373
374 if (negative)
375 sig = -sig;
3db12e8 Initial revision
matz authored
376 break;
377
378 default:
29c2876 @nagachika * signal.c (rb_f_kill): accept '-SIGXXX' style signal with Symbol or
nagachika authored
379 str = rb_check_string_type(argv[0]);
380 if (!NIL_P(str)) {
381 s = RSTRING_PTR(str);
382 goto str_signal;
86c6af5 * marshal.c (w_object): module inclusion using extend() should
matz authored
383 }
29c2876 @nagachika * signal.c (rb_f_kill): accept '-SIGXXX' style signal with Symbol or
nagachika authored
384 rb_raise(rb_eArgError, "bad signal type %s",
385 rb_obj_classname(argv[0]));
3db12e8 Initial revision
matz authored
386 break;
387 }
388
389 if (sig < 0) {
390 sig = -sig;
391 for (i=1; i<argc; i++) {
3fc37d7 @nobu * eval.c (ruby_cleanup): re-send signal. [ruby-dev:30516]
nobu authored
392 if (killpg(NUM2PIDT(argv[i]), sig) < 0)
3db12e8 Initial revision
matz authored
393 rb_sys_fail(0);
394 }
395 }
396 else {
397 for (i=1; i<argc; i++) {
3fc37d7 @nobu * eval.c (ruby_cleanup): re-send signal. [ruby-dev:30516]
nobu authored
398 if (kill(NUM2PIDT(argv[i]), sig) < 0)
3db12e8 Initial revision
matz authored
399 rb_sys_fail(0);
400 }
401 }
3fc37d7 @nobu * eval.c (ruby_cleanup): re-send signal. [ruby-dev:30516]
nobu authored
402 rb_thread_polling();
3db12e8 Initial revision
matz authored
403 return INT2FIX(i-1);
404 }
405
5c3fe0e @nobu * signal.c (signal_buff): made static. a patch by Tadashi Saito
nobu authored
406 static struct {
c5bf9ce @nobu * vm_core.h (struct rb_vm_struct): replaced signal staff with trap
nobu authored
407 rb_atomic_t cnt[RUBY_NSIG];
408 rb_atomic_t size;
409 } signal_buff;
3db12e8 Initial revision
matz authored
410
4f60a53 @eban * io.c (NOFILE): define NOFILE as 64 if not defined.
eban authored
411 #ifdef __dietlibc__
412 #define sighandler_t sh_t
413 #endif
414
ca32aea * dir.c: changed `foo (*bar)_((boo))' to `foo (*bar)(boo)`.
ocean authored
415 typedef RETSIGTYPE (*sighandler_t)(int);
423657b @nobu * signal.c (USE_SIGALTSTACK): only when SA_SIGINFO also is
nobu authored
416 #ifdef USE_SIGALTSTACK
550f10c @nobu * signal.c (ruby_sigaction_t): added.
nobu authored
417 typedef void ruby_sigaction_t(int, siginfo_t*, void*);
418 #define SIGINFO_ARG , siginfo_t *info, void *ctx
419 #else
420 typedef RETSIGTYPE ruby_sigaction_t(int);
421 #define SIGINFO_ARG
422 #endif
b03bdcd * eval.c (ruby_stop): should not trace error handler.
matz authored
423
68a75f1 * signal.c (register_sigaltstack): use alternative stack for
matz authored
424 #ifdef USE_SIGALTSTACK
425 /* alternate stack for SIGSEGV */
5058731 @mame * vm_core.c (rb_thread_struct): add a field for sigaltstack.
mame authored
426 void
427 rb_register_sigaltstack(rb_thread_t *th)
3380a05 * signal.c (register_sigaltstack): should not add external
matz authored
428 {
68a75f1 * signal.c (register_sigaltstack): use alternative stack for
matz authored
429 stack_t newSS, oldSS;
430
18bc6c3 @kosaki * vm.c (th_init): preallocate alternative stack.
kosaki authored
431 if (!th->altstack)
432 rb_bug("rb_register_sigaltstack: th->altstack not initialized\n");
68a75f1 * signal.c (register_sigaltstack): use alternative stack for
matz authored
433
18bc6c3 @kosaki * vm.c (th_init): preallocate alternative stack.
kosaki authored
434 newSS.ss_sp = th->altstack;
68a75f1 * signal.c (register_sigaltstack): use alternative stack for
matz authored
435 newSS.ss_size = ALT_STACK_SIZE;
436 newSS.ss_flags = 0;
437
4e21416 @akr * signal.c (register_sigaltstack): ignore sigaltstack error.
akr authored
438 sigaltstack(&newSS, &oldSS); /* ignore error. */
68a75f1 * signal.c (register_sigaltstack): use alternative stack for
matz authored
439 }
18bc6c3 @kosaki * vm.c (th_init): preallocate alternative stack.
kosaki authored
440 #endif /* USE_SIGALTSTACK */
68a75f1 * signal.c (register_sigaltstack): use alternative stack for
matz authored
441
76bc2d1 @yugui Imports Ruby's port to NativeClient (a.k.a NaCl).
yugui authored
442 #ifdef POSIX_SIGNAL
b03bdcd * eval.c (ruby_stop): should not trace error handler.
matz authored
443 static sighandler_t
59ffb8a * intern.h, eval.c (rb_thread_signal_raise): costified.
ocean authored
444 ruby_signal(int signum, sighandler_t handler)
3db12e8 Initial revision
matz authored
445 {
b03bdcd * eval.c (ruby_stop): should not trace error handler.
matz authored
446 struct sigaction sigact, old;
3db12e8 Initial revision
matz authored
447
e615e3c @nobu * error.c (builtin_types), signal.c (siglist), st.c (primes),
nobu authored
448 #if 0
7e70ac9 * signal.c: Standard signal handlers ignore signals on non-Ruby native
nagai authored
449 rb_trap_accept_nativethreads[signum] = 0;
e615e3c @nobu * error.c (builtin_types), signal.c (siglist), st.c (primes),
nobu authored
450 #endif
7e70ac9 * signal.c: Standard signal handlers ignore signals on non-Ruby native
nagai authored
451
3db12e8 Initial revision
matz authored
452 sigemptyset(&sigact.sa_mask);
a5eb40b @nobu * signal.c (ruby_signal): fix condition.
nobu authored
453 #ifdef USE_SIGALTSTACK
550f10c @nobu * signal.c (ruby_sigaction_t): added.
nobu authored
454 sigact.sa_sigaction = (ruby_sigaction_t*)handler;
da42035 * signal.c (ruby_signal): use SA_SIGINFO if available.
matz authored
455 sigact.sa_flags = SA_SIGINFO;
456 #else
457 sigact.sa_handler = handler;
3db12e8 Initial revision
matz authored
458 sigact.sa_flags = 0;
da42035 * signal.c (ruby_signal): use SA_SIGINFO if available.
matz authored
459 #endif
460
be1fea0 19991012
matz authored
461 #ifdef SA_NOCLDWAIT
2e23ebc *** empty log message ***
matz authored
462 if (signum == SIGCHLD && handler == SIG_IGN)
be1fea0 19991012
matz authored
463 sigact.sa_flags |= SA_NOCLDWAIT;
464 #endif
68a75f1 * signal.c (register_sigaltstack): use alternative stack for
matz authored
465 #if defined(SA_ONSTACK) && defined(USE_SIGALTSTACK)
5a73c71 @kosaki * thread_pthread.c (get_stack): add to a care of gurad page on Mac
kosaki authored
466 if (signum == SIGSEGV || signum == SIGBUS)
ab9fd5d @nobu * signal.c (register_sigaltstack): stores alt stack for debug
nobu authored
467 sigact.sa_flags |= SA_ONSTACK;
68a75f1 * signal.c (register_sigaltstack): use alternative stack for
matz authored
468 #endif
782576a * ext/curses/curses.c (window_getch): avoid ISPRINT() macro which
matz authored
469 if (sigaction(signum, &sigact, &old) < 0) {
470 if (errno != 0 && errno != EINVAL) {
ff9d908 @akr * include/ruby/ruby.h (rb_bug_errno): declared.
akr authored
471 rb_bug_errno("sigaction", errno);
782576a * ext/curses/curses.c (window_getch): avoid ISPRINT() macro which
matz authored
472 }
473 }
b03bdcd * eval.c (ruby_stop): should not trace error handler.
matz authored
474 return old.sa_handler;
475 }
476
da42035 * signal.c (ruby_signal): use SA_SIGINFO if available.
matz authored
477 sighandler_t
59ffb8a * intern.h, eval.c (rb_thread_signal_raise): costified.
ocean authored
478 posix_signal(int signum, sighandler_t handler)
b03bdcd * eval.c (ruby_stop): should not trace error handler.
matz authored
479 {
1dd06c4 @akr * signal.c (posix_signal): return value.
akr authored
480 return ruby_signal(signum, handler);
3db12e8 Initial revision
matz authored
481 }
7e70ac9 * signal.c: Standard signal handlers ignore signals on non-Ruby native
nagai authored
482
483 #else /* !POSIX_SIGNAL */
fc38c70 @akr * signal.c: parenthesize macro arguments.
akr authored
484 #define ruby_signal(sig,handler) (/* rb_trap_accept_nativethreads[(sig)] = 0,*/ signal((sig),(handler)))
e615e3c @nobu * error.c (builtin_types), signal.c (siglist), st.c (primes),
nobu authored
485 #if 0 /* def HAVE_NATIVETHREAD */
6f6b9a9 @nobu * signal.c (ruby_signal, ruby_nativethread_signal): must be valid as
nobu authored
486 static sighandler_t
dda5dc0 * array.c: moved to ANSI function style from K&R function style.
ocean authored
487 ruby_nativethread_signal(int signum, sighandler_t handler)
6f6b9a9 @nobu * signal.c (ruby_signal, ruby_nativethread_signal): must be valid as
nobu authored
488 {
489 sighandler_t old;
490
491 old = signal(signum, handler);
492 rb_trap_accept_nativethreads[signum] = 1;
493 return old;
494 }
7e70ac9 * signal.c: Standard signal handlers ignore signals on non-Ruby native
nagai authored
495 #endif
3db12e8 Initial revision
matz authored
496 #endif
497
a3e1b1c @ko1 * Merge YARV
ko1 authored
498 static RETSIGTYPE
499 sighandler(int sig)
65a5162 1.4.0
matz authored
500 {
c5bf9ce @nobu * vm_core.h (struct rb_vm_struct): replaced signal staff with trap
nobu authored
501 ATOMIC_INC(signal_buff.cnt[sig]);
502 ATOMIC_INC(signal_buff.size);
d1d5d5e @ko1 * thread_pthread.c: Stop polling in the timer thread when there are
ko1 authored
503 rb_thread_wakeup_timer_thread();
3207cd3 @unak * signal.c (sighandler): need to re-install sighandler on some
unak authored
504 #if !defined(BSD_SIGNAL) && !defined(POSIX_SIGNAL)
505 ruby_signal(sig, sighandler);
506 #endif
65a5162 1.4.0
matz authored
507 }
210367e This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
508
d4b3e8a @nurse * signal.c (rb_signal_buff_size): defined for check whether signal
nurse authored
509 int
845103b @nobu * cont.c (rb_fiber_current), dln.c (dln_print_undef, dln_undefined),
nobu authored
510 rb_signal_buff_size(void)
d4b3e8a @nurse * signal.c (rb_signal_buff_size): defined for check whether signal
nurse authored
511 {
512 return signal_buff.size;
513 }
514
a3e1b1c @ko1 * Merge YARV
ko1 authored
515 #if HAVE_PTHREAD_H
516 #include <pthread.h>
4a774a7 @akr banish a warning.
akr authored
517 #endif
9815949 * eval.c (ruby_native_thread_kill): call pthread_kill() to send a
nagai authored
518
74b339e @kosaki * thread_pthread.c (rb_thread_create_timer_thread): removed
kosaki authored
519 static void
a3e1b1c @ko1 * Merge YARV
ko1 authored
520 rb_disable_interrupt(void)
3db12e8 Initial revision
matz authored
521 {
6bdeed2 @nobu * signal.c (rb_disable_interrupt, rb_enable_interrupt): see
nobu authored
522 #if USE_TRAP_MASK
a3e1b1c @ko1 * Merge YARV
ko1 authored
523 sigset_t mask;
524 sigfillset(&mask);
525 pthread_sigmask(SIG_SETMASK, &mask, NULL);
7e70ac9 * signal.c: Standard signal handlers ignore signals on non-Ruby native
nagai authored
526 #endif
a3e1b1c @ko1 * Merge YARV
ko1 authored
527 }
7e70ac9 * signal.c: Standard signal handlers ignore signals on non-Ruby native
nagai authored
528
74b339e @kosaki * thread_pthread.c (rb_thread_create_timer_thread): removed
kosaki authored
529 static void
a3e1b1c @ko1 * Merge YARV
ko1 authored
530 rb_enable_interrupt(void)
531 {
6bdeed2 @nobu * signal.c (rb_disable_interrupt, rb_enable_interrupt): see
nobu authored
532 #if USE_TRAP_MASK
a3e1b1c @ko1 * Merge YARV
ko1 authored
533 sigset_t mask;
534 sigemptyset(&mask);
535 pthread_sigmask(SIG_SETMASK, &mask, NULL);
3db12e8 Initial revision
matz authored
536 #endif
a3e1b1c @ko1 * Merge YARV
ko1 authored
537 }
3db12e8 Initial revision
matz authored
538
a3e1b1c @ko1 * Merge YARV
ko1 authored
539 int
c5bf9ce @nobu * vm_core.h (struct rb_vm_struct): replaced signal staff with trap
nobu authored
540 rb_get_next_signal(void)
a3e1b1c @ko1 * Merge YARV
ko1 authored
541 {
542 int i, sig = 0;
543
fa4514e @ko1 * thread.c (rb_threadptr_check_signal): only wake up main thread.
ko1 authored
544 if (signal_buff.size != 0) {
545 for (i=1; i<RUBY_NSIG; i++) {
546 if (signal_buff.cnt[i] > 0) {
547 rb_disable_interrupt();
548 {
549 ATOMIC_DEC(signal_buff.cnt[i]);
550 ATOMIC_DEC(signal_buff.size);
551 }
552 rb_enable_interrupt();
553 sig = i;
554 break;
a3e1b1c @ko1 * Merge YARV
ko1 authored
555 }
556 }
3db12e8 Initial revision
matz authored
557 }
a3e1b1c @ko1 * Merge YARV
ko1 authored
558 return sig;
3db12e8 Initial revision
matz authored
559 }
560
561 #ifdef SIGBUS
562 static RETSIGTYPE
5a73c71 @kosaki * thread_pthread.c (get_stack): add to a care of gurad page on Mac
kosaki authored
563 sigbus(int sig SIGINFO_ARG)
3db12e8 Initial revision
matz authored
564 {
5a73c71 @kosaki * thread_pthread.c (get_stack): add to a care of gurad page on Mac
kosaki authored
565 /*
566 * Mac OS X makes KERN_PROTECTION_FAILURE when thread touch guard page.
567 * and it's delivered as SIGBUS instaed of SIGSEGV to userland. It's crazy
568 * wrong IMHO. but anyway we have to care it. Sigh.
569 */
570 #if defined __MACH__ && defined __APPLE__ && defined USE_SIGALTSTACK
571 int ruby_stack_overflowed_p(const rb_thread_t *, const void *);
572 NORETURN(void ruby_thread_stack_overflow(rb_thread_t *th));
573 rb_thread_t *th = GET_THREAD();
574 if (ruby_stack_overflowed_p(th, info->si_addr)) {
575 ruby_thread_stack_overflow(th);
576 }
577 #endif
210367e This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
578 rb_bug("Bus Error");
3db12e8 Initial revision
matz authored
579 }
580 #endif
581
582 #ifdef SIGSEGV
a3e1b1c @ko1 * Merge YARV
ko1 authored
583 static int segv_received = 0;
3db12e8 Initial revision
matz authored
584 static RETSIGTYPE
7348aa6 @nobu * gc.c (ruby_stack_check): no check if using sigaltstack.
nobu authored
585 sigsegv(int sig SIGINFO_ARG)
3db12e8 Initial revision
matz authored
586 {
7348aa6 @nobu * gc.c (ruby_stack_check): no check if using sigaltstack.
nobu authored
587 #ifdef USE_SIGALTSTACK
588 int ruby_stack_overflowed_p(const rb_thread_t *, const void *);
589 NORETURN(void ruby_thread_stack_overflow(rb_thread_t *th));
590 rb_thread_t *th = GET_THREAD();
591 if (ruby_stack_overflowed_p(th, info->si_addr)) {
592 ruby_thread_stack_overflow(th);
593 }
594 #endif
a3e1b1c @ko1 * Merge YARV
ko1 authored
595 if (segv_received) {
b9e0294 @akr fix typos.
akr authored
596 fprintf(stderr, "SEGV received in SEGV handler\n");
2acd615 @kosaki * signal.c (sigsegv): use abort() instead of exit() when nested
kosaki authored
597 abort();
a3e1b1c @ko1 * Merge YARV
ko1 authored
598 }
599 else {
4641b80 @nobu * gc.c (ruby_gc_stress): moved to rb_objspace_t.
nobu authored
600 extern int ruby_disable_gc_stress;
a3e1b1c @ko1 * Merge YARV
ko1 authored
601 segv_received = 1;
4641b80 @nobu * gc.c (ruby_gc_stress): moved to rb_objspace_t.
nobu authored
602 ruby_disable_gc_stress = 1;
a3e1b1c @ko1 * Merge YARV
ko1 authored
603 rb_bug("Segmentation fault");
7e70ac9 * signal.c: Standard signal handlers ignore signals on non-Ruby native
nagai authored
604 }
3db12e8 Initial revision
matz authored
605 }
606 #endif
607
290569b @nobu * signal.c (trap): fixed segfaults. [ruby-dev:30830]
nobu authored
608 static void
c5bf9ce @nobu * vm_core.h (struct rb_vm_struct): replaced signal staff with trap
nobu authored
609 signal_exec(VALUE cmd, int safe, int sig)
290569b @nobu * signal.c (trap): fixed segfaults. [ruby-dev:30830]
nobu authored
610 {
29f5911 @ko1 * signal.c (signal_exec): execute rb_eval_cmd() directly.
ko1 authored
611 VALUE signum = INT2NUM(sig);
612 rb_eval_cmd(cmd, rb_ary_new3(1, signum), safe);
290569b @nobu * signal.c (trap): fixed segfaults. [ruby-dev:30830]
nobu authored
613 }
614
3db12e8 Initial revision
matz authored
615 void
dda5dc0 * array.c: moved to ANSI function style from K&R function style.
ocean authored
616 rb_trap_exit(void)
3db12e8 Initial revision
matz authored
617 {
c5bf9ce @nobu * vm_core.h (struct rb_vm_struct): replaced signal staff with trap
nobu authored
618 rb_vm_t *vm = GET_VM();
619 VALUE trap_exit = vm->trap_list[0].cmd;
f54418b matz
matz authored
620
c5bf9ce @nobu * vm_core.h (struct rb_vm_struct): replaced signal staff with trap
nobu authored
621 if (trap_exit) {
622 vm->trap_list[0].cmd = 0;
623 signal_exec(trap_exit, vm->trap_list[0].safe, 0);
210367e This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
624 }
3db12e8 Initial revision
matz authored
625 }
626
627 void
9c57438 @ko1 * blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
ko1 authored
628 rb_signal_exec(rb_thread_t *th, int sig)
a3e1b1c @ko1 * Merge YARV
ko1 authored
629 {
c5bf9ce @nobu * vm_core.h (struct rb_vm_struct): replaced signal staff with trap
nobu authored
630 rb_vm_t *vm = GET_VM();
631 VALUE cmd = vm->trap_list[sig].cmd;
632 int safe = vm->trap_list[sig].safe;
a3e1b1c @ko1 * Merge YARV
ko1 authored
633
205f310 @nobu * call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
nobu authored
634 if (cmd == 0) {
635 switch (sig) {
636 case SIGINT:
637 rb_interrupt();
638 break;
a3e1b1c @ko1 * Merge YARV
ko1 authored
639 #ifdef SIGHUP
205f310 @nobu * call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
nobu authored
640 case SIGHUP:
a3e1b1c @ko1 * Merge YARV
ko1 authored
641 #endif
642 #ifdef SIGQUIT
205f310 @nobu * call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
nobu authored
643 case SIGQUIT:
a3e1b1c @ko1 * Merge YARV
ko1 authored
644 #endif
3fc37d7 @nobu * eval.c (ruby_cleanup): re-send signal. [ruby-dev:30516]
nobu authored
645 #ifdef SIGTERM
646 case SIGTERM:
647 #endif
a3e1b1c @ko1 * Merge YARV
ko1 authored
648 #ifdef SIGALRM
205f310 @nobu * call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
nobu authored
649 case SIGALRM:
a3e1b1c @ko1 * Merge YARV
ko1 authored
650 #endif
651 #ifdef SIGUSR1
205f310 @nobu * call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
nobu authored
652 case SIGUSR1:
a3e1b1c @ko1 * Merge YARV
ko1 authored
653 #endif
654 #ifdef SIGUSR2
205f310 @nobu * call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
nobu authored
655 case SIGUSR2:
a3e1b1c @ko1 * Merge YARV
ko1 authored
656 #endif
79b62da @ko1 * thread.c: rename functions which require a parameter
ko1 authored
657 rb_threadptr_signal_raise(th, sig);
205f310 @nobu * call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
nobu authored
658 break;
659 }
660 }
661 else if (cmd == Qundef) {
79b62da @ko1 * thread.c: rename functions which require a parameter
ko1 authored
662 rb_threadptr_signal_exit(th);
205f310 @nobu * call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
nobu authored
663 }
664 else {
c5bf9ce @nobu * vm_core.h (struct rb_vm_struct): replaced signal staff with trap
nobu authored
665 signal_exec(cmd, safe, sig);
a3e1b1c @ko1 * Merge YARV
ko1 authored
666 }
667 }
668
3db12e8 Initial revision
matz authored
669 struct trap_arg {
82f631a @nobu * configure.in (sigsetmask): check when signal semantics is not POSIX.
nobu authored
670 #if USE_TRAP_MASK
3db12e8 Initial revision
matz authored
671 sigset_t mask;
672 #endif
290569b @nobu * signal.c (trap): fixed segfaults. [ruby-dev:30830]
nobu authored
673 int sig;
674 sighandler_t func;
675 VALUE cmd;
3db12e8 Initial revision
matz authored
676 };
677
787f96e @akr * signal.c (default_handler): func argument removed.
akr authored
678 static sighandler_t
679 default_handler(int sig)
680 {
681 sighandler_t func;
682 switch (sig) {
683 case SIGINT:
684 #ifdef SIGHUP
685 case SIGHUP:
686 #endif
687 #ifdef SIGQUIT
688 case SIGQUIT:
689 #endif
690 #ifdef SIGTERM
691 case SIGTERM:
692 #endif
693 #ifdef SIGALRM
694 case SIGALRM:
695 #endif
696 #ifdef SIGUSR1
697 case SIGUSR1:
698 #endif
699 #ifdef SIGUSR2
700 case SIGUSR2:
701 #endif
702 func = sighandler;
703 break;
704 #ifdef SIGBUS
705 case SIGBUS:
5a73c71 @kosaki * thread_pthread.c (get_stack): add to a care of gurad page on Mac
kosaki authored
706 func = (sighandler_t)sigbus;
787f96e @akr * signal.c (default_handler): func argument removed.
akr authored
707 break;
708 #endif
709 #ifdef SIGSEGV
710 case SIGSEGV:
7348aa6 @nobu * gc.c (ruby_stack_check): no check if using sigaltstack.
nobu authored
711 func = (sighandler_t)sigsegv;
13a7994 @unak * signal.c (register_sigaltstack): no need to define on non-sigaltstack
unak authored
712 # ifdef USE_SIGALTSTACK
5058731 @mame * vm_core.c (rb_thread_struct): add a field for sigaltstack.
mame authored
713 rb_register_sigaltstack(GET_THREAD());
13a7994 @unak * signal.c (register_sigaltstack): no need to define on non-sigaltstack
unak authored
714 # endif
787f96e @akr * signal.c (default_handler): func argument removed.
akr authored
715 break;
716 #endif
717 #ifdef SIGPIPE
718 case SIGPIPE:
e39b50d @kosaki * signal.c (Init_signal, default_handler): change default SIGPIPE handle...
kosaki authored
719 func = SIG_IGN;
787f96e @akr * signal.c (default_handler): func argument removed.
akr authored
720 break;
721 #endif
722 default:
723 func = SIG_DFL;
724 break;
725 }
726
727 return func;
728 }
729
290569b @nobu * signal.c (trap): fixed segfaults. [ruby-dev:30830]
nobu authored
730 static sighandler_t
787f96e @akr * signal.c (default_handler): func argument removed.
akr authored
731 trap_handler(VALUE *cmd, int sig)
3db12e8 Initial revision
matz authored
732 {
1b2af06 @nobu * signal.c (signal_exec, trap_handler): trap accepts a string as
nobu authored
733 sighandler_t func = sighandler;
290569b @nobu * signal.c (trap): fixed segfaults. [ruby-dev:30830]
nobu authored
734 VALUE command;
3db12e8 Initial revision
matz authored
735
290569b @nobu * signal.c (trap): fixed segfaults. [ruby-dev:30830]
nobu authored
736 if (NIL_P(*cmd)) {
3db12e8 Initial revision
matz authored
737 func = SIG_IGN;
738 }
639bd5e * eval.c (rb_eval): pre-evaluate argument for unambiguous
matz authored
739 else {
290569b @nobu * signal.c (trap): fixed segfaults. [ruby-dev:30830]
nobu authored
740 command = rb_check_string_type(*cmd);
9e22c83 @nobu * signal.c (trap_handler): also accepts symbols. [ruby-dev:37823]
nobu authored
741 if (NIL_P(command) && SYMBOL_P(*cmd)) {
742 command = rb_id2str(SYM2ID(*cmd));
743 if (!command) rb_raise(rb_eArgError, "bad handler");
744 }
639bd5e * eval.c (rb_eval): pre-evaluate argument for unambiguous
matz authored
745 if (!NIL_P(command)) {
746 SafeStringValue(command); /* taint check */
1b2af06 @nobu * signal.c (signal_exec, trap_handler): trap accepts a string as
nobu authored
747 *cmd = command;
54af808 * ruby.h (struct RString): embed small strings.
matz authored
748 switch (RSTRING_LEN(command)) {
639bd5e * eval.c (rb_eval): pre-evaluate argument for unambiguous
matz authored
749 case 0:
787f96e @akr * signal.c (default_handler): func argument removed.
akr authored
750 goto sig_ign;
639bd5e * eval.c (rb_eval): pre-evaluate argument for unambiguous
matz authored
751 break;
787f96e @akr * signal.c (default_handler): func argument removed.
akr authored
752 case 14:
753 if (strncmp(RSTRING_PTR(command), "SYSTEM_DEFAULT", 14) == 0) {
754 func = SIG_DFL;
755 *cmd = 0;
756 }
757 break;
639bd5e * eval.c (rb_eval): pre-evaluate argument for unambiguous
matz authored
758 case 7:
54af808 * ruby.h (struct RString): embed small strings.
matz authored
759 if (strncmp(RSTRING_PTR(command), "SIG_IGN", 7) == 0) {
787f96e @akr * signal.c (default_handler): func argument removed.
akr authored
760 sig_ign:
761 func = SIG_IGN;
762 *cmd = 0;
639bd5e * eval.c (rb_eval): pre-evaluate argument for unambiguous
matz authored
763 }
54af808 * ruby.h (struct RString): embed small strings.
matz authored
764 else if (strncmp(RSTRING_PTR(command), "SIG_DFL", 7) == 0) {
787f96e @akr * signal.c (default_handler): func argument removed.
akr authored
765 sig_dfl:
766 func = default_handler(sig);
767 *cmd = 0;
639bd5e * eval.c (rb_eval): pre-evaluate argument for unambiguous
matz authored
768 }
54af808 * ruby.h (struct RString): embed small strings.
matz authored
769 else if (strncmp(RSTRING_PTR(command), "DEFAULT", 7) == 0) {
787f96e @akr * signal.c (default_handler): func argument removed.
akr authored
770 goto sig_dfl;
639bd5e * eval.c (rb_eval): pre-evaluate argument for unambiguous
matz authored
771 }
772 break;
773 case 6:
54af808 * ruby.h (struct RString): embed small strings.
matz authored
774 if (strncmp(RSTRING_PTR(command), "IGNORE", 6) == 0) {
787f96e @akr * signal.c (default_handler): func argument removed.
akr authored
775 goto sig_ign;
639bd5e * eval.c (rb_eval): pre-evaluate argument for unambiguous
matz authored
776 }
777 break;
778 case 4:
54af808 * ruby.h (struct RString): embed small strings.
matz authored
779 if (strncmp(RSTRING_PTR(command), "EXIT", 4) == 0) {
290569b @nobu * signal.c (trap): fixed segfaults. [ruby-dev:30830]
nobu authored
780 *cmd = Qundef;
639bd5e * eval.c (rb_eval): pre-evaluate argument for unambiguous
matz authored
781 }
782 break;
3db12e8 Initial revision
matz authored
783 }
290569b @nobu * signal.c (trap): fixed segfaults. [ruby-dev:30830]
nobu authored
784 }
785 else {
786 rb_proc_t *proc;
787 GetProcPtr(*cmd, proc);
b526738 @nobu * bignum.c (big_rshift), compile.c (validate_label,
nobu authored
788 (void)proc;
3db12e8 Initial revision
matz authored
789 }
790 }
791
290569b @nobu * signal.c (trap): fixed segfaults. [ruby-dev:30830]
nobu authored
792 return func;
793 }
794
795 static int
796 trap_signm(VALUE vsig)
797 {
798 int sig = -1;
799 const char *s;
800
801 switch (TYPE(vsig)) {
7194267 2000-04-10
matz authored
802 case T_FIXNUM:
290569b @nobu * signal.c (trap): fixed segfaults. [ruby-dev:30830]
nobu authored
803 sig = FIX2INT(vsig);
804 if (sig < 0 || sig >= NSIG) {
805 rb_raise(rb_eArgError, "invalid signal number (%d)", sig);
806 }
7194267 2000-04-10
matz authored
807 break;
808
809 case T_SYMBOL:
290569b @nobu * signal.c (trap): fixed segfaults. [ruby-dev:30830]
nobu authored
810 s = rb_id2name(SYM2ID(vsig));
7194267 2000-04-10
matz authored
811 if (!s) rb_raise(rb_eArgError, "bad signal");
812 goto str_signal;
813
290569b @nobu * signal.c (trap): fixed segfaults. [ruby-dev:30830]
nobu authored
814 default:
815 s = StringValuePtr(vsig);
3db12e8 Initial revision
matz authored
816
7194267 2000-04-10
matz authored
817 str_signal:
3db12e8 Initial revision
matz authored
818 if (strncmp("SIG", s, 3) == 0)
819 s += 3;
820 sig = signm2signo(s);
821 if (sig == 0 && strcmp(s, "EXIT") != 0)
d497898 * eval.c (cvar_cbase): utility function to find innermost non
matz authored
822 rb_raise(rb_eArgError, "unsupported signal SIG%s", s);
3db12e8 Initial revision
matz authored
823 }
290569b @nobu * signal.c (trap): fixed segfaults. [ruby-dev:30830]
nobu authored
824 return sig;
825 }
826
827 static VALUE
828 trap(struct trap_arg *arg)
829 {
830 sighandler_t oldfunc, func = arg->func;
831 VALUE oldcmd, command = arg->cmd;
832 int sig = arg->sig;
c5bf9ce @nobu * vm_core.h (struct rb_vm_struct): replaced signal staff with trap
nobu authored
833 rb_vm_t *vm = GET_VM();
290569b @nobu * signal.c (trap): fixed segfaults. [ruby-dev:30830]
nobu authored
834
80a97f1 * signal.c (trap): return "DEFAULT" and "IGNORE" respectively for
matz authored
835 oldfunc = ruby_signal(sig, func);
c5bf9ce @nobu * vm_core.h (struct rb_vm_struct): replaced signal staff with trap
nobu authored
836 oldcmd = vm->trap_list[sig].cmd;
290569b @nobu * signal.c (trap): fixed segfaults. [ruby-dev:30830]
nobu authored
837 switch (oldcmd) {
838 case 0:
80a97f1 * signal.c (trap): return "DEFAULT" and "IGNORE" respectively for
matz authored
839 if (oldfunc == SIG_IGN) oldcmd = rb_str_new2("IGNORE");
840 else if (oldfunc == sighandler) oldcmd = rb_str_new2("DEFAULT");
841 else oldcmd = Qnil;
290569b @nobu * signal.c (trap): fixed segfaults. [ruby-dev:30830]
nobu authored
842 break;
843 case Qundef:
844 oldcmd = rb_str_new2("EXIT");
845 break;
80a97f1 * signal.c (trap): return "DEFAULT" and "IGNORE" respectively for
matz authored
846 }
3db12e8 Initial revision
matz authored
847
c5bf9ce @nobu * vm_core.h (struct rb_vm_struct): replaced signal staff with trap
nobu authored
848 vm->trap_list[sig].cmd = command;
849 vm->trap_list[sig].safe = rb_safe_level();
3db12e8 Initial revision
matz authored
850 /* enable at least specified signal. */
82f631a @nobu * configure.in (sigsetmask): check when signal semantics is not POSIX.
nobu authored
851 #if USE_TRAP_MASK
3db12e8 Initial revision
matz authored
852 sigdelset(&arg->mask, sig);
853 #endif
80a97f1 * signal.c (trap): return "DEFAULT" and "IGNORE" respectively for
matz authored
854 return oldcmd;
3db12e8 Initial revision
matz authored
855 }
856
82f631a @nobu * configure.in (sigsetmask): check when signal semantics is not POSIX.
nobu authored
857 #if USE_TRAP_MASK
210367e This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
858 static VALUE
59ffb8a * intern.h, eval.c (rb_thread_signal_raise): costified.
ocean authored
859 trap_ensure(struct trap_arg *arg)
3db12e8 Initial revision
matz authored
860 {
861 /* enable interrupt */
8687db6 @mame * process.c (rb_f_fork): remove after_exec() which sometimes caused
mame authored
862 pthread_sigmask(SIG_SETMASK, &arg->mask, NULL);
210367e This commit was generated by cvs2svn to compensate for changes in r372,
matz authored
863 return 0;
3db12e8 Initial revision
matz authored
864 }
865 #endif
866
bf0d8b7 @nobu * signal.c (reserved_signal_p): static.
nobu authored
867 static int
868 reserved_signal_p(int signo)
89e2951 @kosaki * signal.c (sig_trap): don't permit to change a signal handler which
kosaki authored
869 {
870 /* Synchronous signal can't deliver to main thread */
871 #ifdef SIGSEGV
872 if (signo == SIGSEGV)
873 return 1;
874 #endif
875 #ifdef SIGBUS
876 if (signo == SIGBUS)
877 return 1;
878 #endif
879 #ifdef SIGILL
880 if (signo == SIGILL)
881 return 1;
882 #endif
883 #ifdef SIGFPE
884 if (signo == SIGFPE)
885 return 1;
886 #endif
887
888 /* used ubf internal see thread_pthread.c. */
889 #ifdef SIGVTALRM
890 if (signo == SIGVTALRM)
891 return 1;
892 #endif
893
894 return 0;
895 }
896
75cc3e4 RDoc comments added by Elliott Hughes
dave authored
897 /*
898 * call-seq:
7729de4 @marcandre * array.c: Documentation: change => in call-seq to ->.
marcandre authored
899 * Signal.trap( signal, command ) -> obj
900 * Signal.trap( signal ) {| | block } -> obj
75cc3e4 RDoc comments added by Elliott Hughes
dave authored
901 *
902 * Specifies the handling of signals. The first parameter is a signal
903 * name (a string such as ``SIGALRM'', ``SIGUSR1'', and so on) or a
904 * signal number. The characters ``SIG'' may be omitted from the
905 * signal name. The command or block specifies code to be run when the
8092d0b @akr fix trap's doc.
akr authored
906 * signal is raised.
907 * If the command is the string ``IGNORE'' or ``SIG_IGN'', the signal
908 * will be ignored.
909 * If the command is ``DEFAULT'' or ``SIG_DFL'', the Ruby's default handler
910 * will be invoked.
911 * If the command is ``EXIT'', the script will be terminated by the signal.
787f96e @akr * signal.c (default_handler): func argument removed.
akr authored
912 * If the command is ``SYSTEM_DEFAULT'', the operating system's default
913 * handler will be invoked.
8092d0b @akr fix trap's doc.
akr authored
914 * Otherwise, the given command or block will be run.
75cc3e4 RDoc comments added by Elliott Hughes
dave authored
915 * The special signal name ``EXIT'' or signal number zero will be
916 * invoked just prior to program termination.
917 * trap returns the previous handler for the given signal.
918 *
919 * Signal.trap(0, proc { puts "Terminating: #{$$}" })
920 * Signal.trap("CLD") { puts "Child died" }
921 * fork && Process.wait
922 *
923 * produces:
924 * Terminating: 27461
925 * Child died
926 * Terminating: 27460
927 */
3db12e8 Initial revision
matz authored
928 static VALUE
dda5dc0 * array.c: moved to ANSI function style from K&R function style.
ocean authored
929 sig_trap(int argc, VALUE *argv)
3db12e8 Initial revision
matz authored
930 {
931 struct trap_arg arg;
932
933 rb_secure(2);
7316302 @marcandre * include/ruby/intern.h: Add rb_check_arity, rb_error_arity [#6085]
marcandre authored
934 rb_check_arity(argc, 1, 2);
3db12e8 Initial revision
matz authored
935
290569b @nobu * signal.c (trap): fixed segfaults. [ruby-dev:30830]
nobu authored
936 arg.sig = trap_signm(argv[0]);
89e2951 @kosaki * signal.c (sig_trap): don't permit to change a signal handler which
kosaki authored
937 if (reserved_signal_p(arg.sig)) {
57e95f8 @akr * signal.c (sig_trap): show signal name on error.
akr authored
938 const char *name = signo2signm(arg.sig);
939 if (name)
940 rb_raise(rb_eArgError, "can't trap reserved signal: SIG%s", name);
941 else
942 rb_raise(rb_eArgError, "can't trap reserved signal: %d", (int)arg.sig);
89e2951 @kosaki * signal.c (sig_trap): don't permit to change a signal handler which
kosaki authored
943 }
944
3db12e8 Initial revision
matz authored
945 if (argc == 1) {
590a378 * eval.c (proc_alloc): re-unification of Block and Proc. Block
matz authored
946 arg.cmd = rb_block_proc();
290569b @nobu * signal.c (trap): fixed segfaults. [ruby-dev:30830]
nobu authored
947 arg.func = sighandler;
3db12e8 Initial revision
matz authored
948 }
cb434b4 @nobu * signal.c (sig_trap): suppress warnings.
nobu authored
949 else {
3db12e8 Initial revision
matz authored
950 arg.cmd = argv[1];
787f96e @akr * signal.c (default_handler): func argument removed.
akr authored
951 arg.func = trap_handler(&arg.cmd, arg.sig);
3db12e8 Initial revision
matz authored
952 }
953
7422ccd * signal.c (sighandle): should not re-register sighandler if
matz authored
954 if (OBJ_TAINTED(arg.cmd)) {
955 rb_raise(rb_eSecurityError, "Insecure: tainted signal trap");
956 }
82f631a @nobu * configure.in (sigsetmask): check when signal semantics is not POSIX.
nobu authored
957 #if USE_TRAP_MASK
df52785 @kosaki * signal.c (sig_trap): avoid pthread_sigmask(xx, &mask, &mask) usage
kosaki authored
958 {
959 sigset_t fullmask;
960
961 /* disable interrupt */
962 sigfillset(&fullmask);
963 pthread_sigmask(SIG_BLOCK, &fullmask, &arg.mask);
3a47cf3 @nobu * remove trailing spaces.
nobu authored
964
df52785 @kosaki * signal.c (sig_trap): avoid pthread_sigmask(xx, &mask, &mask) usage
kosaki authored
965 return rb_ensure(trap, (VALUE)&arg, trap_ensure, (VALUE)&arg);
966 }
3db12e8 Initial revision
matz authored
967 #else
968 return trap(&arg);
969 #endif
970 }
971
75cc3e4 RDoc comments added by Elliott Hughes
dave authored
972 /*
973 * call-seq:
7729de4 @marcandre * array.c: Documentation: change => in call-seq to ->.
marcandre authored
974 * Signal.list -> a_hash
75cc3e4 RDoc comments added by Elliott Hughes
dave authored
975 *
976 * Returns a list of signal names mapped to the corresponding
977 * underlying signal numbers.
978 *
aaa90dd @akr update Signal.list rdoc.
akr authored
979 * Signal.list #=> {"EXIT"=>0, "HUP"=>1, "INT"=>2, "QUIT"=>3, "ILL"=>4, "TRAP"=>5, "IOT"=>6, "ABRT"=>6, "FPE"=>8, "KILL"=>9, "BUS"=>7, "SEGV"=>11, "SYS"=>31, "PIPE"=>13, "ALRM"=>14, "TERM"=>15, "URG"=>23, "STOP"=>19, "TSTP"=>20, "CONT"=>18, "CHLD"=>17, "CLD"=>17, "TTIN"=>21, "TTOU"=>22, "IO"=>29, "XCPU"=>24, "XFSZ"=>25, "VTALRM"=>26, "PROF"=>27, "WINCH"=>28, "USR1"=>10, "USR2"=>12, "PWR"=>30, "POLL"=>29}
75cc3e4 RDoc comments added by Elliott Hughes
dave authored
980 */
1289a7a * eval.c (is_defined): should not dump core for "defined?(())".
matz authored
981 static VALUE
dda5dc0 * array.c: moved to ANSI function style from K&R function style.
ocean authored
982 sig_list(void)
1289a7a * eval.c (is_defined): should not dump core for "defined?(())".
matz authored
983 {
984 VALUE h = rb_hash_new();
e615e3c @nobu * error.c (builtin_types), signal.c (siglist), st.c (primes),
nobu authored
985 const struct signals *sigs;
1289a7a * eval.c (is_defined): should not dump core for "defined?(())".
matz authored
986
987 for (sigs = siglist; sigs->signm; sigs++) {
988 rb_hash_aset(h, rb_str_new2(sigs->signm), INT2FIX(sigs->signo));
989 }
990 return h;
991 }
992
b03bdcd * eval.c (ruby_stop): should not trace error handler.
matz authored
993 static void
dda5dc0 * array.c: moved to ANSI function style from K&R function style.
ocean authored
994 install_sighandler(int signum, sighandler_t handler)
b03bdcd * eval.c (ruby_stop): should not trace error handler.
matz authored
995 {
996 sighandler_t old;
997
c307523 @kosaki * signal.c (install_sighandler): fixed a race.
kosaki authored
998 rb_disable_interrupt();
b03bdcd * eval.c (ruby_stop): should not trace error handler.
matz authored
999 old = ruby_signal(signum, handler);
1000 if (old != SIG_DFL) {
1001 ruby_signal(signum, old);
1002 }
c307523 @kosaki * signal.c (install_sighandler): fixed a race.
kosaki authored
1003 rb_enable_interrupt();
b03bdcd * eval.c (ruby_stop): should not trace error handler.
matz authored
1004 }
1005
87e4ad0 @nobu * io.c, signal.c, thread.c, thread_win32.c, include/ruby/intern.h:
nobu authored
1006 #if defined(SIGCLD) || defined(SIGCHLD)
ea03c3f configure.in, eval.c, signal.c: : add '--with-pthread-ext' option
nagai authored
1007 static void
dda5dc0 * array.c: moved to ANSI function style from K&R function style.
ocean authored
1008 init_sigchld(int sig)
ea03c3f configure.in, eval.c, signal.c: : add '--with-pthread-ext' option
nagai authored
1009 {
1010 sighandler_t oldfunc;
1011
7fd8266 @kosaki small cleanup
kosaki authored
1012 rb_disable_interrupt();
ea03c3f configure.in, eval.c, signal.c: : add '--with-pthread-ext' option
nagai authored
1013 oldfunc = ruby_signal(sig, SIG_DFL);
1014 if (oldfunc != SIG_DFL && oldfunc != SIG_IGN) {
1015 ruby_signal(sig, oldfunc);
1016 } else {
c5bf9ce @nobu * vm_core.h (struct rb_vm_struct): replaced signal staff with trap
nobu authored
1017 GET_VM()->trap_list[sig].cmd = 0;
ea03c3f configure.in, eval.c, signal.c: : add '--with-pthread-ext' option
nagai authored
1018 }
7fd8266 @kosaki small cleanup
kosaki authored
1019 rb_enable_interrupt();
ea03c3f configure.in, eval.c, signal.c: : add '--with-pthread-ext' option
nagai authored
1020 }
87e4ad0 @nobu * io.c, signal.c, thread.c, thread_win32.c, include/ruby/intern.h:
nobu authored
1021 #endif
ea03c3f configure.in, eval.c, signal.c: : add '--with-pthread-ext' option
nagai authored
1022
29c7c72 * signal.c (trap_signm): SIGVTALRM no longer used for green
matz authored
1023 void
845103b @nobu * cont.c (rb_fiber_current), dln.c (dln_print_undef, dln_undefined),
nobu authored
1024 ruby_sig_finalize(void)
29c7c72 * signal.c (trap_signm): SIGVTALRM no longer used for green
matz authored
1025 {
1026 sighandler_t oldfunc;
1027
1028 oldfunc = ruby_signal(SIGINT, SIG_IGN);
1029 if (oldfunc == sighandler) {
1030 ruby_signal(SIGINT, SIG_DFL);
1031 }
1032 }
1033
1034
eae8a91 @nobu * debug.c (ruby_set_debug_option): separated from main.c.
nobu authored
1035 int ruby_enable_coredump = 0;
8022385 @nobu * debug.c (ruby_set_debug_option): define always for binary
nobu authored
1036 #ifndef RUBY_DEBUG_ENV
1037 #define ruby_enable_coredump 0
dea470c @akr debug environment variable refined.
akr authored
1038 #endif
1039
75cc3e4 RDoc comments added by Elliott Hughes
dave authored
1040 /*
1041 * Many operating systems allow signals to be sent to running
1042 * processes. Some signals have a defined effect on the process, while
1043 * others may be trapped at the code level and acted upon. For
1044 * example, your process may trap the USR1 signal and use it to toggle
1045 * debugging, and may use TERM to initiate a controlled shutdown.
1046 *
1047 * pid = fork do
1048 * Signal.trap("USR1") do
1049 * $debug = !$debug
1050 * puts "Debug now: #$debug"
1051 * end
1052 * Signal.trap("TERM") do
1053 * puts "Terminating..."
1054 * shutdown()
1055 * end
1056 * # . . . do some work . . .
1057 * end
1058 *
1059 * Process.detach(pid)
1060 *
1061 * # Controlling program:
1062 * Process.kill("USR1", pid)
1063 * # ...
1064 * Process.kill("USR1", pid)
1065 * # ...
1066 * Process.kill("TERM", pid)
1067 *
1068 * produces:
1069 * Debug now: true
1070 * Debug now: false
1071 * Terminating...
1072 *
1073 * The list of available signal names and their interpretation is
1074 * system dependent. Signal delivery semantics may also vary between
1075 * systems; in particular signal delivery may not always be reliable.
1076 */
3db12e8 Initial revision
matz authored
1077 void
dda5dc0 * array.c: moved to ANSI function style from K&R function style.
ocean authored
1078 Init_signal(void)
3db12e8 Initial revision
matz authored
1079 {
1289a7a * eval.c (is_defined): should not dump core for "defined?(())".
matz authored
1080 VALUE mSignal = rb_define_module("Signal");
1081
1082 rb_define_global_function("trap", sig_trap, -1);
1083 rb_define_module_function(mSignal, "trap", sig_trap, -1);
1084 rb_define_module_function(mSignal, "list", sig_list, 0);
1085
3fc37d7 @nobu * eval.c (ruby_cleanup): re-send signal. [ruby-dev:30516]
nobu authored
1086 rb_define_method(rb_eSignal, "initialize", esignal_init, -1);
bd90304 @mame * signal.c (esignal_signo): fix SignalException#signo which returned
mame authored
1087 rb_define_method(rb_eSignal, "signo", esignal_signo, 0);
3fc37d7 @nobu * eval.c (ruby_cleanup): re-send signal. [ruby-dev:30516]
nobu authored
1088 rb_alias(rb_eSignal, rb_intern("signm"), rb_intern("message"));
1089 rb_define_method(rb_eInterrupt, "initialize", interrupt_init, -1);
1090
b03bdcd * eval.c (ruby_stop): should not trace error handler.
matz authored
1091 install_sighandler(SIGINT, sighandler);
6d53b69 @eban support mingw32.
eban authored
1092 #ifdef SIGHUP
b03bdcd * eval.c (ruby_stop): should not trace error handler.
matz authored
1093 install_sighandler(SIGHUP, sighandler);
65a5162 1.4.0
matz authored
1094 #endif
1095 #ifdef SIGQUIT
b03bdcd * eval.c (ruby_stop): should not trace error handler.
matz authored
1096 install_sighandler(SIGQUIT, sighandler);
65a5162 1.4.0
matz authored
1097 #endif
e18aabc @nobu * signal.c (Init_signal): handle SIGTERM. fixed: [ruby-list:42895]
nobu authored
1098 #ifdef SIGTERM
1099 install_sighandler(SIGTERM, sighandler);
1100 #endif
65a5162 1.4.0
matz authored
1101 #ifdef SIGALRM
b03bdcd * eval.c (ruby_stop): should not trace error handler.
matz authored
1102 install_sighandler(SIGALRM, sighandler);
65a5162 1.4.0
matz authored
1103 #endif
1104 #ifdef SIGUSR1
b03bdcd * eval.c (ruby_stop): should not trace error handler.
matz authored
1105 install_sighandler(SIGUSR1, sighandler);
65a5162 1.4.0
matz authored
1106 #endif
1107 #ifdef SIGUSR2
b03bdcd * eval.c (ruby_stop): should not trace error handler.
matz authored
1108 install_sighandler(SIGUSR2, sighandler);
3db12e8 Initial revision
matz authored
1109 #endif
65a5162 1.4.0
matz authored
1110
8022385 @nobu * debug.c (ruby_set_debug_option): define always for binary
nobu authored
1111 if (!ruby_enable_coredump) {
3db12e8 Initial revision
matz authored
1112 #ifdef SIGBUS
5a73c71 @kosaki * thread_pthread.c (get_stack): add to a care of gurad page on Mac
kosaki authored
1113 install_sighandler(SIGBUS, (sighandler_t)sigbus);
3db12e8 Initial revision
matz authored
1114 #endif
1115 #ifdef SIGSEGV
13a7994 @unak * signal.c (register_sigaltstack): no need to define on non-sigaltstack
unak authored
1116 # ifdef USE_SIGALTSTACK
8022385 @nobu * debug.c (ruby_set_debug_option): define always for binary
nobu authored
1117 rb_register_sigaltstack(GET_THREAD());
13a7994 @unak * signal.c (register_sigaltstack): no need to define on non-sigaltstack
unak authored
1118 # endif
8022385 @nobu * debug.c (ruby_set_debug_option): define always for binary
nobu authored
1119 install_sighandler(SIGSEGV, (sighandler_t)sigsegv);
3db12e8 Initial revision
matz authored
1120 #endif
dea470c @akr debug environment variable refined.
akr authored
1121 }
be1fea0 19991012
matz authored
1122 #ifdef SIGPIPE
e39b50d @kosaki * signal.c (Init_signal, default_handler): change default SIGPIPE handle...
kosaki authored
1123 install_sighandler(SIGPIPE, SIG_IGN);
be1fea0 19991012
matz authored
1124 #endif
ea03c3f configure.in, eval.c, signal.c: : add '--with-pthread-ext' option
nagai authored
1125
65aa6b9 * signal.c (Init_signal): avoid duplicated installation of SIGCHLD
matz authored
1126 #if defined(SIGCLD)
ea03c3f configure.in, eval.c, signal.c: : add '--with-pthread-ext' option
nagai authored
1127 init_sigchld(SIGCLD);
65aa6b9 * signal.c (Init_signal): avoid duplicated installation of SIGCHLD
matz authored
1128 #elif defined(SIGCHLD)
ea03c3f configure.in, eval.c, signal.c: : add '--with-pthread-ext' option
nagai authored
1129 init_sigchld(SIGCHLD);
1130 #endif
3db12e8 Initial revision
matz authored
1131 }
Something went wrong with that request. Please try again.