CVS commit: [netbsd-8] src/lib/libc/gen

2019-01-27 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jan 27 18:25:52 UTC 2019

Modified Files:
src/lib/libc/gen [netbsd-8]: popen.c

Log Message:
Pull up following revision(s) (requested by christos in ticket #1170):

lib/libc/gen/popen.c: revision 1.36

PR/53904: Jintao Zhu: Use a mutex instead of an rwlock to assure thread safety


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.35.8.1 src/lib/libc/gen/popen.c

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/popen.c
diff -u src/lib/libc/gen/popen.c:1.35 src/lib/libc/gen/popen.c:1.35.8.1
--- src/lib/libc/gen/popen.c:1.35	Mon Feb  2 22:07:05 2015
+++ src/lib/libc/gen/popen.c	Sun Jan 27 18:25:52 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: popen.c,v 1.35 2015/02/02 22:07:05 christos Exp $	*/
+/*	$NetBSD: popen.c,v 1.35.8.1 2019/01/27 18:25:52 martin Exp $	*/
 
 /*
  * Copyright (c) 1988, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)popen.c	8.3 (Berkeley) 5/3/95";
 #else
-__RCSID("$NetBSD: popen.c,v 1.35 2015/02/02 22:07:05 christos Exp $");
+__RCSID("$NetBSD: popen.c,v 1.35.8.1 2019/01/27 18:25:52 martin Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -73,7 +73,20 @@ static struct pid {
 } *pidlist; 
 	
 #ifdef _REENTRANT
-static rwlock_t pidlist_lock = RWLOCK_INITIALIZER;
+static  mutex_t pidlist_mutex = MUTEX_INITIALIZER;
+# define MUTEX_LOCK() \
+do { \
+	if (__isthreaded) \
+		mutex_lock(_mutex); \
+} while (/*CONSTCOND*/0)
+# define MUTEX_UNLOCK() \
+do { \
+	if (__isthreaded) \
+		mutex_unlock(_mutex); \
+} while (/*CONSTCOND*/0)
+#else
+# define MUTEX_LOCK() __nothing
+# define MUTEX_UNLOCK() __nothing
 #endif
 
 static struct pid *
@@ -183,17 +196,13 @@ popen(const char *cmd, const char *type)
 	if ((cur = pdes_get(pdes, )) == NULL)
 		return NULL;
 
-#ifdef _REENTRANT
-	(void)rwlock_rdlock(_lock);
-#endif
+	MUTEX_LOCK();
 	(void)__readlockenv();
 	switch (pid = vfork()) {
 	case -1:			/* Error. */
 		serrno = errno;
 		(void)__unlockenv();
-#ifdef _REENTRANT
-		(void)rwlock_unlock(_lock);
-#endif
+		MUTEX_UNLOCK();
 		pdes_error(pdes, cur);
 		errno = serrno;
 		return NULL;
@@ -208,9 +217,7 @@ popen(const char *cmd, const char *type)
 
 	pdes_parent(pdes, cur, pid, type);
 
-#ifdef _REENTRANT
-	(void)rwlock_unlock(_lock);
-#endif
+	MUTEX_UNLOCK();
 
 	return cur->fp;
 }
