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