0
|
1 |
/*
|
|
2 |
* CDDL HEADER START
|
|
3 |
*
|
|
4 |
* The contents of this file are subject to the terms of the
|
|
5 |
* Common Development and Distribution License, Version 1.0 only
|
|
6 |
* (the "License"). You may not use this file except in compliance
|
|
7 |
* with the License.
|
|
8 |
*
|
|
9 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
10 |
* or http://www.opensolaris.org/os/licensing.
|
|
11 |
* See the License for the specific language governing permissions
|
|
12 |
* and limitations under the License.
|
|
13 |
*
|
|
14 |
* When distributing Covered Code, include this CDDL HEADER in each
|
|
15 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
16 |
* If applicable, add the following below this CDDL HEADER, with the
|
|
17 |
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
18 |
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
19 |
*
|
|
20 |
* CDDL HEADER END
|
|
21 |
*/
|
|
22 |
/*
|
|
23 |
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
|
|
24 |
* Use is subject to license terms.
|
|
25 |
*/
|
|
26 |
|
|
27 |
#pragma ident "%Z%%M% %I% %E% SMI"
|
|
28 |
|
|
29 |
#include "synonyms.h"
|
|
30 |
#include <mtlib.h>
|
|
31 |
#include <sys/types.h>
|
|
32 |
#include <synch.h>
|
|
33 |
#include <thread.h>
|
|
34 |
#include "libc.h"
|
|
35 |
|
|
36 |
/*
|
|
37 |
* fork1-safety.
|
|
38 |
* These three routines were used to make some libc interfaces fork1-safe.
|
|
39 |
* With the merge of libthread into libc, almost all libc internal-only
|
|
40 |
* locks are acquired via lmutex_lock() or lrw_rdlock()/lrw_wrlock(),
|
|
41 |
* which makes them automatically fork1-safe (as well as async-signal
|
|
42 |
* safe), so these functions are now used only for the locks that cannot
|
|
43 |
* be used with lmutex_lock or lrw_rdlock()/lrw_wrlock().
|
|
44 |
*/
|
|
45 |
|
|
46 |
extern void atexit_locks(void);
|
|
47 |
extern void atexit_unlocks(void);
|
|
48 |
|
|
49 |
extern void stdio_locks(void);
|
|
50 |
extern void stdio_unlocks(void);
|
|
51 |
|
|
52 |
static void
|
|
53 |
libc_prepare_atfork(void)
|
|
54 |
{
|
|
55 |
atexit_locks();
|
|
56 |
stdio_locks();
|
|
57 |
}
|
|
58 |
|
|
59 |
static void
|
|
60 |
libc_child_atfork(void)
|
|
61 |
{
|
|
62 |
stdio_unlocks();
|
|
63 |
atexit_unlocks();
|
|
64 |
}
|
|
65 |
|
|
66 |
static void
|
|
67 |
libc_parent_atfork(void)
|
|
68 |
{
|
|
69 |
stdio_unlocks();
|
|
70 |
atexit_unlocks();
|
|
71 |
}
|
|
72 |
|
|
73 |
/* called from libc_init() */
|
|
74 |
void
|
|
75 |
atfork_init(void)
|
|
76 |
{
|
|
77 |
/* same as pthread_atfork() but private to libc */
|
|
78 |
extern int _private_pthread_atfork(void (*)(void),
|
|
79 |
void (*)(void), void (*)(void));
|
|
80 |
|
|
81 |
(void) _private_pthread_atfork(libc_prepare_atfork,
|
|
82 |
libc_parent_atfork, libc_child_atfork);
|
|
83 |
}
|