annotate src/signal.c @ 518:e6e7cbdea419

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