Skip to content

Commit 034d75b

Browse files
author
roy
committed
Document that our use of pthread_mutex_unlock(3) is async-signal-safe
and as such can be used in a phtread_atfork(3) child handler.
1 parent aeee967 commit 034d75b

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

lib/libc/gen/arc4random.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: arc4random.c,v 1.24 2014/06/12 19:12:19 apb Exp $ */
1+
/* $NetBSD: arc4random.c,v 1.25 2014/07/19 14:53:22 roy Exp $ */
22
/* $OpenBSD: arc4random.c,v 1.6 2001/06/05 05:05:38 pvalchev Exp $ */
33

44
/*
@@ -27,7 +27,7 @@
2727

2828
#include <sys/cdefs.h>
2929
#if defined(LIBC_SCCS) && !defined(lint)
30-
__RCSID("$NetBSD: arc4random.c,v 1.24 2014/06/12 19:12:19 apb Exp $");
30+
__RCSID("$NetBSD: arc4random.c,v 1.25 2014/07/19 14:53:22 roy Exp $");
3131
#endif /* LIBC_SCCS and not lint */
3232

3333
#include "namespace.h"
@@ -125,6 +125,12 @@ arc4_fork_child(void)
125125
static inline void
126126
arc4_check_init(struct arc4_stream *as)
127127
{
128+
/*
129+
* pthread_atfork(3) only allows async-signal-safe functions in
130+
* the child handler.
131+
* NetBSD's mutex_unlock is async-signal safe, other implementations
132+
* may not be.
133+
*/
128134

129135
if (__predict_false(!as->inited)) {
130136
as->inited = true;

lib/libc/gen/pthread_atfork.3

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.\" $NetBSD: pthread_atfork.3,v 1.5 2008/04/30 13:10:50 martin Exp $
1+
.\" $NetBSD: pthread_atfork.3,v 1.6 2014/07/19 14:53:22 roy Exp $
22
.\"
33
.\" Copyright (c) 2003 The NetBSD Foundation, Inc.
44
.\" All rights reserved.
@@ -27,7 +27,7 @@
2727
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2828
.\" POSSIBILITY OF SUCH DAMAGE.
2929
.\"
30-
.Dd February 12, 2003
30+
.Dd July 18, 2014
3131
.Dt PTHREAD_ATFORK 3
3232
.Os
3333
.Sh NAME
@@ -91,7 +91,9 @@ The following error code may be returned:
9191
Insufficient memory exists to register the fork handlers.
9292
.El
9393
.Sh SEE ALSO
94-
.Xr fork 2
94+
.Xr fork 2 ,
95+
.Xr pthread_mutex 3 ,
96+
.Xr signal 7
9597
.Sh STANDARDS
9698
The
9799
.Fn pthread_atfork
@@ -115,6 +117,11 @@ functions are not async-signal-safe, so it is not safe to use such functions
115117
in the
116118
.Ar child
117119
handler.
120+
POSIX does not mandate that
121+
.Fn pthread_mutex_unlock
122+
be async-signal-safe, but it is in NetBSD and thus safe to use within the
123+
.Ar child
124+
handler.
118125
.Sh BUGS
119126
There is no way to unregister a handler registered with
120127
.Fn pthread_atfork .

share/man/man7/signal.7

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.\" $NetBSD: signal.7,v 1.16 2011/01/19 04:33:13 uwe Exp $
1+
.\" $NetBSD: signal.7,v 1.17 2014/07/19 14:53:22 roy Exp $
22
.\"
33
.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
44
.\" All rights reserved.
@@ -24,7 +24,7 @@
2424
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2525
.\" POSSIBILITY OF SUCH DAMAGE.
2626
.\"
27-
.Dd February 27, 2009
27+
.Dd July 18, 2014
2828
.Dt SIGNAL 7
2929
.Os
3030
.Sh NAME
@@ -148,6 +148,7 @@ below is unsafe to use in signal handlers.
148148
.Xr poll 2 ,
149149
.\" .Xr posix_trace_event 2
150150
.\" .Xr pselect 2
151+
.Xr pthread_mutex_unlock 3 ,
151152
.Xr raise 3 ,
152153
.Xr read 2 ,
153154
.Xr readlink 2 ,

0 commit comments

Comments
 (0)