Mercurial > emacs
comparison src/emacs.c @ 1774:04cd18603ec5
* emacs.c (shut_down_emacs): New function.
(fatal_error_signal, Fkill_emacs): Call it, instead of writing it out.
* xterm.c (x_connection_closed): Call shut_down_emacs instead of
Fkill_emacs; the latter will try to perform operations on the X
server and die a horrible death.
* lisp.h (shut_down_emacs): Add extern declaration for it.
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Thu, 14 Jan 1993 15:07:32 +0000 |
parents | 59b6f3d6aa26 |
children | 04fb1d3d6992 |
comparison
equal
deleted
inserted
replaced
1773:f18ae1a08d85 | 1774:04cd18603ec5 |
---|---|
1 /* Fully extensible Emacs, running on Unix, intended for GNU. | 1 /* Fully extensible Emacs, running on Unix, intended for GNU. |
2 Copyright (C) 1985, 1986, 1987, 1992 Free Software Foundation, Inc. | 2 Copyright (C) 1985, 1986, 1987, 1992, 1993 Free Software Foundation, Inc. |
3 | 3 |
4 This file is part of GNU Emacs. | 4 This file is part of GNU Emacs. |
5 | 5 |
6 GNU Emacs is free software; you can redistribute it and/or modify | 6 GNU Emacs is free software; you can redistribute it and/or modify |
7 it under the terms of the GNU General Public License as published by | 7 it under the terms of the GNU General Public License as published by |
8 the Free Software Foundation; either version 1, or (at your option) | 8 the Free Software Foundation; either version 2, or (at your option) |
9 any later version. | 9 any later version. |
10 | 10 |
11 GNU Emacs is distributed in the hope that it will be useful, | 11 GNU Emacs is distributed in the hope that it will be useful, |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
128 if (fatal_error_in_progress) | 128 if (fatal_error_in_progress) |
129 kill (getpid (), fatal_error_code); | 129 kill (getpid (), fatal_error_code); |
130 | 130 |
131 fatal_error_in_progress = 1; | 131 fatal_error_in_progress = 1; |
132 | 132 |
133 /* If we are controlling the terminal, reset terminal modes */ | 133 shut_down_emacs (sig); |
134 #ifdef EMACS_HAVE_TTY_PGRP | 134 |
135 { | 135 #ifdef VMS |
136 int tpgrp; | |
137 if (EMACS_GET_TTY_PGRP (0, &tpgrp) != -1 | |
138 && tpgrp == getpgrp (0)) | |
139 { | |
140 reset_sys_modes (); | |
141 if (sig != SIGTERM) | |
142 fprintf (stderr, "Fatal error (%d).", sig); | |
143 } | |
144 } | |
145 #endif /* uses pgrp */ | |
146 | |
147 /* Clean up */ | |
148 kill_buffer_processes (Qnil); | |
149 Fdo_auto_save (Qt, Qnil); | |
150 | |
151 #ifdef CLASH_DETECTION | |
152 unlock_all_files (); | |
153 #endif /* CLASH_DETECTION */ | |
154 | |
155 #ifdef VMS | |
156 kill_vms_processes (); | |
157 LIB$STOP (SS$_ABORT); | 136 LIB$STOP (SS$_ABORT); |
158 #else | 137 #else |
159 /* Signal the same code; this time it will really be fatal. */ | 138 /* Signal the same code; this time it will really be fatal. */ |
160 kill (getpid (), fatal_error_code); | 139 kill (getpid (), fatal_error_code); |
161 #endif /* not VMS */ | 140 #endif /* not VMS */ |
616 arg = Qt; | 595 arg = Qt; |
617 | 596 |
618 if (!NILP (Vrun_hooks) && !noninteractive) | 597 if (!NILP (Vrun_hooks) && !noninteractive) |
619 call1 (Vrun_hooks, intern ("kill-emacs-hook")); | 598 call1 (Vrun_hooks, intern ("kill-emacs-hook")); |
620 | 599 |
621 kill_buffer_processes (Qnil); | |
622 | |
623 #ifdef VMS | |
624 kill_vms_processes (); | |
625 #endif /* VMS */ | |
626 | |
627 Fdo_auto_save (Qt, Qnil); | |
628 | |
629 #ifdef CLASH_DETECTION | |
630 unlock_all_files (); | |
631 #endif /* CLASH_DETECTION */ | |
632 | |
633 fflush (stdout); | |
634 reset_sys_modes (); | |
635 | |
636 #ifdef HAVE_X_WINDOWS | 600 #ifdef HAVE_X_WINDOWS |
637 if (!noninteractive && EQ (Vwindow_system, intern ("x"))) | 601 if (!noninteractive && EQ (Vwindow_system, intern ("x"))) |
638 Fx_close_current_connection (); | 602 Fx_close_current_connection (); |
639 #endif /* HAVE_X_WINDOWS */ | 603 #endif /* HAVE_X_WINDOWS */ |
640 | 604 |
644 when we are going to exit anyway? */ | 608 when we are going to exit anyway? */ |
645 /* #ifdef VMS | 609 /* #ifdef VMS |
646 stop_vms_input (); | 610 stop_vms_input (); |
647 #endif */ | 611 #endif */ |
648 stuff_buffered_input (arg); | 612 stuff_buffered_input (arg); |
613 | |
614 shut_down_emacs (0); | |
615 | |
616 exit ((XTYPE (arg) == Lisp_Int) ? XINT (arg) | |
617 #ifdef VMS | |
618 : 1 | |
619 #else | |
620 : 0 | |
621 #endif | |
622 ); | |
623 /* NOTREACHED */ | |
624 } | |
625 | |
626 | |
627 /* Perform an orderly shutdown of Emacs. Autosave any modified | |
628 buffers, kill any child processes, clean up the terminal modes (if | |
629 we're in the foreground), and other stuff like that. Don't perform | |
630 any redisplay; this may be called when Emacs is shutting down in | |
631 the background, or after its X connection has died. | |
632 | |
633 If SIG is a signal number, print a message for it. | |
634 | |
635 This is called by fatal signal handlers, X protocol error handlers, | |
636 and Fkill_emacs. */ | |
637 void | |
638 shut_down_emacs (sig) | |
639 int sig; | |
640 { | |
641 /* If we are controlling the terminal, reset terminal modes */ | |
642 #ifdef EMACS_HAVE_TTY_PGRP | |
643 { | |
644 int tpgrp; | |
645 if (EMACS_GET_TTY_PGRP (0, &tpgrp) != -1 | |
646 && tpgrp == getpgrp (0)) | |
647 { | |
648 fflush (stdout); | |
649 reset_sys_modes (); | |
650 if (sig && sig != SIGTERM) | |
651 fprintf (stderr, "Fatal error (%d).", sig); | |
652 } | |
653 } | |
654 #else | |
655 fflush (stdout); | |
656 reset_sys_modes (); | |
657 #endif | |
658 | |
659 kill_buffer_processes (Qnil); | |
660 Fdo_auto_save (Qt, Qnil); | |
661 | |
662 #ifdef CLASH_DETECTION | |
663 unlock_all_files (); | |
664 #endif | |
665 | |
666 #ifdef VMS | |
667 kill_vms_processes (); | |
668 #endif | |
669 | |
649 #ifdef SIGIO | 670 #ifdef SIGIO |
650 /* There is a tendency for a SIGIO signal to arrive within exit, | 671 /* There is a tendency for a SIGIO signal to arrive within exit, |
651 and cause a SIGHUP because the input descriptor is already closed. */ | 672 and cause a SIGHUP because the input descriptor is already closed. */ |
652 unrequest_sigio (); | 673 unrequest_sigio (); |
653 signal (SIGIO, SIG_IGN); | 674 signal (SIGIO, SIG_IGN); |
654 #endif | 675 #endif |
655 exit ((XTYPE (arg) == Lisp_Int) ? XINT (arg) | |
656 #ifdef VMS | |
657 : 1 | |
658 #else | |
659 : 0 | |
660 #endif | |
661 ); | |
662 /* NOTREACHED */ | |
663 } | 676 } |
677 | |
678 | |
664 | 679 |
665 #ifndef CANNOT_DUMP | 680 #ifndef CANNOT_DUMP |
666 /* Nothing like this can be implemented on an Apollo. | 681 /* Nothing like this can be implemented on an Apollo. |
667 What a loss! */ | 682 What a loss! */ |
668 | 683 |