summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/atexit.c
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2015-04-07 01:27:06 +0000
committerguenther <guenther@openbsd.org>2015-04-07 01:27:06 +0000
commit514a545f8a3983d53b7de4e8dfcefe16c9496776 (patch)
treee17cf0966466dfd49a1decf34dd536d3fdbe4765 /lib/libc/stdlib/atexit.c
parentDo not mistreat empty arguments to font alternating macros (diff)
downloadwireguard-openbsd-514a545f8a3983d53b7de4e8dfcefe16c9496776.tar.xz
wireguard-openbsd-514a545f8a3983d53b7de4e8dfcefe16c9496776.zip
Make pthread_atfork() track the DSO that called it like atexit() does,
unregistering callbacks if the DSO is unloaded. Move the callback handling from libpthread to libc, though libpthread still overrides the inner call to handle locking and thread-library reinitialization. Major version bump for both libc and libpthread. verification that this fixes various ports ajacoutot@ asm assistance miod@; ok millert@ deraadt@
Diffstat (limited to 'lib/libc/stdlib/atexit.c')
-rw-r--r--lib/libc/stdlib/atexit.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/libc/stdlib/atexit.c b/lib/libc/stdlib/atexit.c
index 6532b382eab..a33080571fe 100644
--- a/lib/libc/stdlib/atexit.c
+++ b/lib/libc/stdlib/atexit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: atexit.c,v 1.20 2014/07/11 09:51:37 kettenis Exp $ */
+/* $OpenBSD: atexit.c,v 1.21 2015/04/07 01:27:07 guenther Exp $ */
/*
* Copyright (c) 2002 Daniel Hartmeier
* All rights reserved.
@@ -35,6 +35,7 @@
#include <string.h>
#include <unistd.h>
#include "atexit.h"
+#include "atfork.h"
#include "thread_private.h"
struct atexit *__atexit;
@@ -161,6 +162,23 @@ restart:
__atexit = NULL;
}
_ATEXIT_UNLOCK();
+
+ /*
+ * If unloading a DSO, unregister any atfork handlers registered
+ * by it. Skip the locking if the list is currently empty.
+ */
+ if (dso != NULL && TAILQ_FIRST(&_atfork_list) != NULL) {
+ struct atfork_fn *af, *afnext;
+
+ _ATFORK_LOCK();
+ TAILQ_FOREACH_SAFE(af, &_atfork_list, fn_next, afnext)
+ if (af->fn_dso == dso) {
+ TAILQ_REMOVE(&_atfork_list, af, fn_next);
+ free(af);
+ }
+ _ATFORK_UNLOCK();
+
+ }
}
/*