@@ -228,15 +235,11 @@ popenve(const char *cmd, char *const *ar
 	if ((cur = pdes_get(pdes, )) == NULL)
 		return NULL;
 
-#ifdef _REENTRANT
-	(void)rwlock_rdlock(_lock);
-#endif
+	MUTEX_LOCK();
 	switch (pid = vfork()) {
 	case -1:			/* Error. */
 		serrno = errno;
-#ifdef _REENTRANT
-		(void)rwlock_unlock(_lock);
-#endif
+		MUTEX_UNLOCK();
 		pdes_error(pdes, cur);
 		errno = serrno;
 		return NULL;
@@ -250,9 +253,7 @@ popenve(const char *cmd, char *const *ar
 
 	pdes_parent(pdes, cur, pid, type);
 
-#ifdef _REENTRANT
-	(void)rwlock_unlock(_lock);
-#endif
+	MUTEX_UNLOCK();
 
 	return cur->fp;
 }
@@ -271,18 +272,14 @@ pclose(FILE *iop)
 
 	_DIAGASSERT(iop != NULL);
 
-#ifdef _REENTRANT
-	rwlock_wrlock(_lock);
-#endif
+	MUTEX_LOCK();
 
 	/* Find the appropriate file pointer. */
 	for (last = NULL, cur = pidlist; cur; last = cur, cur = cur->next)
 		if (cur->fp == iop)
 			break;
 	if (cur == NULL) {
-#ifdef _REENTRANT
-		(void)rwlock_unlock(_lock);
-#endif
+		MUTEX_UNLOCK();
 		errno = ESRCH;
 		return -1;
 	}
@@ -295,9 +292,7 @@ pclose(FILE *iop)
 	else
 		last->next = cur->next;
 
-#ifdef _REENTRANT
-	(void)rwlock_unlock(_lock);
-#endif
+	MUTEX_UNLOCK();
 
 	do {
 		pid = waitpid(cur->pid, , 0);



CVS commit: [netbsd-8] src/lib/libc/gen

2018-01-16 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Jan 16 14:15:50 UTC 2018

Modified Files:
src/lib/libc/gen [netbsd-8]: vis.c

Log Message:
Pull up the following, requested by maya in #411:

lib/libc/gen/vis.c  1.74

Use 16x instead of 4x the amount of space since each wint_t
can result in 4 bytes of 4 characters ("\ooo") each.


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.73.4.1 src/lib/libc/gen/vis.c

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/vis.c
diff -u src/lib/libc/gen/vis.c:1.73 src/lib/libc/gen/vis.c:1.73.4.1
--- src/lib/libc/gen/vis.c:1.73	Sun Apr 23 01:58:48 2017
+++ src/lib/libc/gen/vis.c	Tue Jan 16 14:15:50 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: vis.c,v 1.73 2017/04/23 01:58:48 christos Exp $	*/
+/*	$NetBSD: vis.c,v 1.73.4.1 2018/01/16 14:15:50 martin Exp $	*/
 
 /*-
  * Copyright (c) 1989, 1993
@@ -57,7 +57,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: vis.c,v 1.73 2017/04/23 01:58:48 christos Exp $");
+__RCSID("$NetBSD: vis.c,v 1.73.4.1 2018/01/16 14:15:50 martin Exp $");
 #endif /* LIBC_SCCS and not lint */
 #ifdef __FBSDID
 __FBSDID("$FreeBSD$");
@@ -432,10 +432,10 @@ istrsenvisx(char **mbdstp, size_t *dlen,
 	mdst = NULL;
 	if ((psrc = calloc(mbslength + 1, sizeof(*psrc))) == NULL)
 		return -1;
-	if ((pdst = calloc((4 * mbslength) + 1, sizeof(*pdst))) == NULL)
+	if ((pdst = calloc((16 * mbslength) + 1, sizeof(*pdst))) == NULL)
 		goto out;
 	if (*mbdstp == NULL) {
-		if ((mdst = calloc((4 * mbslength) + 1, sizeof(*mdst))) == NULL)
+		if ((mdst = calloc((16 * mbslength) + 1, sizeof(*mdst))) == NULL)
 			goto out;
 		*mbdstp = mdst;
 	}
@@ -468,12 +468,13 @@ istrsenvisx(char **mbdstp, size_t *dlen,
 			clen = 1;
 			cerr = 1;
 		}
-		if (clen == 0)
+		if (clen == 0) {
 			/*
 			 * NUL in input gives 0 return value. process
 			 * as single NUL byte and keep going.
 			 */
 			clen = 1;
+		}
 		/* Advance buffer character pointer. */
 		src++;
 		/* Advance input pointer by number of bytes read. */



CVS commit: [netbsd-8] src/lib/libc/gen

2017-12-10 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Sun Dec 10 10:18:22 UTC 2017

Modified Files:
src/lib/libc/gen [netbsd-8]: signal.3

Log Message:
Pull up following revision(s) (requested by dholland in ticket #433):
lib/libc/gen/signal.3: revision 1.28
The list of async-signal-safe functions got moved to sigaction(2).


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.27.8.1 src/lib/libc/gen/signal.3

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/signal.3
diff -u src/lib/libc/gen/signal.3:1.27 src/lib/libc/gen/signal.3:1.27.8.1
--- src/lib/libc/gen/signal.3:1.27	Mon Jun  6 08:28:18 2016
+++ src/lib/libc/gen/signal.3	Sun Dec 10 10:18:22 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: signal.3,v 1.27 2016/06/06 08:28:18 wiz Exp $
+.\"	$NetBSD: signal.3,v 1.27.8.1 2017/12/10 10:18:22 snj Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -149,7 +149,7 @@ ignored signals remain ignored.
 .Pp
 Only functions that are async-signal-safe can safely be used in signal
 handlers, see
-.Xr signal 7
+.Xr sigaction 2
 for a complete list.
 .Sh RETURN VALUES
 The previous action is returned on a successful call.