From: maxice8 Date: Tue, 16 Jan 2018 10:29:32 +0000 (-0200) Subject: work-around usage of glibc-specific __register_atfork for musl systems X-Git-Tag: v235.3~19 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=572cbd8524a5e2b22150c32118f58672449a5ca7;p=elogind.git work-around usage of glibc-specific __register_atfork for musl systems __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__ --- diff --git a/src/basic/process-util.c b/src/basic/process-util.c index d15027751..89e6f576b 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -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; diff --git a/src/shared/musl_missing.h b/src/shared/musl_missing.h index 20fc20a56..9b234556a 100644 --- a/src/shared/musl_missing.h +++ b/src/shared/musl_missing.h @@ -24,6 +24,7 @@ void elogind_set_program_name(const char* pcall); #include #include #include +#include /* 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