This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Fix bug of __register_atfork
- From: Lai Jiangshan <laijs at cn dot fujitsu dot com>
- To: Ulrich Drepper <drepper at redhat dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Tue, 30 Oct 2007 09:33:38 +0800
- Subject: Re: [PATCH] Fix bug of __register_atfork
- References: <47205A3E.8050807@cn.fujitsu.com> <4723DF98.3000301@redhat.com>
Ulrich Drepper wrote:
Yes, there is a problem, but your patch is far too expensive. You
didn't wonder why there is a set of preallocated structs? I've checked
in a patch.
Sorry I haven't thought deeply about the preallocated structs.
It seems there is a little problem in the new patch.
There are two statements in the function __register_atfork():
newp->next = __fork_handlers;
__fork_handlers = newp;
which have race condition with __linkin_atfork().
See this sequence:
Thread-1 Thread-2
newp->next = __fork_handlers;
__linkin_atfork(linkin_newp).
__fork_handlers = newp;
linkin_newp was failed to be inserted into the linked-list after
this sequence.
The easiest way to fix this race condition is using
__linkin_atfork(newp) to replace these two statements.
--- glibc/nptl/sysdeps/unix/sysv/linux/register-atfork.c.org 2007-10-27 15:49:31.000000000 +0800
+++ glibc/nptl/sysdeps/unix/sysv/linux/register-atfork.c 2007-10-27 17:39:26.000000000 +0800
@@ -98,8 +98,7 @@
newp->child_handler = child;
newp->dso_handle = dso_handle;
- newp->next = __fork_handlers;
- __fork_handlers = newp;
+ __linkin_atfork(newp);
}
/* Release the lock. */