This is the mail archive of the
mailing list for the glibc project.
Re: [PATCH] Provide pthread_atfork in libc_nonshared.a and libc.a.
- From: Jakub Jelinek <jakub at redhat dot com>
- To: "Carlos O'Donell" <carlos at redhat dot com>
- Cc: GNU C Library <libc-alpha at sourceware dot org>, Roland McGrath <roland at hack dot frob dot com>
- Date: Thu, 3 Oct 2013 11:29:04 +0200
- Subject: Re: [PATCH] Provide pthread_atfork in libc_nonshared.a and libc.a.
- Authentication-results: sourceware.org; auth=none
- References: <524C90A1 dot 6050801 at redhat dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Wed, Oct 02, 2013 at 05:31:13PM -0400, Carlos O'Donell wrote:
> +/* The standard design pattern for making it optional to link against
> + libpthread is to mark the function weak, test if the function
> + address is non-zero and call the function, otherwise use a fallback.
> + The problem with pthread_atfork is that there is no viable
> + fallback. If you need to do something during fork it has to be done
> + via pthread_atfork. This makes having libpthread optional and using
> + pthread_atfork impossible. We make it possible by providing
> + pthread_atfork in libc_nonshared.a. The real work of pthread_atfork
> + is done by __register_atfork which is already provided in
> + libc_nonshared.a. It's included in libc_nonshared.a because
__register_atfork is in libc.so or libc.a, not in libc_nonshared.a.
> + __dso_handle has to be unique to each DSO such that unloading the DSO
> + can unregister the atfork handlers. We build pthread_atfork again
> + under a different file name and include it into libc_nonshared.a and
> + libc.a. We keep pthread_atfork in libpthread_nonshared.a and
> + libpthread.a for compatibility and completeness.
> + Applications that can't rely on a new glibc should use the following
> + code to optionally include libpthread and still register a function
> + via pthread_atfork i.e. use __register_atfork directly:
> + extern void *__dso_handle __attribute__ ((__weak__, __visibility__ ("hidden")));
> + extern int __register_atfork (void (*) (void), void (*) (void), void (*) (void), void *);
> + static int __app_atfork (void (*prepare) (void), void (*parent) (void), void (*child) (void))
__ prefix is implementation namespace, so if you think this comment
is worthwhile, make it app_atfork rather than __app_atfork to avoid
teaching people bad habits.