summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/exit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/stdlib/exit.c')
-rw-r--r--src/lib/libc/stdlib/exit.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/lib/libc/stdlib/exit.c b/src/lib/libc/stdlib/exit.c
index b1412f42bb..c69639125e 100644
--- a/src/lib/libc/stdlib/exit.c
+++ b/src/lib/libc/stdlib/exit.c
@@ -32,29 +32,47 @@
32 */ 32 */
33 33
34#if defined(LIBC_SCCS) && !defined(lint) 34#if defined(LIBC_SCCS) && !defined(lint)
35/*static char *sccsid = "from: @(#)exit.c 5.4 (Berkeley) 2/23/91";*/ 35static char *rcsid = "$OpenBSD: exit.c,v 1.7 2002/08/30 07:58:07 dhartmei Exp $";
36static char *rcsid = "$Id: exit.c,v 1.1.1.1 1995/10/18 08:42:17 deraadt Exp $";
37#endif /* LIBC_SCCS and not lint */ 36#endif /* LIBC_SCCS and not lint */
38 37
38#include <sys/types.h>
39#include <sys/mman.h>
39#include <stdlib.h> 40#include <stdlib.h>
40#include <unistd.h> 41#include <unistd.h>
41#include "atexit.h" 42#include "atexit.h"
43#include "thread_private.h"
42 44
43void (*__cleanup)(); 45void (*__cleanup)();
44 46
45/* 47/*
48 * This variable is zero until a process has created a thread.
49 * It is used to avoid calling locking functions in libc when they
50 * are not required. By default, libc is intended to be(come)
51 * thread-safe, but without a (significant) penalty to non-threaded
52 * processes.
53 */
54int __isthreaded = 0;
55
56/*
46 * Exit, flushing stdio buffers if necessary. 57 * Exit, flushing stdio buffers if necessary.
47 */ 58 */
48void 59void
49exit(status) 60exit(status)
50 int status; 61 int status;
51{ 62{
52 register struct atexit *p; 63 register struct atexit *p, *q;
53 register int n; 64 register int n, pgsize = getpagesize();
54 65
55 for (p = __atexit; p; p = p->next) 66 if (!__atexit_invalid) {
56 for (n = p->ind; --n >= 0;) 67 p = __atexit;
57 (*p->fns[n])(); 68 while (p != NULL) {
69 for (n = p->ind; --n >= 0;)
70 (*p->fns[n])();
71 q = p;
72 p = p->next;
73 munmap(q, pgsize);
74 }
75 }
58 if (__cleanup) 76 if (__cleanup)
59 (*__cleanup)(); 77 (*__cleanup)();
60 _exit(status); 78 _exit(status);