Browse Source

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@
OPENBSD_5_8
guenther 9 years ago
parent
commit
04a5d5b45d
1 changed files with 19 additions and 1 deletions
  1. +19
    -1
      src/lib/libc/stdlib/atexit.c

+ 19
- 1
src/lib/libc/stdlib/atexit.c View File

@ -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 * Copyright (c) 2002 Daniel Hartmeier
* All rights reserved. * All rights reserved.
@ -35,6 +35,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "atexit.h" #include "atexit.h"
#include "atfork.h"
#include "thread_private.h" #include "thread_private.h"
struct atexit *__atexit; struct atexit *__atexit;
@ -161,6 +162,23 @@ restart:
__atexit = NULL; __atexit = NULL;
} }
_ATEXIT_UNLOCK(); _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();
}
} }
/* /*


Loading…
Cancel
Save