]> granicus.if.org Git - p11-kit/commitdiff
common: Prefer __register_atfork() to pthread_atfork() if possible
authorDaiki Ueno <dueno@redhat.com>
Thu, 9 Aug 2018 15:45:37 +0000 (17:45 +0200)
committerDaiki Ueno <ueno@gnu.org>
Fri, 10 Aug 2018 08:11:24 +0000 (10:11 +0200)
common/library.c
configure.ac

index c1275f3229b9d0b261d12e148ce7cdf6a8458d92..b72465ba587a10c7969fc702d66f803df9d44610 100644 (file)
@@ -138,6 +138,23 @@ _p11_library_get_thread_local (void)
 }
 #endif
 
+#if defined(HAVE_DECL___REGISTER_ATFORK) && !HAVE_DECL___REGISTER_ATFORK
+extern int __register_atfork (void (*prepare) (void), void (*parent) (void),
+                             void (*child) (void), void *dso_handle);
+#endif /* HAVE_DECL___REGISTER_ATFORK */
+
+#ifdef HAVE___REGISTER_ATFORK
+
+#define p11_register_atfork(a,b,c,d) \
+       (__register_atfork((a),(b),(c),(d)))
+
+#else
+
+#define p11_register_atfork(a,b,c,d) \
+       (pthread_atfork((a),(b),(c)))
+
+#endif /* HAVE___REGISTER_ATFORK */
+
 static void
 count_forks (void)
 {
@@ -160,7 +177,7 @@ p11_library_init_impl (void)
        p11_message_locale = newlocale (LC_ALL_MASK, "POSIX", (locale_t) 0);
 #endif
 
-       pthread_atfork (NULL, NULL, count_forks);
+       p11_register_atfork (NULL, NULL, count_forks, NULL);
 }
 
 void
index d4ff1ad3ef096ac0fe0cb1674c66f5c18ff43c15..24e9519ce6f36ca31727e6e239b0174c84c8902a 100644 (file)
@@ -123,6 +123,8 @@ if test "$os_unix" = "yes"; then
        AC_CHECK_FUNCS([setenv])
        AC_CHECK_FUNCS([getpeereid])
        AC_CHECK_FUNCS([getpeerucred])
+       AC_CHECK_FUNCS([__register_atfork])
+       AC_CHECK_DECLS([__register_atfork])
 
        # Check if issetugid() is available and has compatible behavior with OpenBSD
        AC_CHECK_FUNCS([issetugid], [