update from main archive 961217
[glibc.git] / sysdeps / generic / abort.c
blob61b99377b92ec2ab42158c95b2867381de941f82
1 /* Copyright (C) 1991, 1993, 1995, 1996 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
19 #include <signal.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <signal.h>
26 /* Function to close all streams and also make sure we don't loop by
27 calling abort while closing the streams. */
28 extern void __close_all_streams (void);
31 /* Cause an abnormal program termination with core-dump. */
32 void
33 abort (void)
35 struct sigaction act;
36 sigset_t sigs;
38 if (__sigemptyset (&sigs) == 0 &&
39 __sigaddset (&sigs, SIGABRT) == 0)
40 __sigprocmask (SIG_UNBLOCK, &sigs, (sigset_t *) NULL);
42 /* If there is a user handler installed use it. We don't close or
43 flush streams. */
44 if (__sigaction (SIGABRT, NULL, &act) >= 0
45 && act.sa_handler != SIG_DFL)
47 /* Send signal to call user handler. */
48 raise (SIGABRT);
50 /* It returns, so we are responsible for closing the streams. */
51 __close_all_streams ();
53 /* There was a handler installed. Now remove it. */
54 memset (&act, '\0', sizeof (struct sigaction));
55 act.sa_handler = SIG_DFL;
56 __sigfillset (&act.sa_mask);
57 act.sa_flags = 0;
58 __sigaction (SIGABRT, &act, NULL);
60 else
61 /* No handler installed so the next `raise' will hopefully
62 terminate the process. Therefore we must close the streams. */
63 __close_all_streams ();
65 /* Try again. */
66 raise (SIGABRT);
68 /* If we can't signal ourselves, exit. */
69 _exit (127);
71 /* If even this fails make sure we never return. */
72 while (1)
73 /* For ever and ever. */