Page MenuHome GnuPG

pthread_atfork() does not work in Android
Closed, ResolvedPublic

Description

Commit 9a3377bb534654ec398300c1900350b02321f86c added a call to
pthread_atfork(). This function is not provided by Android's Bionic libc or any
other included library. So npth can't built for Android as it is in the HEAD of
master right now.

Details

Version
9a3377bb534654ec398300c1900350b02321f86c

Event Timeline

HansChristophSteiner set Version to 9a3377bb534654ec398300c1900350b02321f86c.

I checked the source code of Bionic libc. There is the function defined:
https://github.com/android/platform_bionic/blob/master/libc/bionic/pthread_atfork.
cpp

Is it compile time option not including this function?

It looks like pthread_atfork() was not added to bionic libc[1] until after
android-10/v2.3.6/Gingerbread. That excludes 1/4 of current Google Android
users, and probably more of unoffical Android users.[4] To target older
versions of Android, you either have to include pthread-atfork.c[2] or the newer
[pthread_atfork.cpp][3] in your project, or not use pthread_atfork() at all.
We might be able to manage including pthread-atfork.c, but it could be ugly.

[1]:

https://android.googlesource.com/platform/bionic.git/+/4f086aeb4aa06e13079b7fec71a8178ceeacf318

[2]:

https://android.googlesource.com/platform/bionic.git/+/android-4.0.1_r1/libc/bionic/pthread-atfork.c

[3]:

https://android.googlesource.com/platform/bionic.git/+/master/libc/bionic/pthread_atfork.cpp

[3]: https://developer.android.com/about/dashboards/index.html

we've decided to suspend support for older versions on Android, so we can leave
this as is for now, any maybe forever. We want to support older versions, but
its more work than we can handle. Patches are welcome though, if anyone wants
to add back support for Android versions old than android-14/4.0/Ice Cream Sandwich.

Bad news, though that .c/.cpp file exists, it does not seem to get built into
Android. I have tried building against android-14, which is after that file was
introduces, and no luck. I also tried looking for it in the libs, and its not
in the .so or .a libs. Running this gives me nothing:

$ strings /opt/android-ndk/platforms/android-*/arch-arm/usr/lib/* | grep atfork

Its also not in any headers in the NDK:

$ grep atfork /opt/android-ndk/platforms/android-*/arch-arm/usr/include/*.h
$ grep atfork /opt/android-ndk/platforms/android-*/arch-arm/usr/include/*/*.h
$

Thanks for information (Note: I don't have experiences for Android).
I realized that fork/exec is basically not supported for applications on
Android.
If this were true, it makes sense to ifdef-out the calls to pthread_atfork for
Android.

The reason why we need to call pthread_atfork is to reset signal mask for
executable fork/exec-ed by the program. We had a bug which stoped killing
pinentry (which was fork/exec-ed by gpg-agent).

Even if that function is never called on Android, it will need to be #ifdefed out
in order for that code to build for Android. Right now, linking fails because it
can't find the symbol pthread_atfork.

Fixed in the git master branch.