diff options
Diffstat (limited to 'src/lib/libc/stdlib/abort.c')
-rw-r--r-- | src/lib/libc/stdlib/abort.c | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/src/lib/libc/stdlib/abort.c b/src/lib/libc/stdlib/abort.c index c298e016b4..244e3b28aa 100644 --- a/src/lib/libc/stdlib/abort.c +++ b/src/lib/libc/stdlib/abort.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: abort.c,v 1.15 2007/09/03 14:40:16 millert Exp $ */ | ||
1 | /* | 2 | /* |
2 | * Copyright (c) 1985 Regents of the University of California. | 3 | * Copyright (c) 1985 Regents of the University of California. |
3 | * All rights reserved. | 4 | * All rights reserved. |
@@ -10,11 +11,7 @@ | |||
10 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
11 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the |
12 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. |
13 | * 3. All advertising materials mentioning features or use of this software | 14 | * 3. Neither the name of the University nor the names of its contributors |
14 | * must display the following acknowledgement: | ||
15 | * This product includes software developed by the University of | ||
16 | * California, Berkeley and its contributors. | ||
17 | * 4. Neither the name of the University nor the names of its contributors | ||
18 | * may be used to endorse or promote products derived from this software | 15 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | 16 | * without specific prior written permission. |
20 | * | 17 | * |
@@ -31,27 +28,43 @@ | |||
31 | * SUCH DAMAGE. | 28 | * SUCH DAMAGE. |
32 | */ | 29 | */ |
33 | 30 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | ||
35 | /*static char *sccsid = "from: @(#)abort.c 5.11 (Berkeley) 2/23/91";*/ | ||
36 | static char *rcsid = "$Id: abort.c,v 1.1.1.1 1995/10/18 08:42:16 deraadt Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <signal.h> | 31 | #include <signal.h> |
40 | #include <stdlib.h> | 32 | #include <stdlib.h> |
41 | #include <unistd.h> | 33 | #include <unistd.h> |
34 | #include "thread_private.h" | ||
35 | #include "atexit.h" | ||
42 | 36 | ||
43 | void | 37 | void |
44 | abort() | 38 | abort(void) |
45 | { | 39 | { |
40 | struct atexit *p = __atexit; | ||
41 | static int cleanup_called = 0; | ||
46 | sigset_t mask; | 42 | sigset_t mask; |
47 | 43 | ||
44 | |||
48 | sigfillset(&mask); | 45 | sigfillset(&mask); |
49 | /* | 46 | /* |
50 | * don't block SIGABRT to give any handler a chance; we ignore | 47 | * don't block SIGABRT to give any handler a chance; we ignore |
51 | * any errors -- X311J doesn't allow abort to return anyway. | 48 | * any errors -- X311J doesn't allow abort to return anyway. |
52 | */ | 49 | */ |
53 | sigdelset(&mask, SIGABRT); | 50 | sigdelset(&mask, SIGABRT); |
54 | (void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); | 51 | (void)_thread_sys_sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); |
52 | |||
53 | /* | ||
54 | * POSIX requires we flush stdio buffers on abort | ||
55 | */ | ||
56 | if (cleanup_called == 0) { | ||
57 | /* the cleanup routine lives in fns[0] on the last page */ | ||
58 | while (p != NULL && p->next != NULL) | ||
59 | p = p->next; | ||
60 | /* the check for fn_dso == NULL is mostly paranoia */ | ||
61 | if (p != NULL && p->fns[0].fn_dso == NULL && | ||
62 | p->fns[0].fn_ptr.std_func != NULL) { | ||
63 | cleanup_called = 1; | ||
64 | (*p->fns[0].fn_ptr.std_func)(); | ||
65 | } | ||
66 | } | ||
67 | |||
55 | (void)kill(getpid(), SIGABRT); | 68 | (void)kill(getpid(), SIGABRT); |
56 | 69 | ||
57 | /* | 70 | /* |
@@ -59,7 +72,7 @@ abort() | |||
59 | * it again, only harder. | 72 | * it again, only harder. |
60 | */ | 73 | */ |
61 | (void)signal(SIGABRT, SIG_DFL); | 74 | (void)signal(SIGABRT, SIG_DFL); |
62 | (void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); | 75 | (void)_thread_sys_sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); |
63 | (void)kill(getpid(), SIGABRT); | 76 | (void)kill(getpid(), SIGABRT); |
64 | exit(1); | 77 | _exit(1); |
65 | } | 78 | } |