[lxc-devel] [PATCH] Use pthread_atfork() to unlock mutexes after fork()

Serge Hallyn serge.hallyn at ubuntu.com
Fri Jan 3 21:30:20 UTC 2014


Quoting S.Çağlar Onur (caglar at 10ur.org):
> Hi,
> 
> On Fri, Jan 3, 2014 at 3:13 PM, Stéphane Graber <stgraber at ubuntu.com> wrote:
> > On Thu, Jan 02, 2014 at 08:59:10AM -0600, Serge Hallyn wrote:
> >> Quoting Stéphane Graber (stgraber at ubuntu.com):
> >> > On Wed, Jan 01, 2014 at 11:37:32PM -0600, Serge Hallyn wrote:
> >> > > Quoting Stéphane Graber (stgraber at ubuntu.com):
> >> > > > This patch caused a build failure on Android:
> >> > > >
> >> > > > arm-linux-androideabi-gcc --sysroot=/tmp/android-build-scripts/android-ndk-r9b/platforms/android-9/arch-arm/ -DHAVE_CONFIG_H -I. -I../../src    -fPIC -DPIC -I../../src -DLXCROOTFSMOUNT=\"/data/lxc/lxc/lib/lxc/rootfs\" -DLXCPATH=\"/data/lxc/lxc/var/lib/lxc\" -DLXC_GLOBAL_CONF=\"/data/lxc/lxc/etc/lxc/lxc.conf\" -DLXCINITDIR=\"/data/lxc/lxc/libexec\" -DLXCTEMPLATEDIR=\"/data/lxc/lxc/share/lxc/templates\" -DLOGPATH=\"/data/lxc/lxc/var/log/lxc\" -DLXC_DEFAULT_CONFIG=\"/data/lxc/lxc/etc/lxc/default.conf\" -DLXClxclock.c: In function 'process_lock_setup_atfork':
> >> > > > lxclock.c:332:2: error: implicit declaration of function 'pthread_atfork' [-Werror=implicit-function-declaration]
> >> > > >   pthread_atfork(process_lock, process_unlock, process_unlock);
> >> > >
> >> > > Hm,  according to
> >> > > http://stackoverflow.com/questions/12370970/undefined-reference-to-pthread-atfork-while-i-was-trying-to-port-libpcsclite-t
> >> > > perhaps all we need is to declare the fn before its use.  Do you
> >> > > have a local bionic compiler handy to test that on?
> >> >
> >> > Not having much luck with that... this just turned it into:
> >> >
> >> > liblxc.so: error: undefined reference to 'pthread_atfork'
> >> >
> >> > pthread on bionic is part of the C library so no extra linker flags
> >> > should be needed to make this work...
> >>
> >> Hm.  So we can either (a) keep looking for a way to make it work in
> >> bionic, (b) give in and switch all uses of fork() to lxc_fork() to
> >> do our own atfork hook, or (c) detect at configure.ac whether we have
> >> pthread_atfork(), and if not then just don't do it.
> >
> > I think doing (c) would be the easiest here and would also mean that
> > whenever pthread_atfork actually shows up in bionic (assuming the
> > configure.ac detection code doesn't already detect it as present...),
> > things will just work.
> >
> > It may be worth adding an entry to the configure.ac config overview part
> > to indicate threading support so it's clear to anyone building on bionic
> > that they shouldn't expect this to be working.
> 
> What about something like [1] (after reverting
> 64b1be2903078ef9e9ba3ffcbc30a4dc9bc5cc6c)?
> 
> It adds the pthread_atfork check, removes static_lock/unlock, puts the
> values array into TLS for non-bionic targets and lastly add a warning
> for bionic users.
> 
> [1] http://10ur.org/lock.patch

Would it be possible+better to have the warning printed when
we didn't find pthread_atfork?


More information about the lxc-devel mailing list