0
|
1 /* Handling asynchronous signals.
|
|
2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995, 1996 Ben Wing.
|
|
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 /* Just to make sure we don't use any global vars below */
|
|
25 #define DONT_DECLARE_MAC_VARS
|
|
26
|
|
27 #include <config.h>
|
|
28 #include "lisp.h"
|
|
29
|
|
30 #include "console.h"
|
|
31 #include "events.h" /* for signal_fake_event() */
|
|
32 #include "frame.h"
|
|
33 #include "sysdep.h"
|
|
34 #include "syssignal.h"
|
|
35 #include "systime.h"
|
|
36
|
|
37 #include <errno.h>
|
|
38
|
|
39 /* Set to 1 when a quit-check signal (either a SIGIO interrupt or
|
|
40 the asynch. timeout for poll-for-quit) occurs. The QUITP
|
|
41 macro may look at this. */
|
|
42 volatile int quit_check_signal_happened;
|
|
43
|
|
44 /* Count of the number of times a quit-check signal has occurred.
|
|
45 Some stuff in event-Xt.c looks at this. */
|
|
46 volatile int quit_check_signal_tick_count;
|
|
47
|
|
48 /* Set to 1 when a SIGINT (or SIGQUIT) interrupt is processed.
|
|
49 maybe_read_quit_event() looks at this. */
|
|
50 volatile int sigint_happened;
|
|
51
|
|
52 /* Set to 1 when an asynch. timeout signal occurs. */
|
|
53 static volatile int alarm_happened;
|
|
54
|
|
55 /* This is used to synchronize setting the waiting_for_user_input_p
|
|
56 flag. */
|
|
57 static volatile int alarm_happened_while_emacs_was_blocking;
|
|
58
|
|
59 /* See check_quit() for when this is set. */
|
|
60 int dont_check_for_quit;
|
|
61
|
|
62 #if !defined (SIGIO) && !defined (DONT_POLL_FOR_QUIT)
|
|
63 int poll_for_quit_id;
|
|
64 #endif
|
|
65
|
|
66 #ifndef SIGCHLD
|
|
67 int poll_for_sigchld_id;
|
|
68 #endif
|
|
69
|
|
70 /* This variable is used to communicate to a lisp
|
|
71 process-filter/sentinel/asynchronous callback (via the function
|
|
72 Fwaiting_for_user_input_p below) whether XEmacs was waiting for
|
|
73 user-input when that process-filter was called. */
|
|
74 static int waiting_for_user_input_p;
|
|
75
|
|
76 static int interrupts_slowed_down;
|
|
77
|
104
|
78 #define SLOWED_DOWN_INTERRUPTS_SECS 15
|
0
|
79 #define NORMAL_QUIT_CHECK_TIMEOUT_MSECS 250
|
|
80 #define NORMAL_SIGCHLD_CHECK_TIMEOUT_MSECS 250
|
|
81
|
|
82 /* Used so that signals can break out of system calls that aren't
|
|
83 naturally interruptible. */
|
|
84
|
|
85 JMP_BUF break_system_call_jump;
|
16
|
86 volatile int can_break_system_calls;
|
0
|
87
|
|
88
|
|
89 /**********************************************************************/
|
|
90 /* Asynchronous timeout functions */
|
|
91 /**********************************************************************/
|
|
92
|
|
93 /* The pending timers are stored in an ordered list, where the first timer
|
|
94 on the list is the first one to fire. Times recorded here are
|
|
95 absolute. */
|
|
96 static struct low_level_timeout *async_timer_queue;
|
|
97
|
|
98 /* Nonzero means async timers are temporarily suppressed. */
|
|
99 static int async_timer_suppress_count;
|
|
100
|
|
101 static void
|
|
102 set_one_shot_timer (EMACS_TIME interval)
|
|
103 {
|
|
104 #ifdef HAVE_SETITIMER
|
|
105 struct itimerval it;
|
|
106 it.it_value = interval;
|
|
107 EMACS_SET_SECS_USECS (it.it_interval, 0, 0);
|
|
108 setitimer (ITIMER_REAL, &it, 0);
|
|
109 #else
|
|
110 int secs;
|
|
111 EMACS_TIME_TO_INT (interval, secs);
|
|
112 alarm (secs);
|
|
113 #endif
|
|
114 }
|
|
115
|
|
116 static void
|
|
117 reset_interval_timer (void)
|
|
118 {
|
|
119 EMACS_TIME interval;
|
|
120
|
|
121 /* Get the interval to set. If an interval is available,
|
|
122 make sure it's not zero (this is a valid return, but it will
|
|
123 cause the timer to get disabled, so convert it to a very short
|
|
124 time). */
|
|
125 if (get_low_level_timeout_interval (async_timer_queue, &interval))
|
|
126 {
|
|
127 if (EMACS_SECS (interval) == 0 && EMACS_USECS (interval) == 0)
|
|
128 EMACS_SET_USECS (interval, 1);
|
|
129 }
|
|
130 else
|
|
131 /* A time of 0 means "disable". */
|
|
132 EMACS_SET_SECS_USECS (interval, 0, 0);
|
|
133
|
|
134 set_one_shot_timer (interval);
|
|
135 }
|
|
136
|
|
137 int
|
|
138 event_stream_add_async_timeout (EMACS_TIME thyme)
|
|
139 {
|
|
140 int id = add_low_level_timeout (&async_timer_queue, thyme);
|
|
141
|
|
142 /* If this timeout is at the head of the queue, then we need to
|
|
143 set the timer right now for this timeout. Otherwise, things
|
|
144 are fine as-is; after the timers ahead of us are signalled,
|
|
145 the timer will be set for us. */
|
|
146
|
|
147 if (async_timer_queue->id == id)
|
|
148 reset_interval_timer ();
|
|
149
|
|
150 return id;
|
|
151 }
|
|
152
|
|
153 void
|
|
154 event_stream_remove_async_timeout (int id)
|
|
155 {
|
|
156 int first = (async_timer_queue && async_timer_queue->id == id);
|
|
157 remove_low_level_timeout (&async_timer_queue, id);
|
|
158
|
|
159 /* If we removed the timeout from the head of the queue, then
|
|
160 we need to reset the interval timer right now. */
|
|
161 if (first)
|
|
162 reset_interval_timer ();
|
|
163 }
|
|
164
|
|
165 /* Handle an alarm once each second and read pending input
|
|
166 so as to handle a C-g if it comes in. */
|
|
167
|
|
168 static SIGTYPE
|
|
169 alarm_signal (int signo)
|
|
170 {
|
|
171 if (interrupts_slowed_down)
|
|
172 {
|
|
173 something_happened = 1; /* tell QUIT to wake up */
|
|
174 /* we are in "slowed-down interrupts" mode; the only alarm
|
|
175 happening here is the slowed-down quit-check alarm, so
|
|
176 we set this flag.
|
|
177
|
|
178 Do NOT set alarm_happened, because we don't want anyone
|
|
179 looking at the timeout queue. We didn't set it and
|
|
180 it needs to stay the way it is. */
|
|
181 quit_check_signal_happened = 1;
|
|
182
|
|
183 /* can_break_system_calls is set when we want to break out of
|
|
184 non-interruptible system calls. */
|
|
185 if (can_break_system_calls)
|
|
186 {
|
|
187 /* reset the flag for safety and such. Do this *before*
|
|
188 unblocking or reestablishing the signal to avoid potential
|
|
189 race conditions. */
|
|
190 can_break_system_calls = 0;
|
|
191 EMACS_UNBLOCK_SIGNAL (signo);
|
|
192 EMACS_REESTABLISH_SIGNAL (signo, alarm_signal);
|
|
193 LONGJMP (break_system_call_jump, 0);
|
|
194 }
|
|
195
|
|
196 EMACS_REESTABLISH_SIGNAL (signo, alarm_signal);
|
|
197 SIGRETURN;
|
|
198 }
|
|
199
|
|
200 something_happened = 1; /* tell QUIT to wake up */
|
|
201 alarm_happened = 1;
|
|
202 if (emacs_is_blocking)
|
|
203 alarm_happened_while_emacs_was_blocking = 1;
|
|
204 /* #### This is for QUITP. When it is run, it may not be the
|
|
205 place to do arbitrary stuff like run asynch. handlers, but
|
|
206 it needs to know whether the poll-for-quit asynch. timeout
|
|
207 went off. Rather than put the code in to compute this
|
|
208 specially, we just set this flag. Should fix this. */
|
|
209 quit_check_signal_happened = 1;
|
|
210 signal_fake_event ();
|
|
211
|
|
212 EMACS_REESTABLISH_SIGNAL (signo, alarm_signal);
|
|
213 SIGRETURN;
|
|
214 }
|
|
215
|
|
216 static void
|
|
217 init_async_timeouts (void)
|
|
218 {
|
|
219 signal (SIGALRM, alarm_signal);
|
|
220 async_timer_suppress_count = 0;
|
|
221 }
|
|
222
|
|
223 /* Turn off async timeouts. */
|
|
224
|
|
225 static void
|
|
226 stop_async_timeouts (void)
|
|
227 {
|
|
228 if (async_timer_suppress_count == 0)
|
|
229 {
|
|
230 /* If timer was on, turn it off. */
|
|
231 EMACS_TIME thyme;
|
|
232 EMACS_SET_SECS_USECS (thyme, 0, 0);
|
|
233 set_one_shot_timer (thyme);
|
|
234 }
|
|
235 async_timer_suppress_count++;
|
|
236 }
|
|
237
|
|
238 /* Turn on async timeouts again. */
|
|
239
|
|
240 static void
|
|
241 start_async_timeouts (void)
|
|
242 {
|
|
243 assert (async_timer_suppress_count > 0);
|
|
244 async_timer_suppress_count--;
|
|
245 if (async_timer_suppress_count == 0)
|
|
246 {
|
|
247 /* Some callers turn off async timeouts and then use the alarm
|
|
248 for their own purposes; so reinitialize everything. */
|
|
249 signal (SIGALRM, alarm_signal);
|
|
250 reset_interval_timer ();
|
|
251 }
|
|
252 }
|
|
253
|
|
254 /* Some functions don't like being interrupted with SIGALRM or SIGIO.
|
|
255 Previously we were calling stop_interrupts() / start_interrupts(),
|
|
256 but then if the program hangs in one of those functions, e.g.
|
|
257 waiting for a connect(), we're really screwed. So instead we
|
|
258 just "slow them down". We do this by disabling all interrupts
|
|
259 and then installing a timer of length fairly large, like 5 or
|
|
260 10 secs. That way, any "legitimate" connections (which should
|
|
261 take a fairly short amount of time) go through OK, but we can
|
|
262 interrupt bogus ones. */
|
|
263
|
|
264 void
|
|
265 slow_down_interrupts (void)
|
|
266 {
|
|
267 EMACS_TIME thyme;
|
|
268
|
|
269 /* We have to set the flag *before* setting the slowed-down timer,
|
|
270 to avoid a race condition -- if the signal occurs between the
|
|
271 call to set_one_shot_timer() and the setting of this flag,
|
|
272 alarm_happened will get set, which will be a Bad Thing if
|
|
273 there were no timeouts on the queue. */
|
|
274 interrupts_slowed_down++;
|
|
275 if (interrupts_slowed_down == 1)
|
|
276 {
|
|
277 stop_interrupts ();
|
|
278 EMACS_SET_SECS_USECS (thyme, SLOWED_DOWN_INTERRUPTS_SECS, 0);
|
|
279 set_one_shot_timer (thyme);
|
|
280 }
|
|
281 }
|
|
282
|
|
283 void
|
|
284 speed_up_interrupts (void)
|
|
285 {
|
|
286 if (interrupts_slowed_down > 0)
|
|
287 {
|
|
288 start_interrupts ();
|
|
289 /* Change this flag AFTER fiddling with interrupts, for the same
|
|
290 race-condition reasons as above. */
|
|
291 interrupts_slowed_down--;
|
|
292 }
|
|
293 }
|
|
294
|
|
295 static void
|
|
296 handle_alarm_going_off (void)
|
|
297 {
|
|
298 int interval_id;
|
|
299
|
|
300 /* If asynch. timeouts are blocked, then don't do anything now,
|
|
301 but make this function get called again next QUIT.
|
|
302
|
|
303 #### This is a bit inefficient because there will be function call
|
|
304 overhead each time QUIT occurs. */
|
|
305
|
|
306 if (!NILP (Vinhibit_quit))
|
|
307 {
|
|
308 something_happened = 1;
|
|
309 alarm_happened = 1;
|
|
310 return;
|
|
311 }
|
|
312
|
|
313 interval_id = pop_low_level_timeout (&async_timer_queue, 0);
|
|
314
|
|
315 reset_interval_timer ();
|
|
316 if (alarm_happened_while_emacs_was_blocking)
|
|
317 {
|
|
318 alarm_happened_while_emacs_was_blocking = 0;
|
|
319 waiting_for_user_input_p = 1;
|
|
320 }
|
|
321 event_stream_deal_with_async_timeout (interval_id);
|
|
322 waiting_for_user_input_p = 0;
|
|
323 }
|
|
324
|
|
325 #ifdef HAVE_SETITIMER
|
|
326 unsigned int
|
|
327 alarm (unsigned int howlong)
|
|
328 {
|
|
329 struct itimerval old_it, new_it;
|
|
330
|
|
331 /* If alarm() gets called when polling isn't disabled, it can mess
|
|
332 up the periodic timer. */
|
|
333 assert (async_timer_suppress_count > 0);
|
|
334
|
|
335 new_it.it_value.tv_sec = howlong;
|
|
336 new_it.it_value.tv_usec = 0;
|
|
337 new_it.it_interval.tv_sec = 0;
|
|
338 new_it.it_interval.tv_usec = 0;
|
|
339 setitimer (ITIMER_REAL, &new_it, &old_it);
|
|
340
|
|
341 /* Never return zero if there was a timer outstanding. */
|
|
342 return old_it.it_value.tv_sec + (old_it.it_value.tv_usec > 0 ? 1 : 0);
|
|
343 }
|
|
344 #endif
|
|
345
|
20
|
346 DEFUN ("waiting-for-user-input-p", Fwaiting_for_user_input_p, 0, 0, 0, /*
|
0
|
347 Return non-nil if XEmacs is waiting for input from the user.
|
|
348 This is intended for use by asynchronous timeout callbacks and by
|
|
349 asynchronous process output filters and sentinels (not yet implemented
|
|
350 in XEmacs). It will always be nil if XEmacs is not inside of
|
|
351 an asynchronout timeout or process callback.
|
20
|
352 */
|
|
353 ())
|
0
|
354 {
|
|
355 return ((waiting_for_user_input_p) ? Qt : Qnil);
|
|
356 }
|
|
357
|
|
358
|
|
359 /**********************************************************************/
|
|
360 /* Control-G checking */
|
|
361 /**********************************************************************/
|
|
362
|
|
363 /* Set this for debugging, to have a way to get out */
|
|
364 int stop_character; /* #### not currently implemented */
|
|
365
|
|
366 /* This routine is called in response to a SIGINT or SIGQUIT.
|
|
367 On TTY's, one of these two signals will get generated in response
|
|
368 to C-g. (When running under X, C-g is handled using the SIGIO
|
|
369 handler, which sets a flag telling the QUIT macro to scan the
|
|
370 unread events for a ^G.)
|
|
371
|
|
372 Otherwise it sets the Lisp variable quit-flag not-nil.
|
|
373 This causes eval to throw, when it gets a chance.
|
|
374 If quit-flag is already non-nil, it stops the job right away. */
|
|
375
|
|
376 static SIGTYPE
|
|
377 interrupt_signal (int sig)
|
|
378 {
|
70
|
379 /* This function can GC (?!) */
|
0
|
380 /* Must preserve main program's value of errno. */
|
|
381 int old_errno = errno;
|
|
382
|
|
383 EMACS_REESTABLISH_SIGNAL (sig, interrupt_signal);
|
|
384
|
|
385 /* with the macroized error-checking stuff, the garbage below
|
|
386 may mess things up because XCONSOLE() and such can use and
|
|
387 change global vars. */
|
|
388 #if ! (defined (ERROR_CHECK_TYPECHECK) && defined (MACROIZE_ERROR_CHECKING))
|
|
389 if (sigint_happened && CONSOLEP (Vcontrolling_terminal) &&
|
|
390 CONSOLE_LIVE_P (XCONSOLE (Vcontrolling_terminal)) &&
|
|
391 !emacs_is_blocking)
|
|
392 {
|
|
393 char c;
|
|
394 fflush (stdout);
|
|
395 reset_initial_console ();
|
|
396 EMACS_UNBLOCK_SIGNAL (sig);
|
|
397 #ifdef SIGTSTP /* Support possible in later USG versions */
|
|
398 /*
|
|
399 * On systems which can suspend the current process and return to the original
|
|
400 * shell, this command causes the user to end up back at the shell.
|
|
401 * The "Auto-save" and "Abort" questions are not asked until
|
|
402 * the user elects to return to emacs, at which point he can save the current
|
|
403 * job and either dump core or continue.
|
|
404 */
|
|
405 sys_suspend ();
|
|
406 #else
|
|
407 #ifdef VMS
|
|
408 if (sys_suspend () == -1)
|
|
409 {
|
|
410 stdout_out ("Not running as a subprocess;\n");
|
|
411 stdout_out ("you can continue or abort.\n");
|
|
412 }
|
|
413 #else /* not VMS */
|
|
414 /* Perhaps should really fork an inferior shell?
|
|
415 But that would not provide any way to get back
|
|
416 to the original shell, ever. */
|
|
417 stdout_out ("No support for stopping a process on this operating system;\n");
|
|
418 stdout_out ("you can continue or abort.\n");
|
|
419 #endif /* not VMS */
|
|
420 #endif /* not SIGTSTP */
|
|
421 stdout_out ("Auto-save? (y or n) ");
|
|
422 fflush (stdout);
|
|
423 if (((c = getc (stdin)) & ~040) == 'Y')
|
|
424 Fdo_auto_save (Qnil, Qnil);
|
|
425 while (c != '\n')
|
|
426 c = getc (stdin);
|
|
427 #ifdef VMS
|
|
428 stdout_out ("Abort (and enter debugger)? (y or n) ");
|
|
429 #else /* not VMS */
|
|
430 stdout_out ("Abort (and dump core)? (y or n) ");
|
|
431 #endif /* not VMS */
|
|
432 fflush (stdout);
|
|
433 if (((c = getc (stdin)) & ~040) == 'Y')
|
|
434 abort ();
|
|
435 while (c != '\n')
|
|
436 c = getc (stdin);
|
|
437 stdout_out ("Continuing...\n");
|
|
438 fflush (stdout);
|
|
439 reinit_initial_console ();
|
|
440 MARK_FRAME_CHANGED (XFRAME (DEVICE_SELECTED_FRAME
|
|
441 (XDEVICE (CONSOLE_SELECTED_DEVICE
|
|
442 (XCONSOLE
|
|
443 (Vcontrolling_terminal))))));
|
|
444 }
|
|
445 else
|
|
446 #endif /* ! (defined (ERROR_CHECKING) && defined (MACROIZE_ERROR_CHECKING)) */
|
|
447 {
|
|
448 /* Else request quit when it's safe */
|
|
449 Vquit_flag = Qt;
|
|
450 sigint_happened = 1;
|
|
451 signal_fake_event ();
|
|
452 }
|
|
453 errno = old_errno;
|
|
454 SIGRETURN;
|
|
455 }
|
|
456
|
|
457 static Lisp_Object
|
|
458 restore_dont_check_for_quit (Lisp_Object val)
|
|
459 {
|
|
460 dont_check_for_quit = XINT (val);
|
|
461 return Qnil;
|
|
462 }
|
|
463
|
|
464 void
|
|
465 begin_dont_check_for_quit (void)
|
|
466 {
|
|
467 specbind (Qinhibit_quit, Qt);
|
|
468 record_unwind_protect (restore_dont_check_for_quit,
|
|
469 make_int (dont_check_for_quit));
|
|
470 dont_check_for_quit = 1;
|
|
471 }
|
|
472
|
|
473 /* The effect of this function is to set Vquit_flag if the user pressed
|
|
474 ^G and discard the ^G, so as to not notice the same ^G again. */
|
|
475 int
|
|
476 check_quit (void)
|
|
477 {
|
|
478 /* dont_check_for_quit is set in two circumstances:
|
|
479
|
|
480 (1) when we are in the process of changing the window
|
|
481 configuration. The frame might be in an inconsistent state,
|
|
482 which will cause assertion failures if we check for QUIT.
|
|
483
|
|
484 (2) when we are reading events, and want to read the C-g
|
|
485 as an event. The normal check for quit will discard the C-g,
|
|
486 which would be bad.
|
|
487
|
|
488 #### C-g is still often read as quit, e.g. if you type C-x C-g
|
|
489 (the C-g happens during the sit-for in maybe_echo_keys(); even
|
|
490 if we attempt to inhibit quit here, there is still a check
|
|
491 later on for QUIT. To fix this properly requires a fairly
|
|
492 substantial overhaul of the quit-checking code, which is
|
|
493 probably not worth it.)
|
|
494
|
|
495 We should *not* conditionalize on Vinhibit_quit, or
|
|
496 critical-quit (Control-Shift-G) won't work right. */
|
|
497
|
|
498 if (dont_check_for_quit)
|
|
499 return 0;
|
|
500
|
|
501 if (quit_check_signal_happened)
|
|
502 {
|
|
503 quit_check_signal_happened = 0;
|
|
504 event_stream_quit_p ();
|
|
505 return 1;
|
|
506 }
|
|
507 else
|
|
508 return 0;
|
|
509 }
|
|
510
|
|
511 int
|
|
512 check_what_happened (void) /* called from QUIT when
|
|
513 something_happened gets set */
|
|
514 {
|
|
515 something_happened = 0;
|
|
516 if (alarm_happened)
|
|
517 {
|
|
518 alarm_happened = 0;
|
|
519 handle_alarm_going_off ();
|
|
520 }
|
|
521 return check_quit ();
|
|
522 }
|
|
523
|
|
524
|
|
525
|
|
526 void
|
|
527 init_poll_for_quit (void)
|
|
528 {
|
|
529 #if !defined (SIGIO) && !defined (DONT_POLL_FOR_QUIT)
|
|
530 /* Check for C-g every 1/4 of a second.
|
|
531
|
|
532 #### This is just a guess. Some investigation will have to be
|
|
533 done to see what the best value is. The best value is the
|
|
534 smallest possible value that doesn't cause a significant amount
|
|
535 of running time to be spent in C-g checking. */
|
|
536 if (!poll_for_quit_id)
|
|
537 poll_for_quit_id =
|
|
538 event_stream_generate_wakeup (NORMAL_QUIT_CHECK_TIMEOUT_MSECS,
|
|
539 NORMAL_QUIT_CHECK_TIMEOUT_MSECS,
|
|
540 Qnil, Qnil, 1);
|
|
541 #endif /* not SIGIO and not DONT_POLL_FOR_QUIT */
|
|
542 }
|
|
543
|
|
544 void
|
|
545 reset_poll_for_quit (void)
|
|
546 {
|
|
547 #if !defined (SIGIO) && !defined (DONT_POLL_FOR_QUIT)
|
|
548 if (poll_for_quit_id)
|
|
549 {
|
|
550 event_stream_disable_wakeup (poll_for_quit_id, 1);
|
|
551 poll_for_quit_id = 0;
|
|
552 }
|
|
553 #endif /* not SIGIO and not DONT_POLL_FOR_QUIT */
|
|
554 }
|
|
555
|
|
556 #ifndef SIGCHLD
|
|
557
|
|
558 static void
|
|
559 init_poll_for_sigchld (void)
|
|
560 {
|
|
561 /* Check for terminated processes every 1/4 of a second.
|
|
562
|
|
563 #### This is just a guess. Some investigation will have to be
|
|
564 done to see what the best value is. The best value is the
|
|
565 smallest possible value that doesn't cause a significant amount
|
|
566 of running time to be spent in process-termination checking.
|
|
567 */
|
|
568 poll_for_sigchld_id =
|
|
569 event_stream_generate_wakeup (NORMAL_SIGCHLD_CHECK_TIMEOUT_MSECS,
|
|
570 NORMAL_SIGCHLD_CHECK_TIMEOUT_MSECS,
|
|
571 Qnil, Qnil, 1);
|
|
572 }
|
|
573
|
|
574 #endif /* not SIGCHLD */
|
|
575
|
|
576 #ifdef SIGIO
|
|
577
|
|
578 static void
|
|
579 input_available_signal (int signo)
|
|
580 {
|
|
581 something_happened = 1; /* tell QUIT to wake up */
|
|
582 quit_check_signal_happened = 1;
|
|
583 quit_check_signal_tick_count++;
|
|
584 EMACS_REESTABLISH_SIGNAL (signo, input_available_signal);
|
|
585 SIGRETURN;
|
|
586 }
|
|
587
|
|
588 #endif /* SIGIO */
|
|
589
|
|
590
|
|
591 /**********************************************************************/
|
|
592 /* Enabling/disabling signals */
|
|
593 /**********************************************************************/
|
|
594
|
|
595 static int interrupts_initted;
|
|
596
|
|
597 void
|
|
598 stop_interrupts (void)
|
|
599 {
|
|
600 if (!interrupts_initted)
|
|
601 return;
|
|
602 #ifdef SIGIO
|
|
603 unrequest_sigio ();
|
|
604 #endif
|
|
605 stop_async_timeouts ();
|
|
606 }
|
|
607
|
|
608 void
|
|
609 start_interrupts (void)
|
|
610 {
|
|
611 if (!interrupts_initted)
|
|
612 return;
|
|
613 #ifdef SIGIO
|
|
614 request_sigio ();
|
|
615 #endif
|
|
616 start_async_timeouts ();
|
|
617 }
|
|
618
|
|
619 /* Cheesy but workable implementation of sleep() that doesn't
|
16
|
620 interfere with our periodic timers. */
|
0
|
621
|
|
622 void
|
|
623 emacs_sleep (int secs)
|
|
624 {
|
|
625 stop_interrupts ();
|
|
626 sleep (secs);
|
|
627 start_interrupts ();
|
|
628 }
|
|
629
|
|
630
|
|
631 /************************************************************************/
|
|
632 /* initialization */
|
|
633 /************************************************************************/
|
|
634
|
|
635 void
|
|
636 init_signals_very_early (void)
|
|
637 {
|
|
638 /* Catch all signals that would kill us. */
|
|
639 if (! noninteractive || initialized)
|
|
640 {
|
|
641 /* Don't catch these signals in batch mode if not initialized.
|
|
642 On some machines, this sets static data that would make
|
|
643 signal fail to work right when the dumped Emacs is run. */
|
16
|
644 signal (SIGHUP, fatal_error_signal);
|
0
|
645 signal (SIGQUIT, fatal_error_signal);
|
16
|
646 signal (SIGILL, fatal_error_signal);
|
0
|
647 signal (SIGTRAP, fatal_error_signal);
|
|
648 #ifdef SIGABRT
|
|
649 signal (SIGABRT, fatal_error_signal);
|
|
650 #endif
|
|
651 #ifdef SIGHWE
|
|
652 signal (SIGHWE, fatal_error_signal);
|
|
653 #endif
|
|
654 #ifdef SIGPRE
|
|
655 signal (SIGPRE, fatal_error_signal);
|
|
656 #endif
|
|
657 #ifdef SIGORE
|
|
658 signal (SIGORE, fatal_error_signal);
|
|
659 #endif
|
|
660 #ifdef SIGUME
|
|
661 signal (SIGUME, fatal_error_signal);
|
|
662 #endif
|
|
663 #ifdef SIGDLK
|
|
664 signal (SIGDLK, fatal_error_signal);
|
|
665 #endif
|
|
666 #ifdef SIGCPULIM
|
|
667 signal (SIGCPULIM, fatal_error_signal);
|
|
668 #endif
|
|
669 #ifdef SIGIOT
|
|
670 signal (SIGIOT, fatal_error_signal);
|
|
671 #endif
|
|
672 #ifdef SIGEMT
|
|
673 signal (SIGEMT, fatal_error_signal);
|
|
674 #endif
|
|
675 signal (SIGFPE, fatal_error_signal);
|
|
676 #ifdef SIGBUS
|
|
677 signal (SIGBUS, fatal_error_signal);
|
|
678 #endif
|
|
679 signal (SIGSEGV, fatal_error_signal);
|
|
680 #ifdef SIGSYS
|
|
681 signal (SIGSYS, fatal_error_signal);
|
|
682 #endif
|
|
683 signal (SIGPIPE, fatal_error_signal);
|
|
684 signal (SIGTERM, fatal_error_signal);
|
|
685 #ifdef SIGXCPU
|
|
686 signal (SIGXCPU, fatal_error_signal);
|
|
687 #endif
|
|
688 #ifdef SIGXFSZ
|
|
689 signal (SIGXFSZ, fatal_error_signal);
|
|
690 #endif /* SIGXFSZ */
|
|
691
|
|
692 #ifdef SIGDANGER
|
|
693 /* This just means available memory is getting low. */
|
|
694 signal (SIGDANGER, memory_warning_signal);
|
|
695 #endif
|
|
696
|
|
697 #ifdef SIGLOST
|
|
698 signal (SIGLOST, fatal_error_signal);
|
|
699 #endif
|
|
700 #ifdef SIGSTKFLT /* coprocessor stack fault under Linux */
|
|
701 signal (SIGSTKFLT, fatal_error_signal);
|
|
702 #endif
|
|
703 #ifdef SIGUSR1
|
|
704 signal (SIGUSR1, fatal_error_signal);
|
|
705 #endif
|
|
706 #ifdef SIGUSR2
|
|
707 signal (SIGUSR2, fatal_error_signal);
|
|
708 #endif
|
|
709 #ifdef SIGALRM
|
|
710 /* This will get reset later, once we're capable of handling
|
|
711 this properly. */
|
|
712 signal (SIGALRM, fatal_error_signal);
|
|
713 #endif
|
|
714 #ifdef SIGVTALRM
|
|
715 signal (SIGVTALRM, fatal_error_signal);
|
|
716 #endif
|
|
717 #ifdef SIGPROF
|
16
|
718 /* Messes up the REAL profiler */
|
|
719 /* signal (SIGPROF, fatal_error_signal); */
|
0
|
720 #endif
|
|
721 #ifdef SIGUNUSED /* exists under Linux, and will kill process! */
|
|
722 signal (SIGUNUSED, fatal_error_signal);
|
|
723 #endif
|
|
724
|
|
725 #ifdef AIX
|
|
726 /* 20 is SIGCHLD, 21 is SIGTTIN, 22 is SIGTTOU. */
|
|
727 #ifndef _I386
|
|
728 signal (SIGIOINT, fatal_error_signal);
|
|
729 #endif
|
16
|
730 signal (SIGGRANT, fatal_error_signal);
|
0
|
731 signal (SIGRETRACT, fatal_error_signal);
|
16
|
732 signal (SIGSOUND, fatal_error_signal);
|
|
733 signal (SIGMSG, fatal_error_signal);
|
0
|
734 #endif /* AIX */
|
|
735 }
|
|
736 }
|
|
737
|
|
738 void
|
|
739 syms_of_signal (void)
|
|
740 {
|
20
|
741 DEFSUBR (Fwaiting_for_user_input_p);
|
0
|
742 }
|
|
743
|
|
744 void
|
|
745 init_interrupts_late (void)
|
|
746 {
|
|
747 if (!noninteractive)
|
|
748 {
|
|
749 signal (SIGINT, interrupt_signal);
|
|
750 #ifdef HAVE_TERMIO
|
|
751 /* On systems with TERMIO, C-g is set up for both SIGINT and SIGQUIT
|
|
752 and we can't tell which one it will give us. */
|
|
753 signal (SIGQUIT, interrupt_signal);
|
|
754 #endif /* HAVE_TERMIO */
|
|
755 init_async_timeouts ();
|
|
756 #ifdef SIGIO
|
|
757 signal (SIGIO, input_available_signal);
|
|
758 # ifdef SIGPOLL
|
|
759 /* Some systems (e.g. Motorola SVR4) losingly have different
|
|
760 values for SIGIO and SIGPOLL, and send SIGPOLL instead of
|
|
761 SIGIO. On those same systems, an uncaught SIGPOLL kills the
|
|
762 process. */
|
|
763 signal (SIGPOLL, input_available_signal);
|
|
764 # endif
|
|
765 #elif !defined (DONT_POLL_FOR_QUIT)
|
|
766 init_poll_for_quit ();
|
|
767 #endif
|
|
768 }
|
|
769
|
|
770 #ifndef SIGCHLD
|
|
771 init_poll_for_sigchld ();
|
|
772 #endif
|
|
773
|
|
774 EMACS_UNBLOCK_ALL_SIGNALS ();
|
|
775
|
|
776 interrupts_initted = 1;
|
|
777 }
|
|
778
|