summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/abort.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/stdlib/abort.c')
-rw-r--r--src/lib/libc/stdlib/abort.c47
1 files changed, 31 insertions, 16 deletions
diff --git a/src/lib/libc/stdlib/abort.c b/src/lib/libc/stdlib/abort.c
index c298e016b4..4c8dc70a1d 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.16 2012/11/10 03:46:11 guenther 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,35 +28,53 @@
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";*/
36static 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"
36
37int _thread_sys_sigprocmask(int, const sigset_t *, sigset_t *);
42 38
43void 39void
44abort() 40abort(void)
45{ 41{
42 struct atexit *p = __atexit;
43 static int cleanup_called = 0;
46 sigset_t mask; 44 sigset_t mask;
47 45
46
48 sigfillset(&mask); 47 sigfillset(&mask);
49 /* 48 /*
50 * don't block SIGABRT to give any handler a chance; we ignore 49 * don't block SIGABRT to give any handler a chance; we ignore
51 * any errors -- X311J doesn't allow abort to return anyway. 50 * any errors -- X311J doesn't allow abort to return anyway.
52 */ 51 */
53 sigdelset(&mask, SIGABRT); 52 sigdelset(&mask, SIGABRT);
54 (void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); 53 (void)_thread_sys_sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL);
55 (void)kill(getpid(), SIGABRT); 54
55 /*
56 * POSIX requires we flush stdio buffers on abort
57 */
58 if (cleanup_called == 0) {
59 /* the cleanup routine lives in fns[0] on the last page */
60 while (p != NULL && p->next != NULL)
61 p = p->next;
62 /* the check for fn_dso == NULL is mostly paranoia */
63 if (p != NULL && p->fns[0].fn_dso == NULL &&
64 p->fns[0].fn_ptr.std_func != NULL) {
65 cleanup_called = 1;
66 (*p->fns[0].fn_ptr.std_func)();
67 }
68 }
69
70 (void)raise(SIGABRT);
56 71
57 /* 72 /*
58 * if SIGABRT ignored, or caught and the handler returns, do 73 * if SIGABRT ignored, or caught and the handler returns, do
59 * it again, only harder. 74 * it again, only harder.
60 */ 75 */
61 (void)signal(SIGABRT, SIG_DFL); 76 (void)signal(SIGABRT, SIG_DFL);
62 (void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); 77 (void)_thread_sys_sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL);
63 (void)kill(getpid(), SIGABRT); 78 (void)raise(SIGABRT);
64 exit(1); 79 _exit(1);
65} 80}