chiark / gitweb /
work-around usage of glibc-specific __register_atfork for musl systems
authormaxice8 <thinkabit.ukim@gmail.com>
Tue, 16 Jan 2018 10:29:32 +0000 (08:29 -0200)
committerSven Eden <yamakuzure@gmx.net>
Wed, 24 Jan 2018 12:22:41 +0000 (13:22 +0100)
__register_atfork is glibc-specific but is roughly equivalent to
pthread_atfork, add a definition of it on musl_missing.h and guard
against the definition of __register_atfork on src/basic/process-util.c
using #ifdef __GLIBC__

src/basic/process-util.c
src/shared/musl_missing.h

index d15027751cc8fd0476e09a6920c618eae511a004..89e6f576b7e0b2ac3086630499913864f92caf86 100644 (file)
@@ -1022,8 +1022,10 @@ static void reset_cached_pid(void) {
 /* We use glibc __register_atfork() + __dso_handle directly here, as they are not included in the glibc
  * headers. __register_atfork() is mostly equivalent to pthread_atfork(), but doesn't require us to link against
  * libpthread, as it is part of glibc anyway. */
+#ifdef __GLIBC__
 extern int __register_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void), void * __dso_handle);
 extern void* __dso_handle __attribute__ ((__weak__));
+#endif // ifdef __GLIBC__
 
 pid_t getpid_cached(void) {
         pid_t current_value;
index 20fc20a56fb5bb743417c6238e385575874c883f..9b234556a7e137afffcf9868d15af6c564c31777 100644 (file)
@@ -24,6 +24,7 @@ void elogind_set_program_name(const char* pcall);
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <pthread.h> /* for pthread_atfork */
 
 #define strerror_r(e, m, k) (strerror_r(e, m, k) < 0 ? strdup("strerror_r() failed") : m);
 
@@ -99,6 +100,13 @@ typedef __compar_fn_t comparison_fn_t;
 # endif
 #endif // ENABLE_UTMP
 
+/*
+ * Systemd makes use of undeclared glibc-specific __register_atfork to avoid
+ * a depednency on libpthread, __register_atfork is roughly equivalent to
+ * pthread_atfork so define __register_atfork to pthread_atfork.
+ */
+#define __register_atfork(prepare,parent,child,dso) pthread_atfork(prepare,parent,child)
+
 #endif // !defined(__GLIBC__)
 
 #endif // ELOGIND_BASIC_MUSL_MISSING_H_INCLUDED