]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
build: Use __register_atfork() only if really available
authorGuillem Jover <guillem@hadrons.org>
Tue, 6 Aug 2019 21:16:42 +0000 (23:16 +0200)
committerGuillem Jover <guillem@hadrons.org>
Thu, 8 Aug 2019 01:21:49 +0000 (03:21 +0200)
This is a glibc-specific symbol that has no public declaration. But is
being used by the OpenBSD and this implementation as a hack to avoid
having to link against the pthread library. This interface is at least
included in LSB 5.0 [L], and using pthread_atfork() is otherwise
problematic anyway [P].

 [L] <https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/baselib---register-atfork.html>
 [P] <http://austingroupbugs.net/view.php?id=851>

One problem is that we were using it whenever __GLIBC__ is defined,
which is supposed to be defined only on an actual glibc, but uClibc
defines that macro, but it does not provide the symbol on its noMMU
variant.

We add a new configure check that will try to link a program that uses
that symbol to make sure it is present.

Closes: !2
Reported-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
configure.ac
src/Makefile.am
src/arc4random_linux.h
src/arc4random_unix.h

index 1654072c2a6cd38f9a6573a4136a9a2ee99a1849..3beb08e7aea556c27957386bb95b0b863d6a5216 100644 (file)
@@ -145,6 +145,23 @@ AC_LINK_IFELSE(
         AC_MSG_RESULT([yes])],
        [AC_MSG_RESULT([no])])
 
+AC_MSG_CHECKING([for __register_atfork])
+AC_LINK_IFELSE(
+       [AC_LANG_PROGRAM([[
+               #include <stddef.h>
+               extern void *__dso_handle;
+               extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
+       ]], [[
+               __register_atfork(NULL, NULL, NULL, __dso_handle);
+       ]])],
+       [AC_DEFINE([HAVE___REGISTER_ATFORK], [1],
+                  [Define to 1 if you have __register_atfork])
+        AC_MSG_RESULT([yes])],
+       [ARC4RANDOM_ATFORK_LIBS="-pthread"
+        AC_SUBST([ARC4RANDOM_ATFORK_LIBS])
+        AC_MSG_RESULT([no])
+       ])
+
 AC_CHECK_FUNCS([clearenv dirfd fopencookie __fpurge \
                 getauxval getentropy getexecname getline \
                 pstat_getproc sysconf])
index f3cc0fa1b9d7e14d4fb96f0e01f8a7e14461771f..76222a3c1653f68c872c4223b7a8106db08579eb 100644 (file)
@@ -54,7 +54,9 @@ libbsd_la_DEPENDENCIES = \
        $(libbsd_la_included_sources) \
        libbsd.map
 libbsd_la_LIBADD = \
-       $(CLOCK_GETTIME_LIBS)
+       $(CLOCK_GETTIME_LIBS) \
+       $(ARC4RANDOM_ATFORK_LIBS) \
+       $(nil)
 libbsd_la_LDFLAGS = \
        -Wl,--version-script=$(srcdir)/libbsd.map \
        -version-number $(LIBBSD_ABI)
index 7a2ca1e7619ac5093ee80e0205dbb5fbb33f1a0d..bc57cd17ae9b0742f3661fedbca0481c16ae4e99 100644 (file)
@@ -32,7 +32,7 @@ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
 #define _ARC4_LOCK()   pthread_mutex_lock(&arc4random_mtx)
 #define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)
 
-#ifdef __GLIBC__
+#ifdef HAVE___REGISTER_ATFORK
 extern void *__dso_handle;
 extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
 #define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle)
index 0e3768315b612723b9ff545d23c102e4303f79f0..2e6c6ea56e84ec6e3c16d492d47a013b2116a9e7 100644 (file)
@@ -32,7 +32,7 @@ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
 #define _ARC4_LOCK()   pthread_mutex_lock(&arc4random_mtx)
 #define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)
 
-#ifdef __GLIBC__
+#ifdef HAVE___REGISTER_ATFORK
 extern void *__dso_handle;
 extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
 #define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle)