1 /* Copyright (C) 2002 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 #include <sys/types.h>
24 #include <libio/libioP.h>
29 unsigned long int *__fork_generation_pointer
;
32 lll_lock_t __fork_lock
= LLL_LOCK_INITIALIZER
;
33 LIST_HEAD (__fork_prepare_list
);
34 LIST_HEAD (__fork_parent_list
);
35 LIST_HEAD (__fork_child_list
);
39 fresetlockfiles (void)
43 for (i
= _IO_iter_begin(); i
!= _IO_iter_end(); i
= _IO_iter_next(i
))
44 *((pthread_mutex_t
*) _IO_iter_file(i
)->_lock
)
45 = (pthread_mutex_t
) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
;
55 /* Get the lock so that the set of registered handlers is not
56 inconsistent or changes beneath us. */
57 lll_lock (__fork_lock
);
59 /* Run all the registered preparation handlers. In reverse order. */
60 list_for_each_prev (runp
, &__fork_prepare_list
)
62 struct fork_handler
*curp
;
64 curp
= list_entry (runp
, struct fork_handler
, list
);
74 # error "ARCH_FORK must be defined so that the CLONE_SETTID flag is used"
75 pid
= INLINE_SYSCALL (fork
, 0);
80 if (__fork_generation_pointer
!= NULL
)
81 *__fork_generation_pointer
+= 4;
83 /* Reset the file list. These are recursive mutexes. */
86 /* We execute this even if the 'fork' call failed. */
87 _IO_list_resetlock ();
89 /* Run the handlers registered for the child. */
90 list_for_each (runp
, &__fork_child_list
)
92 struct fork_handler
*curp
;
94 curp
= list_entry (runp
, struct fork_handler
, list
);
99 /* Initialize the fork lock. */
100 __fork_lock
= (lll_lock_t
) LLL_LOCK_INITIALIZER
;
104 /* We execute this even if the 'fork' call failed. */
107 /* Run the handlers registered for the parent. */
108 list_for_each (runp
, &__fork_parent_list
)
110 struct fork_handler
*curp
;
112 curp
= list_entry (runp
, struct fork_handler
, list
);
117 /* Release the for lock. */
118 lll_unlock (__fork_lock
);
123 weak_alias (__libc_fork
, __fork
)
124 weak_alias (__libc_fork
, fork
)