Skip to content

Commit

Permalink
build: Link to libpthread, if pthread_atfork() needs to be used
Browse files Browse the repository at this point in the history
On non-glibc systems (e.g., FreeBSD), pthread_atfork() stub is
provided as a nop and our fork detection mechanism doesn't work.  Pull
in the actual implementation from libpthread in that case.

Signed-off-by: Daiki Ueno <[email protected]>
  • Loading branch information
ueno committed Aug 10, 2018
1 parent 6a8da20 commit 541d79c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* server: Enable socket activation through systemd [PR#173]
* rpc-server: p11_kit_remote_serve_tokens: Allow exporting all modules [PR#174]
* proxy: Fail early if there is no slot mapping [PR#175]
* Remove hard dependency on libpthread [PR#177]
* Remove hard dependency on libpthread on glibc systems [PR#177]
* Build fixes [PR#170, PR#176]

0.23.12 (stable)
Expand Down
10 changes: 6 additions & 4 deletions common/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,14 @@ extern int __register_atfork (void (*prepare) (void), void (*parent) (void),

#ifdef HAVE___REGISTER_ATFORK

#define p11_register_atfork(a,b,c,d) \
(__register_atfork((a),(b),(c),(d)))
extern void *__dso_handle;

#define p11_register_atfork(a,b,c) \
(__register_atfork((a),(b),(c),__dso_handle))

#else

#define p11_register_atfork(a,b,c,d) \
#define p11_register_atfork(a,b,c) \
(pthread_atfork((a),(b),(c)))

#endif /* HAVE___REGISTER_ATFORK */
Expand All @@ -177,7 +179,7 @@ p11_library_init_impl (void)
p11_message_locale = newlocale (LC_ALL_MASK, "POSIX", (locale_t) 0);
#endif

p11_register_atfork (NULL, NULL, count_forks, NULL);
p11_register_atfork (NULL, NULL, count_forks);
}

void
Expand Down
7 changes: 6 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ if test "$os_unix" = "yes"; then
AC_CHECK_FUNCS([setenv])
AC_CHECK_FUNCS([getpeereid])
AC_CHECK_FUNCS([getpeerucred])
AC_CHECK_FUNCS([__register_atfork])
# If __register_atfork() is not available, we have to link to
# libpthread so that the non-stub version of pthread_atfork() work
# FIXME: replace pthread_atfork() uses with manual PID checks
AC_CHECK_FUNCS([__register_atfork], , [
AC_CHECK_LIB([pthread], [pthread_atfork])
])
AC_CHECK_DECLS([__register_atfork])

# Check if issetugid() is available and has compatible behavior with OpenBSD
Expand Down

0 comments on commit 541d79c

Please sign in to comment.