Module Name: src
Committed By: roy
Date: Sat Jul 19 14:53:22 UTC 2014
Modified Files:
src/lib/libc/gen: arc4random.c pthread_atfork.3
src/share/man/man7: signal.7
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/lib/libc/gen/arc4random.c
cvs rdiff -u -r1.5 -r1.6 src/lib/libc/gen/pthread_atfork.3
cvs rdiff -u -r1.16 -r1.17 src/share/man/man7/signal.7
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/gen/arc4random.c
diff -u src/lib/libc/gen/arc4random.c:1.24 src/lib/libc/gen/arc4random.c:1.25
--- src/lib/libc/gen/arc4random.c:1.24 Thu Jun 12 19:12:19 2014
+++ src/lib/libc/gen/arc4random.c Sat Jul 19 14:53:22 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: arc4random.c,v 1.24 2014/06/12 19:12:19 apb Exp $ */
+/* $NetBSD: arc4random.c,v 1.25 2014/07/19 14:53:22 roy Exp $ */
/* $OpenBSD: arc4random.c,v 1.6 2001/06/05 05:05:38 pvalchev Exp $ */
/*
@@ -27,7 +27,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: arc4random.c,v 1.24 2014/06/12 19:12:19 apb Exp $");
+__RCSID("$NetBSD: arc4random.c,v 1.25 2014/07/19 14:53:22 roy Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@@ -125,6 +125,12 @@ arc4_fork_child(void)
static inline void
arc4_check_init(struct arc4_stream *as)
{
+ /*
+ * pthread_atfork(3) only allows async-signal-safe functions in
+ * the child handler.
+ * NetBSD's mutex_unlock is async-signal safe, other implementations
+ * may not be.
+ */
if (__predict_false(!as->inited)) {
as->inited = true;
Index: src/lib/libc/gen/pthread_atfork.3
diff -u src/lib/libc/gen/pthread_atfork.3:1.5 src/lib/libc/gen/pthread_atfork.3:1.6
--- src/lib/libc/gen/pthread_atfork.3:1.5 Wed Apr 30 13:10:50 2008
+++ src/lib/libc/gen/pthread_atfork.3 Sat Jul 19 14:53:22 2014
@@ -1,4 +1,4 @@
-.\" $NetBSD: pthread_atfork.3,v 1.5 2008/04/30 13:10:50 martin Exp $
+.\" $NetBSD: pthread_atfork.3,v 1.6 2014/07/19 14:53:22 roy Exp $
.\"
.\" Copyright (c) 2003 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -27,7 +27,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd February 12, 2003
+.Dd July 18, 2014
.Dt PTHREAD_ATFORK 3
.Os
.Sh NAME
@@ -91,7 +91,9 @@ The following error code may be returned
Insufficient memory exists to register the fork handlers.
.El
.Sh SEE ALSO
-.Xr fork 2
+.Xr fork 2 ,
+.Xr pthread_mutex 3 ,
+.Xr signal 7
.Sh STANDARDS
The
.Fn pthread_atfork
@@ -115,6 +117,11 @@ functions are not async-signal-safe, so
in the
.Ar child
handler.
+POSIX does not mandate that
+.Fn pthread_mutex_unlock
+be async-signal-safe, but it is in NetBSD and thus safe to use within the
+.Ar child
+handler.
.Sh BUGS
There is no way to unregister a handler registered with
.Fn pthread_atfork .
Index: src/share/man/man7/signal.7
diff -u src/share/man/man7/signal.7:1.16 src/share/man/man7/signal.7:1.17
--- src/share/man/man7/signal.7:1.16 Wed Jan 19 04:33:13 2011
+++ src/share/man/man7/signal.7 Sat Jul 19 14:53:22 2014
@@ -1,4 +1,4 @@
-.\" $NetBSD: signal.7,v 1.16 2011/01/19 04:33:13 uwe Exp $
+.\" $NetBSD: signal.7,v 1.17 2014/07/19 14:53:22 roy Exp $
.\"
.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -24,7 +24,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd February 27, 2009
+.Dd July 18, 2014
.Dt SIGNAL 7
.Os
.Sh NAME
@@ -148,6 +148,7 @@ below is unsafe to use in signal handler
.Xr poll 2 ,
.\" .Xr posix_trace_event 2
.\" .Xr pselect 2
+.Xr pthread_mutex_unlock 3 ,
.Xr raise 3 ,
.Xr read 2 ,
.Xr readlink 2 ,