annotate src/signal.c @ 617:af57a77cbc92

[xemacs-hg @ 2001-06-18 07:09:50 by ben] --------------------------------------------------------------- DOCUMENTATION FIXES: --------------------------------------------------------------- eval.c: Correct documentation. elhash.c: Doc correction. --------------------------------------------------------------- LISP OBJECT CLEANUP: --------------------------------------------------------------- bytecode.h, buffer.h, casetab.h, chartab.h, console-msw.h, console.h, database.c, device.h, eldap.h, elhash.h, events.h, extents.h, faces.h, file-coding.h, frame.h, glyphs.h, gui-x.h, gui.h, keymap.h, lisp-disunion.h, lisp-union.h, lisp.h, lrecord.h, lstream.h, mule-charset.h, objects.h, opaque.h, postgresql.h, process.h, rangetab.h, specifier.h, toolbar.h, tooltalk.h, ui-gtk.h: Add wrap_* to all objects (it was already there for a few of them) -- an expression to encapsulate a pointer into a Lisp object, rather than the inconvenient XSET*. "wrap" was chosen because "make" as in make_int(), make_char() is not appropriate. (It implies allocation. The issue does not exist for ints and chars because they are not allocated.) Full error checking has been added to these expressions. When used without error checking, non-union build, use of these expressions will incur no loss of efficiency. (In fact, XSET* is now defined in terms of wrap_* in a non-union build.) In a union build, you will also get no loss of efficiency provided that you have a decent optimizing compiler, and a compiler that either understands inlines or automatically inlines those particular functions. (And since people don't normally do their production builds on union, it doesn't matter.) Update the sample Lisp object definition in lrecord.h accordingly. dumper.c: Fix places in dumper that referenced wrap_object to reference its new name, wrap_pointer_1. buffer.c, bufslots.h, conslots.h, console.c, console.h, devslots.h, device.c, device.h, frame.c, frame.h, frameslots.h, window.c, window.h, winslots.h: -- Extract out the Lisp objects of `struct device' into devslots.h, just like for the other structures. -- Extract out the remaining (not copied into the window config) Lisp objects in `struct window' into winslots.h; use different macros (WINDOW_SLOT vs. WINDOW_SAVED_SLOT) to differentiate them. -- Eliminate the `dead' flag of `struct frame', since it duplicates information already available in `framemeths', and fix FRAME_LIVE_P accordingly. (Devices and consoles already work this way.) -- In *slots.h, switch to system where MARKED_SLOT is automatically undef'd at the end of the file. (Follows what winslots.h already does.) -- Update the comments at the beginning of *slots.h to be accurate. -- When making any of the above objects dead, zero it out entirely and reset all Lisp object slots to Qnil. (We were already doing this somewhat, but not consistently.) This (1) Eliminates the possibility of extra objects hanging around that ought to be GC'd, (2) Causes an immediate crash if anyone tries to access a structure in one of these objects, (3) Ensures consistent behavior wrt dead objects. dialog-msw.c: Use internal_object_printer, since this object should not escape. --------------------------------------------------------------- FIXING A CRASH THAT I HIT ONCE (AND A RELATED BAD BEHAVIOR): --------------------------------------------------------------- eval.c: Fix up some comments about the FSF implementation. Fix two nasty bugs: (1) condition_case_unwind frees the conses sitting in the catch->tag slot too quickly, resulting in a crash that I hit. (2) catches need to be unwound one at a time when calling unwind-protect code, rather than all at once at the end; otherwise, incorrect behavior can result. (A comment shows exactly how.) backtrace.h: Improve comment about FSF differences in the handler stack. --------------------------------------------------------------- FIXING A CRASH THAT I REPEATEDLY HIT WHEN USING THE MOUSE WHEEL UNDER MSWINDOWS: --------------------------------------------------------------- Basic idea: My crash is due either to a dead, non-marked, GC-collected frame inside of a window mirror, or a prematurely freed window mirror. We need to mark the Lisp objects inside of window mirrors. Tracking the lifespan of window mirrors and scrollbar instances is extremely hard, and there may well be lurking bugs where such objects are freed too soon. The only safe way to fix these problems (and it fixes both problems at once) is to make both of these structures Lisp objects. lrecord.h, emacs.c, inline.c, scrollbar-gtk.c, scrollbar-msw.c, scrollbar-x.c, scrollbar.c, scrollbar.h, symsinit.h: Make scrollbar instances actual Lisp objects. Mark the window mirrors in them. inline.c needs to know about scrollbar.h now. Record the new type in lrecord.h. Fix up scrollbar-*.c appropriately. Create a hash table in scrollbar-msw.c so that the scrollbar instances stored in scrollbar HWND's are properly GC-protected. Create complex_vars_of_scrollbar_mswindows() to create the hash table at startup, and call it from emacs.c. Don't store the scrollbar instance as a property of the GTK scrollbar, as it's not used and if we did this, we'd have to separately GC-protect it in a hash table, like in MS Windows. lrecord.h, frame.h, frame.c, frameslots.h, redisplay.c, window.c, window.h: Move mark_window_mirror from redisplay.c to window.c. Make window mirrors actual Lisp objects. Tell lrecord.h about them. Change the window mirror member of struct frame from a pointer to a Lisp object, and add XWINDOW_MIRROR in appropriate places. Mark the scrollbar instances in the window mirror. redisplay.c, redisplay.h, alloc.c: Delete mark_redisplay. Don't call mark_redisplay. We now mark frame-specific structures in mark_frame. NOTE: I also deleted an extremely questionable call to update_frame_window_mirrors(). It was extremely questionable before, and now totally impossible, since it will create Lisp objects during redisplay. frame.c: Mark the scrollbar instances, which are now Lisp objects. Call mark_gutter() here, not in mark_redisplay(). gutter.c: Update comments about correct marking. --------------------------------------------------------------- ISSUES BROUGHT UP BY MARTIN: --------------------------------------------------------------- buffer.h: Put back these macros the way Steve T and I think they ought to be. I already explained in a previous changelog entry why I think these macros should be the way I'd defined them. Once again: We fix these macros so they don't care about the type of their lvalues. The non-C-string equivalents of these already function in the same way, and it's correct because it should be OK to pass in a CBufbyte *, a BufByte *, a Char_Binary *, an UChar_Binary *, etc. The whole reason for these different types is to work around errors caused by signed-vs-unsigned non-matching types. Any possible error that might be caught in a DFC macro would also be caught wherever the argument is used elsewhere. So creating multiple macro versions would add no useful error-checking and just further complicate an already complicated area. As for Martin's "ANSI aliasing" bug, XEmacs is not ANSI-aliasing clean and probably never will be. Unless the board agrees to change XEmacs in this way (and we really don't want to go down that road), this is not a bug. sound.h: Undo Martin's type change. signal.c: Fix problem identified by Martin with Linux and g++ due to non-standard declaration of setitimer(). systime.h: Update the docs for "qxe_" to point out why making the encapsulation explicit is always the right way to go. (setitimer() itself serves as an example.) For 21.4: update-elc-2.el: Correct misplaced parentheses, making lisp/mule not get recompiled.
author ben
date Mon, 18 Jun 2001 07:10:32 +0000
parents 023b83f4e54b
children 943eaba38521
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Handling asynchronous signals.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
3 Copyright (C) 1995, 1996, 2001 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 /* Synched up with: Not synched with FSF. Split out of keyboard.c. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 #include "console.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #include "events.h" /* for signal_fake_event() */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 #include "frame.h"
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
30 #include "process.h"
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
31
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #include "sysdep.h"
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
33 #include "sysfile.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 #include "syssignal.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 #include "systime.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 /* Set to 1 when a quit-check signal (either a SIGIO interrupt or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 the asynch. timeout for poll-for-quit) occurs. The QUITP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 macro may look at this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 volatile int quit_check_signal_happened;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 /* Count of the number of times a quit-check signal has occurred.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 Some stuff in event-Xt.c looks at this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 volatile int quit_check_signal_tick_count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 /* Set to 1 when a SIGINT (or SIGQUIT) interrupt is processed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 maybe_read_quit_event() looks at this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 volatile int sigint_happened;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 /* Set to 1 when an asynch. timeout signal occurs. */
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
51 static volatile int async_timeout_happened;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
52
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
53 /* Set to 1 when a multiple of SLOWED_DOWN_INTERRUPTS_SECS elapses,
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
54 after slow_down_interrupts() is called. */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
55 static volatile int slowed_interrupt_timeout_happened;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 /* This is used to synchronize setting the waiting_for_user_input_p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 flag. */
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
59 static volatile int async_timeout_happened_while_emacs_was_blocking;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 /* See check_quit() for when this is set. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 int dont_check_for_quit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
64 static int poll_for_quit_id;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
65 static int poll_for_sigchld_id;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 /* This variable is used to communicate to a lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 process-filter/sentinel/asynchronous callback (via the function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 Fwaiting_for_user_input_p below) whether XEmacs was waiting for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 user-input when that process-filter was called. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 static int waiting_for_user_input_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 static int interrupts_slowed_down;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 #define SLOWED_DOWN_INTERRUPTS_SECS 15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 #define NORMAL_QUIT_CHECK_TIMEOUT_MSECS 250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 #define NORMAL_SIGCHLD_CHECK_TIMEOUT_MSECS 250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 /* Used so that signals can break out of system calls that aren't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 naturally interruptible. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 JMP_BUF break_system_call_jump;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 volatile int can_break_system_calls;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
85 static SIGTYPE alarm_signal (int signo);
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
86
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
87
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 /**********************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 /* Asynchronous timeout functions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 /**********************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
93 /* See the comment in event-stream.c, under major heading "Timeouts",
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
94 for the difference between low-level (one-shot) and high-level
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
95 (periodic/resignaling) timeouts. */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
96
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 /* The pending timers are stored in an ordered list, where the first timer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 on the list is the first one to fire. Times recorded here are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 absolute. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 static struct low_level_timeout *async_timer_queue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 /* Nonzero means async timers are temporarily suppressed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 static int async_timer_suppress_count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 set_one_shot_timer (EMACS_TIME interval)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 #ifdef HAVE_SETITIMER
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 struct itimerval it;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 it.it_value = interval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 EMACS_SET_SECS_USECS (it.it_interval, 0, 0);
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
112 qxe_setitimer (ITIMER_REAL, &it, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 int secs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 EMACS_TIME_TO_INT (interval, secs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 alarm (secs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 reset_interval_timer (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 EMACS_TIME interval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 /* Get the interval to set. If an interval is available,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 make sure it's not zero (this is a valid return, but it will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 cause the timer to get disabled, so convert it to a very short
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 time). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 if (get_low_level_timeout_interval (async_timer_queue, &interval))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 if (EMACS_SECS (interval) == 0 && EMACS_USECS (interval) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 EMACS_SET_USECS (interval, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 /* A time of 0 means "disable". */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 EMACS_SET_SECS_USECS (interval, 0, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 set_one_shot_timer (interval);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 init_async_timeouts (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 {
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
145 set_timeout_signal (SIGALRM, alarm_signal);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 async_timer_suppress_count = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 /* Turn off async timeouts. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 stop_async_timeouts (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 if (async_timer_suppress_count == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 /* If timer was on, turn it off. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 EMACS_TIME thyme;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 EMACS_SET_SECS_USECS (thyme, 0, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 set_one_shot_timer (thyme);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 async_timer_suppress_count++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 /* Turn on async timeouts again. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 start_async_timeouts (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 assert (async_timer_suppress_count > 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 async_timer_suppress_count--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 if (async_timer_suppress_count == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 /* Some callers turn off async timeouts and then use the alarm
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 for their own purposes; so reinitialize everything. */
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
175 set_timeout_signal (SIGALRM, alarm_signal);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 reset_interval_timer ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
180 static void
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
181 handle_async_timeout_signal (void)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 {
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
183 int interval_id;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
184 int wakeup_id;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
185 Lisp_Object fun, arg;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
186
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
187 /* No checks for Vinhibit_quit here or anywhere else in this file!!!
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
188 Otherwise critical quit will not work right.
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
189 The only check for Vinhibit_quit is in QUIT itself. */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
190 interval_id = pop_low_level_timeout (&async_timer_queue, 0);
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
191
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
192 reset_interval_timer ();
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
193 if (async_timeout_happened_while_emacs_was_blocking)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
194 {
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
195 async_timeout_happened_while_emacs_was_blocking = 0;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
196 waiting_for_user_input_p = 1;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
197 }
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
198
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
199 wakeup_id = event_stream_resignal_wakeup (interval_id, 1, &fun, &arg);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
201 if (wakeup_id == poll_for_quit_id)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
202 {
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
203 quit_check_signal_happened = 1;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
204 quit_check_signal_tick_count++;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
205 }
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
206 else if (wakeup_id == poll_for_sigchld_id)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 {
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
208 kick_status_notify ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 }
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
210 else
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
211 /* call1 GC-protects its arguments */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
212 call1_trapping_errors ("Error in asynchronous timeout callback",
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
213 fun, arg);
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
214
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
215 waiting_for_user_input_p = 0;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
216 }
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
217
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
218 /* The following two functions are the external interface onto
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
219 creating/deleting asynchronous interval timeouts, and are
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
220 called by event-stream.c. We call back to event-stream.c using
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
221 event_stream_resignal_wakeup(), when an interval goes off. */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
222
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
223 int
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
224 signal_add_async_interval_timeout (EMACS_TIME thyme)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
225 {
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
226 int id = add_low_level_timeout (&async_timer_queue, thyme);
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
227
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
228 /* If this timeout is at the head of the queue, then we need to
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
229 set the timer right now for this timeout. Otherwise, things
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
230 are fine as-is; after the timers ahead of us are signalled,
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
231 the timer will be set for us. */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
232
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
233 if (async_timer_queue->id == id)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
234 reset_interval_timer ();
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
235
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
236 return id;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 void
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
240 signal_remove_async_interval_timeout (int id)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 {
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
242 int first = (async_timer_queue && async_timer_queue->id == id);
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
243 remove_low_level_timeout (&async_timer_queue, id);
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
244
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
245 /* If we removed the timeout from the head of the queue, then
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
246 we need to reset the interval timer right now. */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
247 if (first)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
248 reset_interval_timer ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
251 /* If alarm() gets called when polling isn't disabled, it will mess up
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
252 the asynchronous timeouts, and then C-g checking won't work again.
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
253 Some libraries call alarm() directly, so we override the standard
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
254 library's alarm() and abort() if the caller of the library function
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
255 didn't wrap in stop_interrupts()/start_interrupts().
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
257 NOTE: We could potentially avoid the need to wrap by adding a
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
258 one-shot timeout to simulate the alarm(), smashing our signal
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
259 handler back into place, and calling the library function when the
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
260 alarm goes off. But do we want to? We're not going to gain the
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
261 ability to C-g out of library functions this way (unless we forcibly
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
262 longjmp() out of a signal handler, which is likely to lead to a
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
263 crash). --ben */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 #ifdef HAVE_SETITIMER
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
266
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 unsigned int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 alarm (unsigned int howlong)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 struct itimerval old_it, new_it;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 assert (async_timer_suppress_count > 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 new_it.it_value.tv_sec = howlong;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 new_it.it_value.tv_usec = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 new_it.it_interval.tv_sec = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 new_it.it_interval.tv_usec = 0;
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
278 qxe_setitimer (ITIMER_REAL, &new_it, &old_it);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 /* Never return zero if there was a timer outstanding. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 return old_it.it_value.tv_sec + (old_it.it_value.tv_usec > 0 ? 1 : 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 }
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
283
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
284 int
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
285 qxe_setitimer (int kind, const struct itimerval *itnew,
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
286 struct itimerval *itold)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
287 {
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
288 #if defined (WIN32_NATIVE) || defined (CYGWIN)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
289 /* setitimer() does not exist on native MS Windows, and appears broken
617
af57a77cbc92 [xemacs-hg @ 2001-06-18 07:09:50 by ben]
ben
parents: 613
diff changeset
290 on Cygwin. See win32.c.
af57a77cbc92 [xemacs-hg @ 2001-06-18 07:09:50 by ben]
ben
parents: 613
diff changeset
291
af57a77cbc92 [xemacs-hg @ 2001-06-18 07:09:50 by ben]
ben
parents: 613
diff changeset
292 We are emulating the Unix98 setitimer() function, as found in its
af57a77cbc92 [xemacs-hg @ 2001-06-18 07:09:50 by ben]
ben
parents: 613
diff changeset
293 incarnations on modern versions of Unix. Note however that in
af57a77cbc92 [xemacs-hg @ 2001-06-18 07:09:50 by ben]
ben
parents: 613
diff changeset
294 the win32.c version, ITNEW and ITOLD must be equal if both are
af57a77cbc92 [xemacs-hg @ 2001-06-18 07:09:50 by ben]
ben
parents: 613
diff changeset
295 non-zero, due to limitations in the underlying multimedia-timer
af57a77cbc92 [xemacs-hg @ 2001-06-18 07:09:50 by ben]
ben
parents: 613
diff changeset
296 API. */
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
297 return mswindows_setitimer (kind, itnew, itold);
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
298 #else
617
af57a77cbc92 [xemacs-hg @ 2001-06-18 07:09:50 by ben]
ben
parents: 613
diff changeset
299 /* YUCK! glibc defines setitimer's first argument as
af57a77cbc92 [xemacs-hg @ 2001-06-18 07:09:50 by ben]
ben
parents: 613
diff changeset
300 enum __itimer_which, not int, which causes compile errors if
af57a77cbc92 [xemacs-hg @ 2001-06-18 07:09:50 by ben]
ben
parents: 613
diff changeset
301 we call setitimer() in the obvious way. */
af57a77cbc92 [xemacs-hg @ 2001-06-18 07:09:50 by ben]
ben
parents: 613
diff changeset
302 switch (kind)
af57a77cbc92 [xemacs-hg @ 2001-06-18 07:09:50 by ben]
ben
parents: 613
diff changeset
303 {
af57a77cbc92 [xemacs-hg @ 2001-06-18 07:09:50 by ben]
ben
parents: 613
diff changeset
304 case ITIMER_REAL: return setitimer (ITIMER_REAL, itnew, itold);
af57a77cbc92 [xemacs-hg @ 2001-06-18 07:09:50 by ben]
ben
parents: 613
diff changeset
305 case ITIMER_VIRTUAL: return setitimer (ITIMER_VIRTUAL, itnew, itold);
af57a77cbc92 [xemacs-hg @ 2001-06-18 07:09:50 by ben]
ben
parents: 613
diff changeset
306 case ITIMER_PROF: return setitimer (ITIMER_PROF, itnew, itold);
af57a77cbc92 [xemacs-hg @ 2001-06-18 07:09:50 by ben]
ben
parents: 613
diff changeset
307 default: abort (); return 0;
af57a77cbc92 [xemacs-hg @ 2001-06-18 07:09:50 by ben]
ben
parents: 613
diff changeset
308 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 #endif
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
310 }
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
311
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
312 #endif /* HAVE_SETITIMER */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 593
diff changeset
313
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
314 signal_handler_t
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
315 set_timeout_signal (int signal_number, signal_handler_t action)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
316 {
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
317 #ifdef CYGWIN_BROKEN_SIGNALS
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
318 return mswindows_sigset (signal_number, action);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
319 #else
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
320 return EMACS_SIGNAL (signal_number, action);
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
321 #endif
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
322 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 DEFUN ("waiting-for-user-input-p", Fwaiting_for_user_input_p, 0, 0, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 Return non-nil if XEmacs is waiting for input from the user.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 This is intended for use by asynchronous timeout callbacks and by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 asynchronous process output filters and sentinels (not yet implemented
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 in XEmacs). It will always be nil if XEmacs is not inside of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 an asynchronous timeout or process callback.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 return waiting_for_user_input_p ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 /**********************************************************************/
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
338 /* Enabling/disabling signals */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
339 /**********************************************************************/
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
340
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
341 static int interrupts_initted;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
342
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
343 void
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
344 stop_interrupts (void)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
345 {
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
346 if (!interrupts_initted)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
347 return;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
348 #if defined(SIGIO) && !defined(BROKEN_SIGIO)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
349 unrequest_sigio ();
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
350 #endif
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
351 stop_async_timeouts ();
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
352 }
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
353
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
354 void
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
355 start_interrupts (void)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
356 {
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
357 if (!interrupts_initted)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
358 return;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
359 #if defined(SIGIO) && !defined(BROKEN_SIGIO)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
360 request_sigio ();
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
361 #endif
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
362 start_async_timeouts ();
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
363 }
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
364
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
365
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
366 static void
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
367 establish_slow_interrupt_timer (void)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
368 {
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
369 EMACS_TIME thyme;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
370
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
371 EMACS_SET_SECS_USECS (thyme, SLOWED_DOWN_INTERRUPTS_SECS, 0);
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
372 set_one_shot_timer (thyme);
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
373 }
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
374
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
375 /* Some functions don't like being interrupted with SIGALRM or SIGIO.
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
376 Previously we were calling stop_interrupts() / start_interrupts(),
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
377 but then if the program hangs in one of those functions, e.g.
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
378 waiting for a connect(), we're really screwed. So instead we
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
379 just "slow them down". We do this by disabling all interrupts
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
380 and then installing a timer of length fairly large, like 5 or
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
381 10 secs. That way, any "legitimate" connections (which should
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
382 take a fairly short amount of time) go through OK, but we can
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
383 interrupt bogus ones. */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
384
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
385 void
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
386 slow_down_interrupts (void)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
387 {
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
388 /* We have to set the flag *before* setting the slowed-down timer,
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
389 to avoid a race condition -- if the signal occurs between the
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
390 call to set_one_shot_timer() and the setting of this flag,
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
391 async_timeout_happened will get set, which will be a Bad Thing if
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
392 there were no timeouts on the queue. */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
393 interrupts_slowed_down++;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
394 if (interrupts_slowed_down == 1)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
395 {
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
396 stop_interrupts ();
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
397 establish_slow_interrupt_timer ();
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
398 }
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
399 }
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
400
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
401 void
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
402 speed_up_interrupts (void)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
403 {
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
404 if (interrupts_slowed_down > 0)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
405 {
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
406 start_interrupts ();
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
407 /* Change this flag AFTER fiddling with interrupts, for the same
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
408 race-condition reasons as above. */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
409 interrupts_slowed_down--;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
410 }
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
411 }
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
412
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
413 /* Cheesy but workable implementation of sleep() that doesn't
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
414 interfere with our periodic timers. */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
415
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
416 void
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
417 emacs_sleep (int secs)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
418 {
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
419 stop_interrupts ();
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
420 sleep (secs);
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
421 start_interrupts ();
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
422 }
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
423
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
424
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
425 /**********************************************************************/
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
426 /* The mechanism that drives it all */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 /**********************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
429 /* called from QUIT when something_happened gets set (as a result of
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
430 a signal) */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
431
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
432 int
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
433 check_what_happened (void)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
434 {
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
435 something_happened = 0;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
436 if (async_timeout_happened)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
437 {
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
438 async_timeout_happened = 0;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
439 handle_async_timeout_signal ();
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
440 }
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
441 if (slowed_interrupt_timeout_happened)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
442 {
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
443 slowed_interrupt_timeout_happened = 0;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
444 establish_slow_interrupt_timer ();
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
445 }
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
446
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
447 return check_quit ();
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
448 }
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
449
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
450 #ifdef SIGIO
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
451
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
452 /* Signal handler for SIGIO. */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
453
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
454 static void
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
455 input_available_signal (int signo)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
456 {
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
457 something_happened = 1; /* tell QUIT to wake up */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
458 quit_check_signal_happened = 1;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
459 quit_check_signal_tick_count++;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
460 EMACS_REESTABLISH_SIGNAL (signo, input_available_signal);
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
461 SIGRETURN;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
462 }
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
463
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
464 #endif /* SIGIO */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
465
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
466 /* Actual signal handler for SIGALRM. Called when:
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
467
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
468 -- asynchronous timeouts (added with `add-async-timeout') go off
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
469
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
470 -- when the poll-for-quit timer (used for C-g handling; more or
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
471 less when SIGIO is unavailable or BROKEN_SIGIO is defined) or
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
472 poll-for-sigchld timer (used when BROKEN_SIGCHLD is defined) go
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
473 off. The latter two timers, if set, normally go off every 1/4
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
474 of a second -- see NORMAL_QUIT_CHECK_TIMEOUT_MSECS and
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
475 NORMAL_SIGCHLD_CHECK_TIMEOUT_MSECS. (Both of these timers are
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
476 treated like other asynchronous timeouts, but special-cased
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
477 in handle_async_timeout_signal().)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
478
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
479 -- we called slow_down_interrupts() and SLOWED_DOWN_INTERRUPTS_SECS
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
480 (or a multiple of it) has elapsed.
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
481
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
482 Note that under Windows, we have no working setitimer(), so we
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
483 simulate it using the multimedia timeout functions,
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
484 e.g. timeSetEvent(). See setitimer() in nt.c.
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
485
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
486 Note also that we don't actually *do* anything here (except in the
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
487 case of can_break_system_calls). Instead, we just set various
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
488 flags; next time QUIT is called, the flags will cause
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
489 check_what_happened() to be called, at which point we do everything
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
490 indicated by the flags.
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
491 */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
492
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
493 static SIGTYPE
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
494 alarm_signal (int signo)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
495 {
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
496 something_happened = 1; /* tell QUIT to wake up and call
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
497 check_what_happened() */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
498
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
499 if (interrupts_slowed_down)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
500 {
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
501 /* we are in "slowed-down interrupts" mode; the only alarm
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
502 happening here is the slowed-down quit-check alarm, so
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
503 we set this flag.
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
504
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
505 Do NOT set async_timeout_happened, because we don't want
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
506 anyone looking at the timeout queue -- async timeouts
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
507 are disabled. */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
508 quit_check_signal_happened = 1;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
509 quit_check_signal_tick_count++;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
510 /* make sure we establish the slow timer again. */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
511 slowed_interrupt_timeout_happened = 1;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
512
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
513 /* can_break_system_calls is set when we want to break out of
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
514 non-interruptible system calls. */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
515 if (can_break_system_calls)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
516 {
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
517 /* reset the flag for safety and such. Do this *before*
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
518 unblocking or reestablishing the signal to avoid potential
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
519 race conditions. */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
520 can_break_system_calls = 0;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
521 #ifndef WIN32_NATIVE
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
522 /* #### I didn't add this WIN32_NATIVE check. I'm not sure
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
523 why it's here. But then again, someone needs to review
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
524 this can_break_system_calls stuff and see if it still
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
525 makes sense. --ben */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
526 EMACS_UNBLOCK_SIGNAL (signo);
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
527 EMACS_REESTABLISH_SIGNAL (signo, alarm_signal);
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
528 LONGJMP (break_system_call_jump, 0);
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
529 #endif
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
530 }
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
531 }
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
532 else
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
533 {
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
534 async_timeout_happened = 1;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
535 if (emacs_is_blocking)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
536 async_timeout_happened_while_emacs_was_blocking = 1;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
537 /* #### This is for QUITP. When it is run, it may not be the
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
538 place to do arbitrary stuff like run asynch. handlers, but
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
539 it needs to know whether the poll-for-quit asynch. timeout
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
540 went off. Rather than put the code in to compute this
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
541 specially, we just set this flag. Should fix this. */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
542 quit_check_signal_happened = 1;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
543
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
544 #ifdef HAVE_UNIXOID_EVENT_LOOP
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
545 signal_fake_event ();
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
546 #endif
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
547 }
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
548
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
549 EMACS_REESTABLISH_SIGNAL (signo, alarm_signal);
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
550 SIGRETURN;
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
551 }
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
552
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 /* Set this for debugging, to have a way to get out */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 int stop_character; /* #### not currently implemented */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
556 /* Signal handler for SIGINT and SIGQUIT. On TTY's, one of these two
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
557 signals will get generated in response to C-g. (When running under
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
558 X, C-g is handled using the SIGIO handler, which sets a flag
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
559 telling the QUIT macro to scan the unread events for a ^G.)
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
560 */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 static SIGTYPE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 interrupt_signal (int sig)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 /* This function can call lisp */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 /* #### we should NOT be calling lisp from a signal handler, boys
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 and girls */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 /* Must preserve main program's value of errno. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 int old_errno = errno;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 EMACS_REESTABLISH_SIGNAL (sig, interrupt_signal);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 if (sigint_happened && CONSOLEP (Vcontrolling_terminal) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 CONSOLE_LIVE_P (XCONSOLE (Vcontrolling_terminal)) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 !emacs_is_blocking)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 {
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
577 /* #### this is inherited from GNU Emacs. Do we really want this?
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
578 --ben */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 char c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 fflush (stdout);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 reset_initial_console ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 EMACS_UNBLOCK_SIGNAL (sig);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 #ifdef SIGTSTP /* Support possible in later USG versions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 * On systems which can suspend the current process and return to the original
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 * shell, this command causes the user to end up back at the shell.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 * The "Auto-save" and "Abort" questions are not asked until
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 * the user elects to return to emacs, at which point he can save the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 * job and either dump core or continue.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 sys_suspend ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 /* Perhaps should really fork an inferior shell?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 But that would not provide any way to get back
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 to the original shell, ever. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 stdout_out ("No support for stopping a process on this operating system;\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 stdout_out ("you can continue or abort.\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 #endif /* not SIGTSTP */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 stdout_out ("Auto-save? (y or n) ");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 if (((c = getc (stdin)) & ~040) == 'Y')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 Fdo_auto_save (Qnil, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 while (c != '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 c = getc (stdin);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 stdout_out ("Abort (and dump core)? (y or n) ");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 if (((c = getc (stdin)) & ~040) == 'Y')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 while (c != '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 c = getc (stdin);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 stdout_out ("Continuing...\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 reinit_initial_console ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 MARK_FRAME_CHANGED (XFRAME (DEVICE_SELECTED_FRAME
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 (XDEVICE (CONSOLE_SELECTED_DEVICE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 (XCONSOLE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 (Vcontrolling_terminal))))));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 /* Else request quit when it's safe */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 Vquit_flag = Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 sigint_happened = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 #ifdef HAVE_UNIXOID_EVENT_LOOP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 signal_fake_event ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 errno = old_errno;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 SIGRETURN;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
629
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
630 /**********************************************************************/
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
631 /* Control-G checking */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
632 /**********************************************************************/
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
633
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 restore_dont_check_for_quit (Lisp_Object val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 dont_check_for_quit = XINT (val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 begin_dont_check_for_quit (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 specbind (Qinhibit_quit, Qt);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 record_unwind_protect (restore_dont_check_for_quit,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 make_int (dont_check_for_quit));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 dont_check_for_quit = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 /* The effect of this function is to set Vquit_flag if the user pressed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 ^G and discard the ^G, so as to not notice the same ^G again. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 check_quit (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 /* dont_check_for_quit is set in two circumstances:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 (1) when we are in the process of changing the window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 configuration. The frame might be in an inconsistent state,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 which will cause assertion failures if we check for QUIT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 (2) when we are reading events, and want to read the C-g
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 as an event. The normal check for quit will discard the C-g,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 which would be bad.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 #### C-g is still often read as quit, e.g. if you type C-x C-g
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 (the C-g happens during the sit-for in maybe_echo_keys(); even
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 if we attempt to inhibit quit here, there is still a check
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 later on for QUIT. To fix this properly requires a fairly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 substantial overhaul of the quit-checking code, which is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 probably not worth it.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 We should *not* conditionalize on Vinhibit_quit, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 critical-quit (Control-Shift-G) won't work right. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 if (dont_check_for_quit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 if (quit_check_signal_happened)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 quit_check_signal_happened = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 event_stream_quit_p ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 init_poll_for_quit (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 #if !defined (SIGIO) && !defined (DONT_POLL_FOR_QUIT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 /* Check for C-g every 1/4 of a second.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 #### This is just a guess. Some investigation will have to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 done to see what the best value is. The best value is the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 smallest possible value that doesn't cause a significant amount
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 of running time to be spent in C-g checking. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 if (!poll_for_quit_id)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 poll_for_quit_id =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 event_stream_generate_wakeup (NORMAL_QUIT_CHECK_TIMEOUT_MSECS,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 NORMAL_QUIT_CHECK_TIMEOUT_MSECS,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 Qnil, Qnil, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 #endif /* not SIGIO and not DONT_POLL_FOR_QUIT */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
708 #if 0 /* not used anywhere */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
709
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 reset_poll_for_quit (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 #if !defined (SIGIO) && !defined (DONT_POLL_FOR_QUIT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 if (poll_for_quit_id)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 event_stream_disable_wakeup (poll_for_quit_id, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 poll_for_quit_id = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 #endif /* not SIGIO and not DONT_POLL_FOR_QUIT */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721
593
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
722 #endif /* 0 */
5fd7ba8b56e7 [xemacs-hg @ 2001-05-31 12:45:27 by ben]
ben
parents: 442
diff changeset
723
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 #if defined(HAVE_UNIX_PROCESSES) && !defined(SIGCHLD)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 init_poll_for_sigchld (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 /* Check for terminated processes every 1/4 of a second.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 #### This is just a guess. Some investigation will have to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 done to see what the best value is. The best value is the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 smallest possible value that doesn't cause a significant amount
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 of running time to be spent in process-termination checking.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 poll_for_sigchld_id =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 event_stream_generate_wakeup (NORMAL_SIGCHLD_CHECK_TIMEOUT_MSECS,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 NORMAL_SIGCHLD_CHECK_TIMEOUT_MSECS,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 Qnil, Qnil, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 #endif /* not SIGCHLD */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 /* initialization */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 /* If we've been nohup'ed, keep it that way.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 This allows `nohup xemacs &' to work.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 More generally, if a normally fatal signal has been redirected
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 to SIG_IGN by our invocation environment, trust the environment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 This keeps xemacs from being killed by a SIGQUIT intended for a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 different process after having been backgrounded under a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 non-job-control shell! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 handle_signal_if_fatal (int signo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 {
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
759 if (EMACS_SIGNAL (signo, fatal_error_signal) == SIG_IGN)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
760 EMACS_SIGNAL (signo, SIG_IGN);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 init_signals_very_early (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 /* Catch all signals that would kill us.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 Don't catch these signals in batch mode if not initialized.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 On some machines, this sets static data that would make
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 signal fail to work right when the dumped Emacs is run. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 if (noninteractive && !initialized)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 handle_signal_if_fatal (SIGILL); /* ANSI */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 handle_signal_if_fatal (SIGABRT); /* ANSI */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 handle_signal_if_fatal (SIGFPE); /* ANSI */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 handle_signal_if_fatal (SIGSEGV); /* ANSI */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 handle_signal_if_fatal (SIGTERM); /* ANSI */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 #ifdef SIGHUP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 handle_signal_if_fatal (SIGHUP); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 #ifdef SIGQUIT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 handle_signal_if_fatal (SIGQUIT); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 #ifdef SIGTRAP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 handle_signal_if_fatal (SIGTRAP); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 #ifdef SIGUSR1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 handle_signal_if_fatal (SIGUSR1); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 #ifdef SIGUSR2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 handle_signal_if_fatal (SIGUSR2); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 #ifdef SIGPIPE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 handle_signal_if_fatal (SIGPIPE); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 #ifdef SIGALRM
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 /* This will get reset later, once we're
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 capable of handling it properly. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 handle_signal_if_fatal (SIGALRM); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 #ifdef SIGBUS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 handle_signal_if_fatal (SIGBUS); /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 #ifdef SIGSYS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 handle_signal_if_fatal (SIGSYS); /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 #ifdef SIGXCPU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 handle_signal_if_fatal (SIGXCPU); /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 #ifdef SIGXFSZ
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 handle_signal_if_fatal (SIGXFSZ); /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 #ifdef SIGVTALRM
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 handle_signal_if_fatal (SIGVTALRM); /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 #ifdef SIGPROF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 /* Messes up the REAL profiler */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 /* handle_signal_if_fatal (SIGPROF); */ /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 #ifdef SIGHWE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 handle_signal_if_fatal (SIGHWE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 #ifdef SIGPRE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 handle_signal_if_fatal (SIGPRE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 #ifdef SIGORE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 handle_signal_if_fatal (SIGORE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 #ifdef SIGUME
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 handle_signal_if_fatal (SIGUME);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 #ifdef SIGDLK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 handle_signal_if_fatal (SIGDLK);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 #ifdef SIGCPULIM
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 handle_signal_if_fatal (SIGCPULIM);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 #ifdef SIGIOT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 handle_signal_if_fatal (SIGIOT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 #ifdef SIGEMT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 handle_signal_if_fatal (SIGEMT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 #ifdef SIGLOST
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 handle_signal_if_fatal (SIGLOST);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 #ifdef SIGSTKFLT /* coprocessor stack fault under Linux */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 handle_signal_if_fatal (SIGSTKFLT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 #ifdef SIGUNUSED /* exists under Linux, and will kill process! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 handle_signal_if_fatal (SIGUNUSED);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 #ifdef AIX
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 /* 20 is SIGCHLD, 21 is SIGTTIN, 22 is SIGTTOU. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 #ifndef _I386
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 handle_signal_if_fatal (SIGIOINT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 handle_signal_if_fatal (SIGGRANT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 handle_signal_if_fatal (SIGRETRACT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 handle_signal_if_fatal (SIGSOUND);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 handle_signal_if_fatal (SIGMSG);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 #endif /* AIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 #ifdef SIGDANGER
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 /* This just means available memory is getting low. */
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
873 EMACS_SIGNAL (SIGDANGER, memory_warning_signal);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 syms_of_signal (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 DEFSUBR (Fwaiting_for_user_input_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 init_interrupts_late (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 if (!noninteractive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 {
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
888 EMACS_SIGNAL (SIGINT, interrupt_signal);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 #ifdef HAVE_TERMIO
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 /* On systems with TERMIO, C-g is set up for both SIGINT and SIGQUIT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 and we can't tell which one it will give us. */
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
892 EMACS_SIGNAL (SIGQUIT, interrupt_signal);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 #endif /* HAVE_TERMIO */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 init_async_timeouts ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 #ifdef SIGIO
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
896 EMACS_SIGNAL (SIGIO, input_available_signal);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 # ifdef SIGPOLL /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 /* Some systems (e.g. Motorola SVR4) losingly have different
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 values for SIGIO and SIGPOLL, and send SIGPOLL instead of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 SIGIO. On those same systems, an uncaught SIGPOLL kills the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 process. */
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 611
diff changeset
902 EMACS_SIGNAL (SIGPOLL, input_available_signal);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 # endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 #elif !defined (DONT_POLL_FOR_QUIT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 init_poll_for_quit ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 #if defined(HAVE_UNIX_PROCESSES) && !defined(SIGCHLD)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 init_poll_for_sigchld ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 EMACS_UNBLOCK_ALL_SIGNALS ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 interrupts_initted = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917