annotate src/signal.c @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents 8626e4521993
children 2f8bb876ab1d
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 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 #include "lisp.h"
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 "console.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 #include "events.h" /* for signal_fake_event() */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #include "frame.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 #include "sysdep.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 #include "syssignal.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 #include "systime.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
34 #ifdef HAVE_UNISTD_H
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
35 #include <unistd.h>
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
36 #endif
0
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
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
66 #if defined(HAVE_UNIX_PROCESSES) && !defined(SIGCHLD)
0
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
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 70
diff changeset
78 #define SLOWED_DOWN_INTERRUPTS_SECS 15
0
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
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
183 #ifdef WINDOWSNT
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
184 can_break_system_calls = 0;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
185 #else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 /* can_break_system_calls is set when we want to break out of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 non-interruptible system calls. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 if (can_break_system_calls)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 /* reset the flag for safety and such. Do this *before*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 unblocking or reestablishing the signal to avoid potential
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 race conditions. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 can_break_system_calls = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 EMACS_UNBLOCK_SIGNAL (signo);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 EMACS_REESTABLISH_SIGNAL (signo, alarm_signal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 LONGJMP (break_system_call_jump, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 }
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
198 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 EMACS_REESTABLISH_SIGNAL (signo, alarm_signal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 SIGRETURN;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 something_happened = 1; /* tell QUIT to wake up */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 alarm_happened = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 if (emacs_is_blocking)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 alarm_happened_while_emacs_was_blocking = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 /* #### This is for QUITP. When it is run, it may not be the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 place to do arbitrary stuff like run asynch. handlers, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 it needs to know whether the poll-for-quit asynch. timeout
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 went off. Rather than put the code in to compute this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 specially, we just set this flag. Should fix this. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 quit_check_signal_happened = 1;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
214
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
215 #ifdef HAVE_UNIXOID_EVENT_LOOP
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 signal_fake_event ();
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
217 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 EMACS_REESTABLISH_SIGNAL (signo, alarm_signal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 SIGRETURN;
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 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 init_async_timeouts (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 signal (SIGALRM, alarm_signal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 async_timer_suppress_count = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 /* Turn off async timeouts. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 stop_async_timeouts (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 if (async_timer_suppress_count == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 /* If timer was on, turn it off. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 EMACS_TIME thyme;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 EMACS_SET_SECS_USECS (thyme, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 set_one_shot_timer (thyme);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 async_timer_suppress_count++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 /* Turn on async timeouts again. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 start_async_timeouts (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 assert (async_timer_suppress_count > 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 async_timer_suppress_count--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 if (async_timer_suppress_count == 0)
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 callers turn off async timeouts and then use the alarm
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 for their own purposes; so reinitialize everything. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 signal (SIGALRM, alarm_signal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 reset_interval_timer ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 /* Some functions don't like being interrupted with SIGALRM or SIGIO.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 Previously we were calling stop_interrupts() / start_interrupts(),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 but then if the program hangs in one of those functions, e.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 waiting for a connect(), we're really screwed. So instead we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 just "slow them down". We do this by disabling all interrupts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 and then installing a timer of length fairly large, like 5 or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 10 secs. That way, any "legitimate" connections (which should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 take a fairly short amount of time) go through OK, but we can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 interrupt bogus ones. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 slow_down_interrupts (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 EMACS_TIME thyme;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 /* We have to set the flag *before* setting the slowed-down timer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 to avoid a race condition -- if the signal occurs between the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 call to set_one_shot_timer() and the setting of this flag,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 alarm_happened will get set, which will be a Bad Thing if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 there were no timeouts on the queue. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 interrupts_slowed_down++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 if (interrupts_slowed_down == 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 stop_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 EMACS_SET_SECS_USECS (thyme, SLOWED_DOWN_INTERRUPTS_SECS, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 set_one_shot_timer (thyme);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 speed_up_interrupts (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 if (interrupts_slowed_down > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 start_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 /* Change this flag AFTER fiddling with interrupts, for the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 race-condition reasons as above. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 interrupts_slowed_down--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 handle_alarm_going_off (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 int interval_id;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 /* If asynch. timeouts are blocked, then don't do anything now,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 but make this function get called again next QUIT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 #### This is a bit inefficient because there will be function call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 overhead each time QUIT occurs. */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
312
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 if (!NILP (Vinhibit_quit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 something_happened = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 alarm_happened = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 interval_id = pop_low_level_timeout (&async_timer_queue, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 reset_interval_timer ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 if (alarm_happened_while_emacs_was_blocking)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 alarm_happened_while_emacs_was_blocking = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 waiting_for_user_input_p = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 event_stream_deal_with_async_timeout (interval_id);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 waiting_for_user_input_p = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 #ifdef HAVE_SETITIMER
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 unsigned int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 alarm (unsigned int howlong)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 struct itimerval old_it, new_it;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 /* If alarm() gets called when polling isn't disabled, it can mess
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 up the periodic timer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 assert (async_timer_suppress_count > 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 new_it.it_value.tv_sec = howlong;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 new_it.it_value.tv_usec = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 new_it.it_interval.tv_sec = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 new_it.it_interval.tv_usec = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 setitimer (ITIMER_REAL, &new_it, &old_it);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 /* Never return zero if there was a timer outstanding. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 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
350 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
353 DEFUN ("waiting-for-user-input-p", Fwaiting_for_user_input_p, 0, 0, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 Return non-nil if XEmacs is waiting for input from the user.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 This is intended for use by asynchronous timeout callbacks and by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 asynchronous process output filters and sentinels (not yet implemented
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 in XEmacs). It will always be nil if XEmacs is not inside of
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 280
diff changeset
358 an asynchronous timeout or process callback.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
359 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
360 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
362 return waiting_for_user_input_p ? Qt : Qnil;
0
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 /* Control-G checking */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 /* Set this for debugging, to have a way to get out */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 int stop_character; /* #### not currently implemented */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 /* This routine is called in response to a SIGINT or SIGQUIT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 On TTY's, one of these two signals will get generated in response
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 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
376 handler, which sets a flag telling the QUIT macro to scan the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 unread events for a ^G.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 Otherwise it sets the Lisp variable quit-flag not-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 This causes eval to throw, when it gets a chance.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 If quit-flag is already non-nil, it stops the job right away. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 static SIGTYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 interrupt_signal (int sig)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 {
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
386 /* This function can call lisp */
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
387 /* #### we should NOT be calling lisp from a signal handler, boys
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
388 and girls */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 /* Must preserve main program's value of errno. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 int old_errno = errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 EMACS_REESTABLISH_SIGNAL (sig, interrupt_signal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 /* with the macroized error-checking stuff, the garbage below
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 may mess things up because XCONSOLE() and such can use and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 change global vars. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 #if ! (defined (ERROR_CHECK_TYPECHECK) && defined (MACROIZE_ERROR_CHECKING))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 if (sigint_happened && CONSOLEP (Vcontrolling_terminal) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 CONSOLE_LIVE_P (XCONSOLE (Vcontrolling_terminal)) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 !emacs_is_blocking)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 char c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 fflush (stdout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 reset_initial_console ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 EMACS_UNBLOCK_SIGNAL (sig);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 #ifdef SIGTSTP /* Support possible in later USG versions */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 * On systems which can suspend the current process and return to the original
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 * shell, this command causes the user to end up back at the shell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 * The "Auto-save" and "Abort" questions are not asked until
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 * 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
412 * job and either dump core or continue.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 sys_suspend ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 #else
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 SIGTSTP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 stdout_out ("Auto-save? (y or n) ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 fflush (stdout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 if (((c = getc (stdin)) & ~040) == 'Y')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 Fdo_auto_save (Qnil, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 while (c != '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 c = getc (stdin);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 stdout_out ("Abort (and dump core)? (y or n) ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 fflush (stdout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 if (((c = getc (stdin)) & ~040) == 'Y')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 while (c != '\n')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 c = getc (stdin);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 stdout_out ("Continuing...\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 fflush (stdout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 reinit_initial_console ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 MARK_FRAME_CHANGED (XFRAME (DEVICE_SELECTED_FRAME
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (XDEVICE (CONSOLE_SELECTED_DEVICE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (XCONSOLE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (Vcontrolling_terminal))))));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 #endif /* ! (defined (ERROR_CHECKING) && defined (MACROIZE_ERROR_CHECKING)) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 /* Else request quit when it's safe */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 Vquit_flag = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 sigint_happened = 1;
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
448 #ifdef HAVE_UNIXOID_EVENT_LOOP
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 signal_fake_event ();
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 209
diff changeset
450 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 errno = old_errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 SIGRETURN;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 restore_dont_check_for_quit (Lisp_Object val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 dont_check_for_quit = XINT (val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 begin_dont_check_for_quit (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 specbind (Qinhibit_quit, Qt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 record_unwind_protect (restore_dont_check_for_quit,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 make_int (dont_check_for_quit));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 dont_check_for_quit = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 /* 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
473 ^G and discard the ^G, so as to not notice the same ^G again. */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
474 int
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 check_quit (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 /* dont_check_for_quit is set in two circumstances:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (1) when we are in the process of changing the window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 configuration. The frame might be in an inconsistent state,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 which will cause assertion failures if we check for QUIT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (2) when we are reading events, and want to read the C-g
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 as an event. The normal check for quit will discard the C-g,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 which would be bad.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 #### 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
488 (the C-g happens during the sit-for in maybe_echo_keys(); even
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 if we attempt to inhibit quit here, there is still a check
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 later on for QUIT. To fix this properly requires a fairly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 substantial overhaul of the quit-checking code, which is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 probably not worth it.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 We should *not* conditionalize on Vinhibit_quit, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 critical-quit (Control-Shift-G) won't work right. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 if (dont_check_for_quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 return 0;
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 (quit_check_signal_happened)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 quit_check_signal_happened = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 event_stream_quit_p ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 check_what_happened (void) /* called from QUIT when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 something_happened gets set */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 something_happened = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 if (alarm_happened)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 alarm_happened = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 handle_alarm_going_off ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 return check_quit ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 251
diff changeset
523
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 init_poll_for_quit (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 #if !defined (SIGIO) && !defined (DONT_POLL_FOR_QUIT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 /* Check for C-g every 1/4 of a second.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 #### This is just a guess. Some investigation will have to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 done to see what the best value is. The best value is the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 smallest possible value that doesn't cause a significant amount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 of running time to be spent in C-g checking. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 if (!poll_for_quit_id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 poll_for_quit_id =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 event_stream_generate_wakeup (NORMAL_QUIT_CHECK_TIMEOUT_MSECS,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 NORMAL_QUIT_CHECK_TIMEOUT_MSECS,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 Qnil, Qnil, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 #endif /* not SIGIO and not DONT_POLL_FOR_QUIT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 reset_poll_for_quit (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 #if !defined (SIGIO) && !defined (DONT_POLL_FOR_QUIT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 if (poll_for_quit_id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 event_stream_disable_wakeup (poll_for_quit_id, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 poll_for_quit_id = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 #endif /* not SIGIO and not DONT_POLL_FOR_QUIT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
555 #if defined(HAVE_UNIX_PROCESSES) && !defined(SIGCHLD)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 init_poll_for_sigchld (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 /* Check for terminated processes every 1/4 of a second.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 #### This is just a guess. Some investigation will have to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 done to see what the best value is. The best value is the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 smallest possible value that doesn't cause a significant amount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 of running time to be spent in process-termination checking.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 poll_for_sigchld_id =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 event_stream_generate_wakeup (NORMAL_SIGCHLD_CHECK_TIMEOUT_MSECS,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 NORMAL_SIGCHLD_CHECK_TIMEOUT_MSECS,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 Qnil, Qnil, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 #endif /* not SIGCHLD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 #ifdef SIGIO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 input_available_signal (int signo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 something_happened = 1; /* tell QUIT to wake up */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 quit_check_signal_happened = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 quit_check_signal_tick_count++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 EMACS_REESTABLISH_SIGNAL (signo, input_available_signal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 SIGRETURN;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 #endif /* SIGIO */
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 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 /* Enabling/disabling signals */
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 static int interrupts_initted;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 stop_interrupts (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 if (!interrupts_initted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 return;
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 223
diff changeset
601 #if defined(SIGIO) && !defined(BROKEN_SIGIO)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 unrequest_sigio ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 stop_async_timeouts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 start_interrupts (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 if (!interrupts_initted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 return;
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 223
diff changeset
612 #if defined(SIGIO) && !defined(BROKEN_SIGIO)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 request_sigio ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 start_async_timeouts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 /* Cheesy but workable implementation of sleep() that doesn't
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
619 interfere with our periodic timers. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 emacs_sleep (int secs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 stop_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 sleep (secs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 start_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 /* initialization */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
634 /* If we've been nohup'ed, keep it that way.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
635 This allows `nohup xemacs &' to work.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
636 More generally, if a normally fatal signal has been redirected
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
637 to SIG_IGN by our invocation environment, trust the environment.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
638 This keeps xemacs from being killed by a SIGQUIT intended for a
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
639 different process after having been backgrounded under a
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
640 non-job-control shell! */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
641 static void
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
642 handle_signal_if_fatal (int signo)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
643 {
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
644 if (signal (signo, fatal_error_signal) == SIG_IGN)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
645 signal (signo, SIG_IGN);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
646 }
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
647
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 init_signals_very_early (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 {
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
651 /* Catch all signals that would kill us.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
652 Don't catch these signals in batch mode if not initialized.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
653 On some machines, this sets static data that would make
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
654 signal fail to work right when the dumped Emacs is run. */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
655 if (noninteractive && !initialized)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
656 return;
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
657
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
658 handle_signal_if_fatal (SIGILL); /* ANSI */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
659 handle_signal_if_fatal (SIGABRT); /* ANSI */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
660 handle_signal_if_fatal (SIGFPE); /* ANSI */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
661 handle_signal_if_fatal (SIGSEGV); /* ANSI */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
662 handle_signal_if_fatal (SIGTERM); /* ANSI */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
663
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
664
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
665 #ifdef SIGHUP
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
666 handle_signal_if_fatal (SIGHUP); /* POSIX */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
667 #endif
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
668 #ifdef SIGQUIT
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
669 handle_signal_if_fatal (SIGQUIT); /* POSIX */
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
670 #endif
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
671 #ifdef SIGTRAP
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
672 handle_signal_if_fatal (SIGTRAP); /* POSIX */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
673 #endif
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
674 #ifdef SIGUSR1
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
675 handle_signal_if_fatal (SIGUSR1); /* POSIX */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
676 #endif
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
677 #ifdef SIGUSR2
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
678 handle_signal_if_fatal (SIGUSR2); /* POSIX */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
679 #endif
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
680 #ifdef SIGPIPE
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
681 handle_signal_if_fatal (SIGPIPE); /* POSIX */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
682 #endif
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
683 #ifdef SIGALRM
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
684 /* This will get reset later, once we're
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
685 capable of handling it properly. */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
686 handle_signal_if_fatal (SIGALRM); /* POSIX */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
687 #endif
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
688
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
689
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
690 #ifdef SIGBUS
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
691 handle_signal_if_fatal (SIGBUS); /* XPG5 */
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
692 #endif
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
693 #ifdef SIGSYS
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
694 handle_signal_if_fatal (SIGSYS); /* XPG5 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
695 #endif
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
696 #ifdef SIGXCPU
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
697 handle_signal_if_fatal (SIGXCPU); /* XPG5 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
698 #endif
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
699 #ifdef SIGXFSZ
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
700 handle_signal_if_fatal (SIGXFSZ); /* XPG5 */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 #endif
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
702 #ifdef SIGVTALRM
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
703 handle_signal_if_fatal (SIGVTALRM); /* XPG5 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
704 #endif
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
705 #ifdef SIGPROF
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
706 /* Messes up the REAL profiler */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
707 /* handle_signal_if_fatal (SIGPROF); */ /* XPG5 */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
708 #endif
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
709
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
710
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 #ifdef SIGHWE
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
712 handle_signal_if_fatal (SIGHWE);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 #ifdef SIGPRE
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
715 handle_signal_if_fatal (SIGPRE);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 #ifdef SIGORE
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
718 handle_signal_if_fatal (SIGORE);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 #ifdef SIGUME
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
721 handle_signal_if_fatal (SIGUME);
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 SIGDLK
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
724 handle_signal_if_fatal (SIGDLK);
0
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 #ifdef SIGCPULIM
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
727 handle_signal_if_fatal (SIGCPULIM);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 #ifdef SIGIOT
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
730 handle_signal_if_fatal (SIGIOT);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 #ifdef SIGEMT
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
733 handle_signal_if_fatal (SIGEMT);
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
734 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 #ifdef SIGLOST
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
736 handle_signal_if_fatal (SIGLOST);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 #ifdef SIGSTKFLT /* coprocessor stack fault under Linux */
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
739 handle_signal_if_fatal (SIGSTKFLT);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 #ifdef SIGUNUSED /* exists under Linux, and will kill process! */
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
742 handle_signal_if_fatal (SIGUNUSED);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 #ifdef AIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 /* 20 is SIGCHLD, 21 is SIGTTIN, 22 is SIGTTOU. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 #ifndef _I386
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
748 handle_signal_if_fatal (SIGIOINT);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 #endif
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
750 handle_signal_if_fatal (SIGGRANT);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
751 handle_signal_if_fatal (SIGRETRACT);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
752 handle_signal_if_fatal (SIGSOUND);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
753 handle_signal_if_fatal (SIGMSG);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 #endif /* AIX */
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
755
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
756 #ifdef SIGDANGER
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
757 /* This just means available memory is getting low. */
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
758 signal (SIGDANGER, memory_warning_signal);
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
759 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 syms_of_signal (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 {
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
765 DEFSUBR (Fwaiting_for_user_input_p);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 init_interrupts_late (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 if (!noninteractive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 signal (SIGINT, interrupt_signal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 #ifdef HAVE_TERMIO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 /* 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
776 and we can't tell which one it will give us. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 signal (SIGQUIT, interrupt_signal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 #endif /* HAVE_TERMIO */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 init_async_timeouts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 #ifdef SIGIO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 signal (SIGIO, input_available_signal);
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
782 # ifdef SIGPOLL /* XPG5 */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 /* Some systems (e.g. Motorola SVR4) losingly have different
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 values for SIGIO and SIGPOLL, and send SIGPOLL instead of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 SIGIO. On those same systems, an uncaught SIGPOLL kills the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 process. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 signal (SIGPOLL, input_available_signal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 #elif !defined (DONT_POLL_FOR_QUIT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 init_poll_for_quit ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
794 #if defined(HAVE_UNIX_PROCESSES) && !defined(SIGCHLD)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 init_poll_for_sigchld ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 EMACS_UNBLOCK_ALL_SIGNALS ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 interrupts_initted = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802