428
|
1 /* Handling asynchronous signals.
|
|
2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
|
593
|
3 Copyright (C) 1995, 1996, 2001 Ben Wing.
|
428
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Not synched with FSF. Split out of keyboard.c. */
|
|
23
|
|
24 #include <config.h>
|
|
25 #include "lisp.h"
|
|
26
|
|
27 #include "console.h"
|
|
28 #include "events.h" /* for signal_fake_event() */
|
|
29 #include "frame.h"
|
593
|
30 #include "process.h"
|
611
|
31
|
428
|
32 #include "sysdep.h"
|
611
|
33 #include "sysfile.h"
|
428
|
34 #include "syssignal.h"
|
|
35 #include "systime.h"
|
|
36
|
|
37 /* Set to 1 when a quit-check signal (either a SIGIO interrupt or
|
|
38 the asynch. timeout for poll-for-quit) occurs. The QUITP
|
|
39 macro may look at this. */
|
|
40 volatile int quit_check_signal_happened;
|
|
41
|
|
42 /* Count of the number of times a quit-check signal has occurred.
|
|
43 Some stuff in event-Xt.c looks at this. */
|
|
44 volatile int quit_check_signal_tick_count;
|
|
45
|
|
46 /* Set to 1 when a SIGINT (or SIGQUIT) interrupt is processed.
|
|
47 maybe_read_quit_event() looks at this. */
|
|
48 volatile int sigint_happened;
|
|
49
|
|
50 /* Set to 1 when an asynch. timeout signal occurs. */
|
593
|
51 static volatile int async_timeout_happened;
|
|
52
|
|
53 /* Set to 1 when a multiple of SLOWED_DOWN_INTERRUPTS_SECS elapses,
|
|
54 after slow_down_interrupts() is called. */
|
|
55 static volatile int slowed_interrupt_timeout_happened;
|
428
|
56
|
|
57 /* This is used to synchronize setting the waiting_for_user_input_p
|
|
58 flag. */
|
593
|
59 static volatile int async_timeout_happened_while_emacs_was_blocking;
|
428
|
60
|
|
61 /* See check_quit() for when this is set. */
|
|
62 int dont_check_for_quit;
|
|
63
|
593
|
64 static int poll_for_quit_id;
|
|
65 static int poll_for_sigchld_id;
|
428
|
66
|
|
67 /* This variable is used to communicate to a lisp
|
|
68 process-filter/sentinel/asynchronous callback (via the function
|
|
69 Fwaiting_for_user_input_p below) whether XEmacs was waiting for
|
|
70 user-input when that process-filter was called. */
|
|
71 static int waiting_for_user_input_p;
|
|
72
|
|
73 static int interrupts_slowed_down;
|
|
74
|
|
75 #define SLOWED_DOWN_INTERRUPTS_SECS 15
|
|
76 #define NORMAL_QUIT_CHECK_TIMEOUT_MSECS 250
|
|
77 #define NORMAL_SIGCHLD_CHECK_TIMEOUT_MSECS 250
|
|
78
|
|
79 /* Used so that signals can break out of system calls that aren't
|
|
80 naturally interruptible. */
|
|
81
|
|
82 JMP_BUF break_system_call_jump;
|
|
83 volatile int can_break_system_calls;
|
|
84
|
593
|
85 static SIGTYPE alarm_signal (int signo);
|
|
86
|
|
87
|
428
|
88
|
|
89 /**********************************************************************/
|
|
90 /* Asynchronous timeout functions */
|
|
91 /**********************************************************************/
|
|
92
|
593
|
93 /* See the comment in event-stream.c, under major heading "Timeouts",
|
|
94 for the difference between low-level (one-shot) and high-level
|
|
95 (periodic/resignaling) timeouts. */
|
|
96
|
428
|
97 /* The pending timers are stored in an ordered list, where the first timer
|
|
98 on the list is the first one to fire. Times recorded here are
|
|
99 absolute. */
|
|
100 static struct low_level_timeout *async_timer_queue;
|
|
101
|
|
102 /* Nonzero means async timers are temporarily suppressed. */
|
|
103 static int async_timer_suppress_count;
|
|
104
|
|
105 static void
|
|
106 set_one_shot_timer (EMACS_TIME interval)
|
|
107 {
|
|
108 #ifdef HAVE_SETITIMER
|
|
109 struct itimerval it;
|
|
110 it.it_value = interval;
|
|
111 EMACS_SET_SECS_USECS (it.it_interval, 0, 0);
|
611
|
112 qxe_setitimer (ITIMER_REAL, &it, 0);
|
428
|
113 #else
|
|
114 int secs;
|
|
115 EMACS_TIME_TO_INT (interval, secs);
|
|
116 alarm (secs);
|
|
117 #endif
|
|
118 }
|
|
119
|
|
120 static void
|
|
121 reset_interval_timer (void)
|
|
122 {
|
|
123 EMACS_TIME interval;
|
|
124
|
|
125 /* Get the interval to set. If an interval is available,
|
|
126 make sure it's not zero (this is a valid return, but it will
|
|
127 cause the timer to get disabled, so convert it to a very short
|
|
128 time). */
|
|
129 if (get_low_level_timeout_interval (async_timer_queue, &interval))
|
|
130 {
|
|
131 if (EMACS_SECS (interval) == 0 && EMACS_USECS (interval) == 0)
|
|
132 EMACS_SET_USECS (interval, 1);
|
|
133 }
|
|
134 else
|
|
135 /* A time of 0 means "disable". */
|
|
136 EMACS_SET_SECS_USECS (interval, 0, 0);
|
|
137
|
|
138 set_one_shot_timer (interval);
|
|
139 }
|
|
140
|
|
141
|
|
142 static void
|
|
143 init_async_timeouts (void)
|
|
144 {
|
613
|
145 set_timeout_signal (SIGALRM, alarm_signal);
|
428
|
146 async_timer_suppress_count = 0;
|
|
147 }
|
|
148
|
|
149 /* Turn off async timeouts. */
|
|
150
|
|
151 static void
|
|
152 stop_async_timeouts (void)
|
|
153 {
|
|
154 if (async_timer_suppress_count == 0)
|
|
155 {
|
|
156 /* If timer was on, turn it off. */
|
|
157 EMACS_TIME thyme;
|
|
158 EMACS_SET_SECS_USECS (thyme, 0, 0);
|
|
159 set_one_shot_timer (thyme);
|
|
160 }
|
|
161 async_timer_suppress_count++;
|
|
162 }
|
|
163
|
|
164 /* Turn on async timeouts again. */
|
|
165
|
|
166 static void
|
|
167 start_async_timeouts (void)
|
|
168 {
|
|
169 assert (async_timer_suppress_count > 0);
|
|
170 async_timer_suppress_count--;
|
|
171 if (async_timer_suppress_count == 0)
|
|
172 {
|
|
173 /* Some callers turn off async timeouts and then use the alarm
|
|
174 for their own purposes; so reinitialize everything. */
|
613
|
175 set_timeout_signal (SIGALRM, alarm_signal);
|
428
|
176 reset_interval_timer ();
|
|
177 }
|
|
178 }
|
|
179
|
593
|
180 static void
|
|
181 handle_async_timeout_signal (void)
|
428
|
182 {
|
593
|
183 int interval_id;
|
|
184 int wakeup_id;
|
|
185 Lisp_Object fun, arg;
|
771
|
186 /* Avoid any possibility of GC during QUIT */
|
|
187 int specco = begin_gc_forbidden ();
|
593
|
188
|
|
189 /* No checks for Vinhibit_quit here or anywhere else in this file!!!
|
|
190 Otherwise critical quit will not work right.
|
771
|
191 The only check for Vinhibit_quit is in QUIT itself.
|
|
192
|
|
193 (#### ???? I don't quite understand this comment.) */
|
593
|
194 interval_id = pop_low_level_timeout (&async_timer_queue, 0);
|
|
195
|
|
196 reset_interval_timer ();
|
|
197 if (async_timeout_happened_while_emacs_was_blocking)
|
|
198 {
|
|
199 async_timeout_happened_while_emacs_was_blocking = 0;
|
|
200 waiting_for_user_input_p = 1;
|
|
201 }
|
|
202
|
|
203 wakeup_id = event_stream_resignal_wakeup (interval_id, 1, &fun, &arg);
|
428
|
204
|
593
|
205 if (wakeup_id == poll_for_quit_id)
|
|
206 {
|
|
207 quit_check_signal_happened = 1;
|
|
208 quit_check_signal_tick_count++;
|
|
209 }
|
|
210 else if (wakeup_id == poll_for_sigchld_id)
|
428
|
211 {
|
593
|
212 kick_status_notify ();
|
428
|
213 }
|
593
|
214 else
|
|
215 /* call1 GC-protects its arguments */
|
|
216 call1_trapping_errors ("Error in asynchronous timeout callback",
|
|
217 fun, arg);
|
|
218
|
|
219 waiting_for_user_input_p = 0;
|
771
|
220
|
|
221 unbind_to (specco);
|
593
|
222 }
|
|
223
|
|
224 /* The following two functions are the external interface onto
|
|
225 creating/deleting asynchronous interval timeouts, and are
|
|
226 called by event-stream.c. We call back to event-stream.c using
|
|
227 event_stream_resignal_wakeup(), when an interval goes off. */
|
|
228
|
|
229 int
|
|
230 signal_add_async_interval_timeout (EMACS_TIME thyme)
|
|
231 {
|
|
232 int id = add_low_level_timeout (&async_timer_queue, thyme);
|
|
233
|
|
234 /* If this timeout is at the head of the queue, then we need to
|
|
235 set the timer right now for this timeout. Otherwise, things
|
|
236 are fine as-is; after the timers ahead of us are signalled,
|
|
237 the timer will be set for us. */
|
|
238
|
|
239 if (async_timer_queue->id == id)
|
|
240 reset_interval_timer ();
|
|
241
|
|
242 return id;
|
428
|
243 }
|
|
244
|
|
245 void
|
593
|
246 signal_remove_async_interval_timeout (int id)
|
428
|
247 {
|
593
|
248 int first = (async_timer_queue && async_timer_queue->id == id);
|
|
249 remove_low_level_timeout (&async_timer_queue, id);
|
|
250
|
|
251 /* If we removed the timeout from the head of the queue, then
|
|
252 we need to reset the interval timer right now. */
|
|
253 if (first)
|
|
254 reset_interval_timer ();
|
428
|
255 }
|
|
256
|
593
|
257 /* If alarm() gets called when polling isn't disabled, it will mess up
|
|
258 the asynchronous timeouts, and then C-g checking won't work again.
|
|
259 Some libraries call alarm() directly, so we override the standard
|
|
260 library's alarm() and abort() if the caller of the library function
|
|
261 didn't wrap in stop_interrupts()/start_interrupts().
|
428
|
262
|
593
|
263 NOTE: We could potentially avoid the need to wrap by adding a
|
|
264 one-shot timeout to simulate the alarm(), smashing our signal
|
|
265 handler back into place, and calling the library function when the
|
|
266 alarm goes off. But do we want to? We're not going to gain the
|
|
267 ability to C-g out of library functions this way (unless we forcibly
|
|
268 longjmp() out of a signal handler, which is likely to lead to a
|
|
269 crash). --ben */
|
428
|
270
|
|
271 #ifdef HAVE_SETITIMER
|
611
|
272
|
428
|
273 unsigned int
|
|
274 alarm (unsigned int howlong)
|
|
275 {
|
|
276 struct itimerval old_it, new_it;
|
|
277
|
|
278 assert (async_timer_suppress_count > 0);
|
|
279
|
|
280 new_it.it_value.tv_sec = howlong;
|
|
281 new_it.it_value.tv_usec = 0;
|
|
282 new_it.it_interval.tv_sec = 0;
|
|
283 new_it.it_interval.tv_usec = 0;
|
611
|
284 qxe_setitimer (ITIMER_REAL, &new_it, &old_it);
|
428
|
285
|
|
286 /* Never return zero if there was a timer outstanding. */
|
|
287 return old_it.it_value.tv_sec + (old_it.it_value.tv_usec > 0 ? 1 : 0);
|
|
288 }
|
611
|
289
|
|
290 int
|
|
291 qxe_setitimer (int kind, const struct itimerval *itnew,
|
|
292 struct itimerval *itold)
|
|
293 {
|
|
294 #if defined (WIN32_NATIVE) || defined (CYGWIN)
|
|
295 /* setitimer() does not exist on native MS Windows, and appears broken
|
617
|
296 on Cygwin. See win32.c.
|
|
297
|
|
298 We are emulating the Unix98 setitimer() function, as found in its
|
|
299 incarnations on modern versions of Unix. Note however that in
|
|
300 the win32.c version, ITNEW and ITOLD must be equal if both are
|
|
301 non-zero, due to limitations in the underlying multimedia-timer
|
|
302 API. */
|
611
|
303 return mswindows_setitimer (kind, itnew, itold);
|
|
304 #else
|
617
|
305 /* YUCK! glibc defines setitimer's first argument as
|
|
306 enum __itimer_which, not int, which causes compile errors if
|
|
307 we call setitimer() in the obvious way. */
|
|
308 switch (kind)
|
|
309 {
|
|
310 case ITIMER_REAL: return setitimer (ITIMER_REAL, itnew, itold);
|
|
311 case ITIMER_VIRTUAL: return setitimer (ITIMER_VIRTUAL, itnew, itold);
|
|
312 case ITIMER_PROF: return setitimer (ITIMER_PROF, itnew, itold);
|
|
313 default: abort (); return 0;
|
|
314 }
|
428
|
315 #endif
|
611
|
316 }
|
|
317
|
|
318 #endif /* HAVE_SETITIMER */
|
|
319
|
613
|
320 signal_handler_t
|
|
321 set_timeout_signal (int signal_number, signal_handler_t action)
|
|
322 {
|
|
323 #ifdef CYGWIN_BROKEN_SIGNALS
|
|
324 return mswindows_sigset (signal_number, action);
|
|
325 #else
|
|
326 return EMACS_SIGNAL (signal_number, action);
|
|
327 #endif
|
|
328 }
|
428
|
329
|
|
330 DEFUN ("waiting-for-user-input-p", Fwaiting_for_user_input_p, 0, 0, 0, /*
|
|
331 Return non-nil if XEmacs is waiting for input from the user.
|
|
332 This is intended for use by asynchronous timeout callbacks and by
|
|
333 asynchronous process output filters and sentinels (not yet implemented
|
|
334 in XEmacs). It will always be nil if XEmacs is not inside of
|
|
335 an asynchronous timeout or process callback.
|
|
336 */
|
|
337 ())
|
|
338 {
|
|
339 return waiting_for_user_input_p ? Qt : Qnil;
|
|
340 }
|
|
341
|
|
342
|
|
343 /**********************************************************************/
|
593
|
344 /* Enabling/disabling signals */
|
|
345 /**********************************************************************/
|
|
346
|
|
347 static int interrupts_initted;
|
|
348
|
|
349 void
|
|
350 stop_interrupts (void)
|
|
351 {
|
|
352 if (!interrupts_initted)
|
|
353 return;
|
|
354 #if defined(SIGIO) && !defined(BROKEN_SIGIO)
|
|
355 unrequest_sigio ();
|
|
356 #endif
|
|
357 stop_async_timeouts ();
|
|
358 }
|
|
359
|
|
360 void
|
|
361 start_interrupts (void)
|
|
362 {
|
|
363 if (!interrupts_initted)
|
|
364 return;
|
|
365 #if defined(SIGIO) && !defined(BROKEN_SIGIO)
|
|
366 request_sigio ();
|
|
367 #endif
|
|
368 start_async_timeouts ();
|
|
369 }
|
|
370
|
|
371
|
|
372 static void
|
|
373 establish_slow_interrupt_timer (void)
|
|
374 {
|
|
375 EMACS_TIME thyme;
|
|
376
|
|
377 EMACS_SET_SECS_USECS (thyme, SLOWED_DOWN_INTERRUPTS_SECS, 0);
|
|
378 set_one_shot_timer (thyme);
|
|
379 }
|
|
380
|
|
381 /* Some functions don't like being interrupted with SIGALRM or SIGIO.
|
|
382 Previously we were calling stop_interrupts() / start_interrupts(),
|
|
383 but then if the program hangs in one of those functions, e.g.
|
|
384 waiting for a connect(), we're really screwed. So instead we
|
|
385 just "slow them down". We do this by disabling all interrupts
|
|
386 and then installing a timer of length fairly large, like 5 or
|
|
387 10 secs. That way, any "legitimate" connections (which should
|
|
388 take a fairly short amount of time) go through OK, but we can
|
|
389 interrupt bogus ones. */
|
|
390
|
|
391 void
|
|
392 slow_down_interrupts (void)
|
|
393 {
|
|
394 /* We have to set the flag *before* setting the slowed-down timer,
|
|
395 to avoid a race condition -- if the signal occurs between the
|
|
396 call to set_one_shot_timer() and the setting of this flag,
|
|
397 async_timeout_happened will get set, which will be a Bad Thing if
|
|
398 there were no timeouts on the queue. */
|
|
399 interrupts_slowed_down++;
|
|
400 if (interrupts_slowed_down == 1)
|
|
401 {
|
|
402 stop_interrupts ();
|
|
403 establish_slow_interrupt_timer ();
|
|
404 }
|
|
405 }
|
|
406
|
|
407 void
|
|
408 speed_up_interrupts (void)
|
|
409 {
|
|
410 if (interrupts_slowed_down > 0)
|
|
411 {
|
|
412 start_interrupts ();
|
|
413 /* Change this flag AFTER fiddling with interrupts, for the same
|
|
414 race-condition reasons as above. */
|
|
415 interrupts_slowed_down--;
|
|
416 }
|
|
417 }
|
|
418
|
|
419
|
|
420 /**********************************************************************/
|
|
421 /* The mechanism that drives it all */
|
428
|
422 /**********************************************************************/
|
|
423
|
593
|
424 /* called from QUIT when something_happened gets set (as a result of
|
|
425 a signal) */
|
|
426
|
|
427 int
|
|
428 check_what_happened (void)
|
|
429 {
|
771
|
430 /* No GC can happen anywhere here. handle_async_timeout_signal()
|
|
431 prevents GC (from asynch timeout handler), so does check_quit()
|
|
432 (from processing a message such as WM_INITMENU as a result of
|
|
433 draining the message queue). establish_slow_interrupt_timer() is
|
|
434 too low-level to do anything that might invoke QUIT or call Lisp
|
|
435 code. */
|
593
|
436 something_happened = 0;
|
|
437 if (async_timeout_happened)
|
|
438 {
|
|
439 async_timeout_happened = 0;
|
|
440 handle_async_timeout_signal ();
|
|
441 }
|
|
442 if (slowed_interrupt_timeout_happened)
|
|
443 {
|
|
444 slowed_interrupt_timeout_happened = 0;
|
|
445 establish_slow_interrupt_timer ();
|
|
446 }
|
|
447
|
|
448 return check_quit ();
|
|
449 }
|
|
450
|
|
451 #ifdef SIGIO
|
|
452
|
|
453 /* Signal handler for SIGIO. */
|
|
454
|
|
455 static void
|
|
456 input_available_signal (int signo)
|
|
457 {
|
|
458 something_happened = 1; /* tell QUIT to wake up */
|
|
459 quit_check_signal_happened = 1;
|
|
460 quit_check_signal_tick_count++;
|
|
461 EMACS_REESTABLISH_SIGNAL (signo, input_available_signal);
|
|
462 SIGRETURN;
|
|
463 }
|
|
464
|
|
465 #endif /* SIGIO */
|
|
466
|
|
467 /* Actual signal handler for SIGALRM. Called when:
|
|
468
|
|
469 -- asynchronous timeouts (added with `add-async-timeout') go off
|
|
470
|
|
471 -- when the poll-for-quit timer (used for C-g handling; more or
|
|
472 less when SIGIO is unavailable or BROKEN_SIGIO is defined) or
|
|
473 poll-for-sigchld timer (used when BROKEN_SIGCHLD is defined) go
|
|
474 off. The latter two timers, if set, normally go off every 1/4
|
|
475 of a second -- see NORMAL_QUIT_CHECK_TIMEOUT_MSECS and
|
|
476 NORMAL_SIGCHLD_CHECK_TIMEOUT_MSECS. (Both of these timers are
|
|
477 treated like other asynchronous timeouts, but special-cased
|
|
478 in handle_async_timeout_signal().)
|
|
479
|
|
480 -- we called slow_down_interrupts() and SLOWED_DOWN_INTERRUPTS_SECS
|
|
481 (or a multiple of it) has elapsed.
|
|
482
|
|
483 Note that under Windows, we have no working setitimer(), so we
|
|
484 simulate it using the multimedia timeout functions,
|
|
485 e.g. timeSetEvent(). See setitimer() in nt.c.
|
|
486
|
|
487 Note also that we don't actually *do* anything here (except in the
|
|
488 case of can_break_system_calls). Instead, we just set various
|
|
489 flags; next time QUIT is called, the flags will cause
|
|
490 check_what_happened() to be called, at which point we do everything
|
|
491 indicated by the flags.
|
|
492 */
|
|
493
|
|
494 static SIGTYPE
|
|
495 alarm_signal (int signo)
|
|
496 {
|
|
497 something_happened = 1; /* tell QUIT to wake up and call
|
|
498 check_what_happened() */
|
|
499
|
|
500 if (interrupts_slowed_down)
|
|
501 {
|
|
502 /* we are in "slowed-down interrupts" mode; the only alarm
|
|
503 happening here is the slowed-down quit-check alarm, so
|
|
504 we set this flag.
|
|
505
|
|
506 Do NOT set async_timeout_happened, because we don't want
|
|
507 anyone looking at the timeout queue -- async timeouts
|
|
508 are disabled. */
|
|
509 quit_check_signal_happened = 1;
|
|
510 quit_check_signal_tick_count++;
|
|
511 /* make sure we establish the slow timer again. */
|
|
512 slowed_interrupt_timeout_happened = 1;
|
|
513
|
|
514 /* can_break_system_calls is set when we want to break out of
|
|
515 non-interruptible system calls. */
|
|
516 if (can_break_system_calls)
|
|
517 {
|
|
518 /* reset the flag for safety and such. Do this *before*
|
|
519 unblocking or reestablishing the signal to avoid potential
|
|
520 race conditions. */
|
|
521 can_break_system_calls = 0;
|
|
522 #ifndef WIN32_NATIVE
|
|
523 /* #### I didn't add this WIN32_NATIVE check. I'm not sure
|
|
524 why it's here. But then again, someone needs to review
|
|
525 this can_break_system_calls stuff and see if it still
|
|
526 makes sense. --ben */
|
|
527 EMACS_UNBLOCK_SIGNAL (signo);
|
|
528 EMACS_REESTABLISH_SIGNAL (signo, alarm_signal);
|
|
529 LONGJMP (break_system_call_jump, 0);
|
|
530 #endif
|
|
531 }
|
|
532 }
|
|
533 else
|
|
534 {
|
|
535 async_timeout_happened = 1;
|
|
536 if (emacs_is_blocking)
|
|
537 async_timeout_happened_while_emacs_was_blocking = 1;
|
|
538 /* #### This is for QUITP. When it is run, it may not be the
|
|
539 place to do arbitrary stuff like run asynch. handlers, but
|
|
540 it needs to know whether the poll-for-quit asynch. timeout
|
|
541 went off. Rather than put the code in to compute this
|
|
542 specially, we just set this flag. Should fix this. */
|
|
543 quit_check_signal_happened = 1;
|
|
544
|
|
545 #ifdef HAVE_UNIXOID_EVENT_LOOP
|
|
546 signal_fake_event ();
|
|
547 #endif
|
|
548 }
|
|
549
|
|
550 EMACS_REESTABLISH_SIGNAL (signo, alarm_signal);
|
|
551 SIGRETURN;
|
|
552 }
|
|
553
|
428
|
554 /* Set this for debugging, to have a way to get out */
|
|
555 int stop_character; /* #### not currently implemented */
|
|
556
|
593
|
557 /* Signal handler for SIGINT and SIGQUIT. On TTY's, one of these two
|
|
558 signals will get generated in response to C-g. (When running under
|
|
559 X, C-g is handled using the SIGIO handler, which sets a flag
|
|
560 telling the QUIT macro to scan the unread events for a ^G.)
|
|
561 */
|
428
|
562
|
|
563 static SIGTYPE
|
|
564 interrupt_signal (int sig)
|
|
565 {
|
|
566 /* This function can call lisp */
|
|
567 /* #### we should NOT be calling lisp from a signal handler, boys
|
|
568 and girls */
|
|
569 /* Must preserve main program's value of errno. */
|
|
570 int old_errno = errno;
|
|
571
|
|
572 EMACS_REESTABLISH_SIGNAL (sig, interrupt_signal);
|
|
573
|
|
574 if (sigint_happened && CONSOLEP (Vcontrolling_terminal) &&
|
|
575 CONSOLE_LIVE_P (XCONSOLE (Vcontrolling_terminal)) &&
|
|
576 !emacs_is_blocking)
|
|
577 {
|
593
|
578 /* #### this is inherited from GNU Emacs. Do we really want this?
|
|
579 --ben */
|
428
|
580 char c;
|
|
581 fflush (stdout);
|
|
582 reset_initial_console ();
|
|
583 EMACS_UNBLOCK_SIGNAL (sig);
|
|
584 #ifdef SIGTSTP /* Support possible in later USG versions */
|
|
585 /*
|
|
586 * On systems which can suspend the current process and return to the original
|
|
587 * shell, this command causes the user to end up back at the shell.
|
|
588 * The "Auto-save" and "Abort" questions are not asked until
|
|
589 * the user elects to return to emacs, at which point he can save the current
|
|
590 * job and either dump core or continue.
|
|
591 */
|
|
592 sys_suspend ();
|
|
593 #else
|
|
594 /* Perhaps should really fork an inferior shell?
|
|
595 But that would not provide any way to get back
|
|
596 to the original shell, ever. */
|
|
597 stdout_out ("No support for stopping a process on this operating system;\n");
|
|
598 stdout_out ("you can continue or abort.\n");
|
|
599 #endif /* not SIGTSTP */
|
|
600 stdout_out ("Auto-save? (y or n) ");
|
|
601 if (((c = getc (stdin)) & ~040) == 'Y')
|
|
602 Fdo_auto_save (Qnil, Qnil);
|
|
603 while (c != '\n')
|
|
604 c = getc (stdin);
|
|
605 stdout_out ("Abort (and dump core)? (y or n) ");
|
|
606 if (((c = getc (stdin)) & ~040) == 'Y')
|
|
607 abort ();
|
|
608 while (c != '\n')
|
|
609 c = getc (stdin);
|
|
610 stdout_out ("Continuing...\n");
|
|
611 reinit_initial_console ();
|
|
612 MARK_FRAME_CHANGED (XFRAME (DEVICE_SELECTED_FRAME
|
|
613 (XDEVICE (CONSOLE_SELECTED_DEVICE
|
|
614 (XCONSOLE
|
|
615 (Vcontrolling_terminal))))));
|
|
616 }
|
|
617 else
|
|
618 {
|
|
619 /* Else request quit when it's safe */
|
|
620 Vquit_flag = Qt;
|
|
621 sigint_happened = 1;
|
|
622 #ifdef HAVE_UNIXOID_EVENT_LOOP
|
|
623 signal_fake_event ();
|
|
624 #endif
|
|
625 }
|
|
626 errno = old_errno;
|
|
627 SIGRETURN;
|
|
628 }
|
|
629
|
593
|
630
|
|
631 /**********************************************************************/
|
|
632 /* Control-G checking */
|
|
633 /**********************************************************************/
|
|
634
|
428
|
635 static Lisp_Object
|
|
636 restore_dont_check_for_quit (Lisp_Object val)
|
|
637 {
|
|
638 dont_check_for_quit = XINT (val);
|
|
639 return Qnil;
|
|
640 }
|
|
641
|
771
|
642 /* Defer all checking or processing of C-g. You can do this, for example,
|
|
643 if you want to read C-g's as events. (In that case, you should set
|
|
644 Vquit_flag to Qnil just before you unbind, because it typically gets set
|
|
645 as a result of reading C-g.) */
|
|
646
|
|
647 int
|
428
|
648 begin_dont_check_for_quit (void)
|
|
649 {
|
771
|
650 int depth = specpdl_depth ();
|
|
651 /* As an optimization in QUIT_FLAG_SAYS_SHOULD_QUIT, we bind inhibit-quit
|
|
652 to t -- it has to be checked anyway, and by doing this, we only need
|
|
653 to check dont_check_for_quit when quit-flag == `critical', which is
|
|
654 rare. */
|
428
|
655 specbind (Qinhibit_quit, Qt);
|
|
656 record_unwind_protect (restore_dont_check_for_quit,
|
|
657 make_int (dont_check_for_quit));
|
|
658 dont_check_for_quit = 1;
|
771
|
659
|
|
660 return depth;
|
428
|
661 }
|
|
662
|
|
663 /* The effect of this function is to set Vquit_flag if the user pressed
|
|
664 ^G and discard the ^G, so as to not notice the same ^G again. */
|
|
665 int
|
|
666 check_quit (void)
|
|
667 {
|
|
668 /* dont_check_for_quit is set in two circumstances:
|
|
669
|
|
670 (1) when we are in the process of changing the window
|
|
671 configuration. The frame might be in an inconsistent state,
|
|
672 which will cause assertion failures if we check for QUIT.
|
|
673
|
|
674 (2) when we are reading events, and want to read the C-g
|
|
675 as an event. The normal check for quit will discard the C-g,
|
|
676 which would be bad.
|
|
677
|
771
|
678 [[#### C-g is still often read as quit, e.g. if you type C-x C-g (the
|
|
679 C-g happens during the sit-for in maybe_echo_keys(); even if we
|
|
680 attempt to inhibit quit here, there is still a check later on for
|
|
681 QUIT. To fix this properly requires a fairly substantial overhaul of
|
|
682 the quit-checking code, which is probably not worth it.)]] not true,
|
|
683 we just have to always do dont_check_for_quit around all code that
|
|
684 reads events. my stderr-proc ws already does this.
|
428
|
685
|
|
686 We should *not* conditionalize on Vinhibit_quit, or
|
|
687 critical-quit (Control-Shift-G) won't work right. */
|
|
688
|
771
|
689 /* WARNING: Even calling check_quit(), without actually dispatching
|
|
690 a quit signal, can result in arbitrary Lisp code getting executed
|
|
691 -- at least under Windows. (Not to mention obvious Lisp
|
|
692 invocations like asynchronous timer callbacks.) Here's a sample
|
|
693 stack trace to demonstrate:
|
|
694
|
|
695 NTDLL! DbgBreakPoint@0 address 0x77f9eea9
|
|
696 assert_failed(const char * 0x012d036c, int 4596, const char * 0x012d0354) line 3478
|
|
697 re_match_2_internal(re_pattern_buffer * 0x012d6780, const unsigned char * 0x00000000, int 0, const unsigned char * 0x022f9328, int 34, int 0, re_registers * 0x012d53d0 search_regs, int 34) line 4596 + 41 bytes
|
|
698 re_search_2(re_pattern_buffer * 0x012d6780, const char * 0x00000000, int 0, const char * 0x022f9328, int 34, int 0, int 34, re_registers * 0x012d53d0 search_regs, int 34) line 4269 + 37 bytes
|
|
699 re_search(re_pattern_buffer * 0x012d6780, const char * 0x022f9328, int 34, int 0, int 34, re_registers * 0x012d53d0 search_regs) line 4031 + 37 bytes
|
|
700 string_match_1(long 31222628, long 30282164, long 28377092, buffer * 0x022fde00, int 0) line 413 + 69 bytes
|
|
701 Fstring_match(long 31222628, long 30282164, long 28377092, long 28377092) line 436 + 34 bytes
|
|
702 Ffuncall(int 3, long * 0x008297f8) line 3488 + 168 bytes
|
|
703 execute_optimized_program(const unsigned char * 0x020ddc50, int 6, long * 0x020ddf50) line 744 + 16 bytes
|
|
704 funcall_compiled_function(long 34407748, int 1, long * 0x00829aec) line 516 + 53 bytes
|
|
705 Ffuncall(int 2, long * 0x00829ae8) line 3523 + 17 bytes
|
|
706 execute_optimized_program(const unsigned char * 0x020ddc90, int 4, long * 0x020ddf90) line 744 + 16 bytes
|
|
707 funcall_compiled_function(long 34407720, int 1, long * 0x00829e28) line 516 + 53 bytes
|
|
708 Ffuncall(int 2, long * 0x00829e24) line 3523 + 17 bytes
|
|
709 mapcar1(long 15, long * 0x00829e48, long 34447820, long 34187868) line 2929 + 11 bytes
|
|
710 Fmapcar(long 34447820, long 34187868) line 3035 + 21 bytes
|
|
711 Ffuncall(int 3, long * 0x00829f20) line 3488 + 93 bytes
|
|
712 execute_optimized_program(const unsigned char * 0x020c2b70, int 7, long * 0x020dd010) line 744 + 16 bytes
|
|
713 funcall_compiled_function(long 34407580, int 2, long * 0x0082a210) line 516 + 53 bytes
|
|
714 Ffuncall(int 3, long * 0x0082a20c) line 3523 + 17 bytes
|
|
715 execute_optimized_program(const unsigned char * 0x020cf810, int 6, long * 0x020cfb10) line 744 + 16 bytes
|
|
716 funcall_compiled_function(long 34407524, int 0, long * 0x0082a580) line 516 + 53 bytes
|
|
717 Ffuncall(int 1, long * 0x0082a57c) line 3523 + 17 bytes
|
|
718 run_hook_with_args_in_buffer(buffer * 0x022fde00, int 1, long * 0x0082a57c, int 0) line 3980 + 13 bytes
|
|
719 run_hook_with_args(int 1, long * 0x0082a57c, int 0) line 3993 + 23 bytes
|
|
720 Frun_hooks(int 1, long * 0x0082a57c) line 3847 + 19 bytes
|
|
721 run_hook(long 34447484) line 4094 + 11 bytes
|
|
722 unsafe_handle_wm_initmenu_1(frame * 0x01dbb000) line 736 + 11 bytes
|
|
723 unsafe_handle_wm_initmenu(long 28377092) line 807 + 11 bytes
|
|
724 condition_case_1(long 28377116, long (long)* 0x0101c827 unsafe_handle_wm_initmenu(long), long 28377092, long (long, long)* 0x01005fa4 mswindows_modal_loop_error_handler(long, long), long 28377092) line 1692 + 7 bytes
|
|
725 mswindows_protect_modal_loop(long (long)* 0x0101c827 unsafe_handle_wm_initmenu(long), long 28377092) line 1194 + 32 bytes
|
|
726 mswindows_handle_wm_initmenu(HMENU__ * 0x00010199, frame * 0x01dbb000) line 826 + 17 bytes
|
|
727 mswindows_wnd_proc(HWND__ * 0x000501da, unsigned int 278, unsigned int 65945, long 0) line 3089 + 31 bytes
|
|
728 USER32! UserCallWinProc@20 + 24 bytes
|
|
729 USER32! DispatchClientMessage@20 + 47 bytes
|
|
730 USER32! __fnDWORD@4 + 34 bytes
|
|
731 NTDLL! KiUserCallbackDispatcher@12 + 19 bytes
|
|
732 USER32! DispatchClientMessage@20 address 0x77e163cc
|
|
733 USER32! DefWindowProcW@16 + 34 bytes
|
|
734 qxeDefWindowProc(HWND__ * 0x000501da, unsigned int 274, unsigned int 61696, long 98) line 1188 + 22 bytes
|
|
735 mswindows_wnd_proc(HWND__ * 0x000501da, unsigned int 274, unsigned int 61696, long 98) line 3362 + 21 bytes
|
|
736 USER32! UserCallWinProc@20 + 24 bytes
|
|
737 USER32! DispatchClientMessage@20 + 47 bytes
|
|
738 USER32! __fnDWORD@4 + 34 bytes
|
|
739 NTDLL! KiUserCallbackDispatcher@12 + 19 bytes
|
|
740 USER32! DispatchClientMessage@20 address 0x77e163cc
|
|
741 USER32! DefWindowProcW@16 + 34 bytes
|
|
742 qxeDefWindowProc(HWND__ * 0x000501da, unsigned int 262, unsigned int 98, long 540016641) line 1188 + 22 bytes
|
|
743 mswindows_wnd_proc(HWND__ * 0x000501da, unsigned int 262, unsigned int 98, long 540016641) line 3362 + 21 bytes
|
|
744 USER32! UserCallWinProc@20 + 24 bytes
|
|
745 USER32! DispatchMessageWorker@8 + 244 bytes
|
|
746 USER32! DispatchMessageW@4 + 11 bytes
|
|
747 qxeDispatchMessage(const tagMSG * 0x0082c684 {msg=0x00000106 wp=0x00000062 lp=0x20300001}) line 989 + 10 bytes
|
|
748 mswindows_drain_windows_queue() line 1345 + 9 bytes
|
|
749 emacs_mswindows_quit_p() line 3947
|
|
750 event_stream_quit_p() line 666
|
|
751 check_quit() line 686
|
|
752 check_what_happened() line 437
|
|
753 re_match_2_internal(re_pattern_buffer * 0x012d5a18, const unsigned char * 0x00000000, int 0, const unsigned char * 0x02235000, int 23486, int 14645, re_registers * 0x012d53d0 search_regs, int 23486) line 4717 + 14 bytes
|
|
754 re_search_2(re_pattern_buffer * 0x012d5a18, const char * 0x02235000, int 23486, const char * 0x0223b38e, int 0, int 14645, int 8841, re_registers * 0x012d53d0 search_regs, int 23486) line 4269 + 37 bytes
|
|
755 search_buffer(buffer * 0x022fde00, long 29077572, long 13789, long 23487, long 1, int 1, long 28377092, long 28377092, int 0) line 1224 + 89 bytes
|
|
756 search_command(long 29077572, long 46975, long 28377116, long 28377092, long 28377092, int 1, int 1, int 0) line 1054 + 151 bytes
|
|
757 Fre_search_forward(long 29077572, long 46975, long 28377116, long 28377092, long 28377092) line 2147 + 31 bytes
|
|
758 Ffuncall(int 4, long * 0x0082ceb0) line 3488 + 216 bytes
|
|
759 execute_optimized_program(const unsigned char * 0x02047810, int 13, long * 0x02080c10) line 744 + 16 bytes
|
|
760 funcall_compiled_function(long 34187208, int 3, long * 0x0082d1b8) line 516 + 53 bytes
|
|
761 Ffuncall(int 4, long * 0x0082d1b4) line 3523 + 17 bytes
|
|
762 execute_optimized_program(const unsigned char * 0x01e96a10, int 6, long * 0x020ae510) line 744 + 16 bytes
|
|
763 funcall_compiled_function(long 34186676, int 3, long * 0x0082d4a0) line 516 + 53 bytes
|
|
764 Ffuncall(int 4, long * 0x0082d49c) line 3523 + 17 bytes
|
|
765 execute_optimized_program(const unsigned char * 0x02156b50, int 4, long * 0x020c2db0) line 744 + 16 bytes
|
|
766 funcall_compiled_function(long 34186564, int 2, long * 0x0082d780) line 516 + 53 bytes
|
|
767 Ffuncall(int 3, long * 0x0082d77c) line 3523 + 17 bytes
|
|
768 execute_optimized_program(const unsigned char * 0x0082d964, int 3, long * 0x020c2d70) line 744 + 16 bytes
|
|
769 Fbyte_code(long 29405156, long 34352480, long 7) line 2392 + 38 bytes
|
|
770 Feval(long 34354440) line 3290 + 187 bytes
|
|
771 condition_case_1(long 34354572, long (long)* 0x01087232 Feval(long), long 34354440, long (long, long)* 0x01084764 run_condition_case_handlers(long, long), long 28377092) line 1692 + 7 bytes
|
|
772 condition_case_3(long 34354440, long 28377092, long 34354572) line 1779 + 27 bytes
|
|
773 execute_rare_opcode(long * 0x0082dc7c, const unsigned char * 0x01b090af, int 143) line 1269 + 19 bytes
|
|
774 execute_optimized_program(const unsigned char * 0x01b09090, int 6, long * 0x020ae590) line 654 + 17 bytes
|
|
775 funcall_compiled_function(long 34186620, int 0, long * 0x0082df68) line 516 + 53 bytes
|
|
776 Ffuncall(int 1, long * 0x0082df64) line 3523 + 17 bytes
|
|
777 execute_optimized_program(const unsigned char * 0x02195470, int 1, long * 0x020c2df0) line 744 + 16 bytes
|
|
778 funcall_compiled_function(long 34186508, int 0, long * 0x0082e23c) line 516 + 53 bytes
|
|
779 Ffuncall(int 1, long * 0x0082e238) line 3523 + 17 bytes
|
|
780 execute_optimized_program(const unsigned char * 0x01e5d410, int 6, long * 0x0207d410) line 744 + 16 bytes
|
|
781 funcall_compiled_function(long 34186312, int 1, long * 0x0082e524) line 516 + 53 bytes
|
|
782 Ffuncall(int 2, long * 0x0082e520) line 3523 + 17 bytes
|
|
783 execute_optimized_program(const unsigned char * 0x02108fb0, int 2, long * 0x020c2e30) line 744 + 16 bytes
|
|
784 funcall_compiled_function(long 34186340, int 0, long * 0x0082e7fc) line 516 + 53 bytes
|
|
785 Ffuncall(int 1, long * 0x0082e7f8) line 3523 + 17 bytes
|
|
786 execute_optimized_program(const unsigned char * 0x020fe150, int 2, long * 0x01e6f510) line 744 + 16 bytes
|
|
787 funcall_compiled_function(long 31008124, int 0, long * 0x0082ebd8) line 516 + 53 bytes
|
|
788 Ffuncall(int 1, long * 0x0082ebd4) line 3523 + 17 bytes
|
|
789 run_hook_with_args_in_buffer(buffer * 0x022fde00, int 1, long * 0x0082ebd4, int 0) line 3980 + 13 bytes
|
|
790 run_hook_with_args(int 1, long * 0x0082ebd4, int 0) line 3993 + 23 bytes
|
|
791 Frun_hooks(int 1, long * 0x0082ebd4) line 3847 + 19 bytes
|
|
792 Ffuncall(int 2, long * 0x0082ebd0) line 3509 + 14 bytes
|
|
793 execute_optimized_program(const unsigned char * 0x01ef2210, int 5, long * 0x01da8e10) line 744 + 16 bytes
|
|
794 funcall_compiled_function(long 31020440, int 2, long * 0x0082eeb8) line 516 + 53 bytes
|
|
795 Ffuncall(int 3, long * 0x0082eeb4) line 3523 + 17 bytes
|
|
796 execute_optimized_program(const unsigned char * 0x0082f09c, int 3, long * 0x01d89390) line 744 + 16 bytes
|
|
797 Fbyte_code(long 31102388, long 30970752, long 7) line 2392 + 38 bytes
|
|
798 Feval(long 31087568) line 3290 + 187 bytes
|
|
799 condition_case_1(long 30961240, long (long)* 0x01087232 Feval(long), long 31087568, long (long, long)* 0x01084764 run_condition_case_handlers(long, long), long 28510180) line 1692 + 7 bytes
|
|
800 condition_case_3(long 31087568, long 28510180, long 30961240) line 1779 + 27 bytes
|
|
801 execute_rare_opcode(long * 0x0082f450, const unsigned char * 0x01ef23ec, int 143) line 1269 + 19 bytes
|
|
802 execute_optimized_program(const unsigned char * 0x01ef2310, int 6, long * 0x01da8f10) line 654 + 17 bytes
|
|
803 funcall_compiled_function(long 31020412, int 1, long * 0x0082f740) line 516 + 53 bytes
|
|
804 Ffuncall(int 2, long * 0x0082f73c) line 3523 + 17 bytes
|
|
805 execute_optimized_program(const unsigned char * 0x020fe650, int 3, long * 0x01d8c490) line 744 + 16 bytes
|
|
806 funcall_compiled_function(long 31020020, int 2, long * 0x0082fa14) line 516 + 53 bytes
|
|
807 Ffuncall(int 3, long * 0x0082fa10) line 3523 + 17 bytes
|
|
808 Fcall_interactively(long 29685180, long 28377092, long 28377092) line 1008 + 22 bytes
|
|
809 Fcommand_execute(long 29685180, long 28377092, long 28377092) line 2929 + 17 bytes
|
|
810 execute_command_event(command_builder * 0x01be1900, long 36626492) line 4048 + 25 bytes
|
|
811 Fdispatch_event(long 36626492) line 4341 + 70 bytes
|
|
812 Fcommand_loop_1() line 582 + 9 bytes
|
|
813 command_loop_1(long 28377092) line 495
|
|
814 condition_case_1(long 28377188, long (long)* 0x01064fb9 command_loop_1(long), long 28377092, long (long, long)* 0x010649d0 cmd_error(long, long), long 28377092) line 1692 + 7 bytes
|
|
815 command_loop_3() line 256 + 35 bytes
|
|
816 command_loop_2(long 28377092) line 269
|
|
817 internal_catch(long 28457612, long (long)* 0x01064b20 command_loop_2(long), long 28377092, int * volatile 0x00000000) line 1317 + 7 bytes
|
|
818 initial_command_loop(long 28377092) line 305 + 25 bytes
|
|
819 STACK_TRACE_EYE_CATCHER(int 1, char * * 0x01b63ff0, char * * 0x01ca5300, int 0) line 2501
|
|
820 main(int 1, char * * 0x01b63ff0, char * * 0x01ca5300) line 2938
|
|
821 XEMACS! mainCRTStartup + 180 bytes
|
|
822 _start() line 171
|
|
823 KERNEL32! BaseProcessStart@4 + 115547 bytes
|
|
824
|
|
825 */
|
|
826
|
428
|
827 if (dont_check_for_quit)
|
|
828 return 0;
|
|
829
|
|
830 if (quit_check_signal_happened)
|
|
831 {
|
771
|
832 /* Since arbitrary Lisp code may be executed, GC might happen,
|
|
833 which would majorly fuck a lot of things, e.g. re_match()
|
|
834 [string gets relocated] and lots of other code that's not
|
|
835 prepared to handle GC in QUIT. */
|
|
836 int specdepth = begin_gc_forbidden ();
|
428
|
837 quit_check_signal_happened = 0;
|
|
838 event_stream_quit_p ();
|
771
|
839 unbind_to (specdepth);
|
428
|
840 return 1;
|
|
841 }
|
|
842 else
|
|
843 return 0;
|
|
844 }
|
|
845
|
|
846
|
|
847
|
|
848 void
|
|
849 init_poll_for_quit (void)
|
|
850 {
|
|
851 #if !defined (SIGIO) && !defined (DONT_POLL_FOR_QUIT)
|
|
852 /* Check for C-g every 1/4 of a second.
|
|
853
|
|
854 #### This is just a guess. Some investigation will have to be
|
|
855 done to see what the best value is. The best value is the
|
|
856 smallest possible value that doesn't cause a significant amount
|
|
857 of running time to be spent in C-g checking. */
|
|
858 if (!poll_for_quit_id)
|
|
859 poll_for_quit_id =
|
|
860 event_stream_generate_wakeup (NORMAL_QUIT_CHECK_TIMEOUT_MSECS,
|
|
861 NORMAL_QUIT_CHECK_TIMEOUT_MSECS,
|
|
862 Qnil, Qnil, 1);
|
|
863 #endif /* not SIGIO and not DONT_POLL_FOR_QUIT */
|
|
864 }
|
|
865
|
593
|
866 #if 0 /* not used anywhere */
|
|
867
|
428
|
868 void
|
|
869 reset_poll_for_quit (void)
|
|
870 {
|
|
871 #if !defined (SIGIO) && !defined (DONT_POLL_FOR_QUIT)
|
|
872 if (poll_for_quit_id)
|
|
873 {
|
|
874 event_stream_disable_wakeup (poll_for_quit_id, 1);
|
|
875 poll_for_quit_id = 0;
|
|
876 }
|
|
877 #endif /* not SIGIO and not DONT_POLL_FOR_QUIT */
|
|
878 }
|
|
879
|
593
|
880 #endif /* 0 */
|
|
881
|
428
|
882 #if defined(HAVE_UNIX_PROCESSES) && !defined(SIGCHLD)
|
|
883
|
|
884 static void
|
|
885 init_poll_for_sigchld (void)
|
|
886 {
|
|
887 /* Check for terminated processes every 1/4 of a second.
|
|
888
|
|
889 #### This is just a guess. Some investigation will have to be
|
|
890 done to see what the best value is. The best value is the
|
|
891 smallest possible value that doesn't cause a significant amount
|
|
892 of running time to be spent in process-termination checking.
|
|
893 */
|
|
894 poll_for_sigchld_id =
|
|
895 event_stream_generate_wakeup (NORMAL_SIGCHLD_CHECK_TIMEOUT_MSECS,
|
|
896 NORMAL_SIGCHLD_CHECK_TIMEOUT_MSECS,
|
|
897 Qnil, Qnil, 1);
|
|
898 }
|
|
899
|
|
900 #endif /* not SIGCHLD */
|
|
901
|
|
902
|
|
903 /************************************************************************/
|
|
904 /* initialization */
|
|
905 /************************************************************************/
|
|
906
|
|
907 /* If we've been nohup'ed, keep it that way.
|
|
908 This allows `nohup xemacs &' to work.
|
|
909 More generally, if a normally fatal signal has been redirected
|
|
910 to SIG_IGN by our invocation environment, trust the environment.
|
|
911 This keeps xemacs from being killed by a SIGQUIT intended for a
|
|
912 different process after having been backgrounded under a
|
|
913 non-job-control shell! */
|
|
914 static void
|
|
915 handle_signal_if_fatal (int signo)
|
|
916 {
|
613
|
917 if (EMACS_SIGNAL (signo, fatal_error_signal) == SIG_IGN)
|
|
918 EMACS_SIGNAL (signo, SIG_IGN);
|
428
|
919 }
|
|
920
|
|
921 void
|
|
922 init_signals_very_early (void)
|
|
923 {
|
|
924 /* Catch all signals that would kill us.
|
|
925 Don't catch these signals in batch mode if not initialized.
|
|
926 On some machines, this sets static data that would make
|
|
927 signal fail to work right when the dumped Emacs is run. */
|
|
928 if (noninteractive && !initialized)
|
|
929 return;
|
|
930
|
|
931 handle_signal_if_fatal (SIGILL); /* ANSI */
|
|
932 handle_signal_if_fatal (SIGABRT); /* ANSI */
|
|
933 handle_signal_if_fatal (SIGFPE); /* ANSI */
|
|
934 handle_signal_if_fatal (SIGSEGV); /* ANSI */
|
|
935 handle_signal_if_fatal (SIGTERM); /* ANSI */
|
|
936
|
|
937
|
|
938 #ifdef SIGHUP
|
|
939 handle_signal_if_fatal (SIGHUP); /* POSIX */
|
|
940 #endif
|
|
941 #ifdef SIGQUIT
|
|
942 handle_signal_if_fatal (SIGQUIT); /* POSIX */
|
|
943 #endif
|
|
944 #ifdef SIGTRAP
|
|
945 handle_signal_if_fatal (SIGTRAP); /* POSIX */
|
|
946 #endif
|
|
947 #ifdef SIGUSR1
|
|
948 handle_signal_if_fatal (SIGUSR1); /* POSIX */
|
|
949 #endif
|
|
950 #ifdef SIGUSR2
|
|
951 handle_signal_if_fatal (SIGUSR2); /* POSIX */
|
|
952 #endif
|
|
953 #ifdef SIGPIPE
|
|
954 handle_signal_if_fatal (SIGPIPE); /* POSIX */
|
|
955 #endif
|
|
956 #ifdef SIGALRM
|
|
957 /* This will get reset later, once we're
|
|
958 capable of handling it properly. */
|
|
959 handle_signal_if_fatal (SIGALRM); /* POSIX */
|
|
960 #endif
|
|
961
|
|
962
|
|
963 #ifdef SIGBUS
|
|
964 handle_signal_if_fatal (SIGBUS); /* XPG5 */
|
|
965 #endif
|
|
966 #ifdef SIGSYS
|
|
967 handle_signal_if_fatal (SIGSYS); /* XPG5 */
|
|
968 #endif
|
|
969 #ifdef SIGXCPU
|
|
970 handle_signal_if_fatal (SIGXCPU); /* XPG5 */
|
|
971 #endif
|
|
972 #ifdef SIGXFSZ
|
|
973 handle_signal_if_fatal (SIGXFSZ); /* XPG5 */
|
|
974 #endif
|
|
975 #ifdef SIGVTALRM
|
|
976 handle_signal_if_fatal (SIGVTALRM); /* XPG5 */
|
|
977 #endif
|
|
978 #ifdef SIGPROF
|
|
979 /* Messes up the REAL profiler */
|
|
980 /* handle_signal_if_fatal (SIGPROF); */ /* XPG5 */
|
|
981 #endif
|
|
982
|
|
983
|
|
984 #ifdef SIGHWE
|
|
985 handle_signal_if_fatal (SIGHWE);
|
|
986 #endif
|
|
987 #ifdef SIGPRE
|
|
988 handle_signal_if_fatal (SIGPRE);
|
|
989 #endif
|
|
990 #ifdef SIGORE
|
|
991 handle_signal_if_fatal (SIGORE);
|
|
992 #endif
|
|
993 #ifdef SIGUME
|
|
994 handle_signal_if_fatal (SIGUME);
|
|
995 #endif
|
|
996 #ifdef SIGDLK
|
|
997 handle_signal_if_fatal (SIGDLK);
|
|
998 #endif
|
|
999 #ifdef SIGCPULIM
|
|
1000 handle_signal_if_fatal (SIGCPULIM);
|
|
1001 #endif
|
|
1002 #ifdef SIGIOT
|
|
1003 handle_signal_if_fatal (SIGIOT);
|
|
1004 #endif
|
|
1005 #ifdef SIGEMT
|
|
1006 handle_signal_if_fatal (SIGEMT);
|
|
1007 #endif
|
|
1008 #ifdef SIGLOST
|
|
1009 handle_signal_if_fatal (SIGLOST);
|
|
1010 #endif
|
|
1011 #ifdef SIGSTKFLT /* coprocessor stack fault under Linux */
|
|
1012 handle_signal_if_fatal (SIGSTKFLT);
|
|
1013 #endif
|
|
1014 #ifdef SIGUNUSED /* exists under Linux, and will kill process! */
|
|
1015 handle_signal_if_fatal (SIGUNUSED);
|
|
1016 #endif
|
|
1017
|
|
1018 #ifdef AIX
|
|
1019 /* 20 is SIGCHLD, 21 is SIGTTIN, 22 is SIGTTOU. */
|
|
1020 #ifndef _I386
|
|
1021 handle_signal_if_fatal (SIGIOINT);
|
|
1022 #endif
|
|
1023 handle_signal_if_fatal (SIGGRANT);
|
|
1024 handle_signal_if_fatal (SIGRETRACT);
|
|
1025 handle_signal_if_fatal (SIGSOUND);
|
|
1026 handle_signal_if_fatal (SIGMSG);
|
|
1027 #endif /* AIX */
|
|
1028
|
|
1029 #ifdef SIGDANGER
|
|
1030 /* This just means available memory is getting low. */
|
613
|
1031 EMACS_SIGNAL (SIGDANGER, memory_warning_signal);
|
428
|
1032 #endif
|
|
1033 }
|
|
1034
|
|
1035 void
|
|
1036 syms_of_signal (void)
|
|
1037 {
|
|
1038 DEFSUBR (Fwaiting_for_user_input_p);
|
|
1039 }
|
|
1040
|
|
1041 void
|
|
1042 init_interrupts_late (void)
|
|
1043 {
|
|
1044 if (!noninteractive)
|
|
1045 {
|
613
|
1046 EMACS_SIGNAL (SIGINT, interrupt_signal);
|
428
|
1047 #ifdef HAVE_TERMIO
|
|
1048 /* On systems with TERMIO, C-g is set up for both SIGINT and SIGQUIT
|
|
1049 and we can't tell which one it will give us. */
|
613
|
1050 EMACS_SIGNAL (SIGQUIT, interrupt_signal);
|
428
|
1051 #endif /* HAVE_TERMIO */
|
|
1052 init_async_timeouts ();
|
|
1053 #ifdef SIGIO
|
613
|
1054 EMACS_SIGNAL (SIGIO, input_available_signal);
|
428
|
1055 # ifdef SIGPOLL /* XPG5 */
|
|
1056 /* Some systems (e.g. Motorola SVR4) losingly have different
|
|
1057 values for SIGIO and SIGPOLL, and send SIGPOLL instead of
|
|
1058 SIGIO. On those same systems, an uncaught SIGPOLL kills the
|
|
1059 process. */
|
613
|
1060 EMACS_SIGNAL (SIGPOLL, input_available_signal);
|
428
|
1061 # endif
|
|
1062 #elif !defined (DONT_POLL_FOR_QUIT)
|
|
1063 init_poll_for_quit ();
|
|
1064 #endif
|
|
1065 }
|
|
1066
|
|
1067 #if defined(HAVE_UNIX_PROCESSES) && !defined(SIGCHLD)
|
|
1068 init_poll_for_sigchld ();
|
|
1069 #endif
|
|
1070
|
|
1071 EMACS_UNBLOCK_ALL_SIGNALS ();
|
|
1072
|
|
1073 interrupts_initted = 1;
|
|
1074 }
|
|
1075
|