annotate src/signal.c @ 16:0293115a14e9 r19-15b91

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