This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix bug of __register_atfork


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. */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]