Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libpthread Pass down errno when calling pthread__errorfu...
details: https://anonhg.NetBSD.org/src/rev/e9899e2eb010
branches: trunk
changeset: 933978:e9899e2eb010
user: joerg <joerg%NetBSD.org@localhost>
date: Tue Jun 02 00:29:53 2020 +0000
description:
Pass down errno when calling pthread__errorfunc after a system call.
Allow format arguments for that reason and use (v)snprintf_ss in
pthread_errorfunc to avoid race conditions and the like.
diffstat:
lib/libpthread/pthread.c | 22 ++++++++++++++--------
lib/libpthread/pthread_int.h | 6 +++---
lib/libpthread/pthread_rwlock.c | 6 +++---
3 files changed, 20 insertions(+), 14 deletions(-)
diffs (125 lines):
diff -r 7d0ade462c50 -r e9899e2eb010 lib/libpthread/pthread.c
--- a/lib/libpthread/pthread.c Mon Jun 01 22:58:06 2020 +0000
+++ b/lib/libpthread/pthread.c Tue Jun 02 00:29:53 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread.c,v 1.171 2020/06/01 11:44:59 ad Exp $ */
+/* $NetBSD: pthread.c,v 1.172 2020/06/02 00:29:53 joerg Exp $ */
/*-
* Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread.c,v 1.171 2020/06/01 11:44:59 ad Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.172 2020/06/02 00:29:53 joerg Exp $");
#define __EXPOSE_STACK 1
@@ -622,7 +622,7 @@
self->pt_nwaiters = 0;
if (rv != 0) {
pthread__errorfunc(__FILE__, __LINE__, __func__,
- "_lwp_unpark failed");
+ "_lwp_unpark failed: %d", errno);
}
break;
default:
@@ -631,7 +631,7 @@
self->pt_nwaiters = 0;
if (rv != 0) {
pthread__errorfunc(__FILE__, __LINE__, __func__,
- "_lwp_unpark_all failed");
+ "_lwp_unpark_all failed: %d", errno);
}
break;
}
@@ -1102,23 +1102,29 @@
void
pthread__errorfunc(const char *file, int line, const char *function,
- const char *msg)
+ const char *msg, ...)
{
char buf[1024];
+ char buf2[1024];
size_t len;
+ va_list ap;
if (pthread__diagassert == 0)
return;
+ va_start(ap, msg);
+ vsnprintf_ss(buf2, sizeof(buf2), msg, ap);
+ va_end(ap);
+
/*
* snprintf should not acquire any locks, or we could
* end up deadlocked if the assert caller held locks.
*/
- len = snprintf(buf, 1024,
+ len = snprintf_ss(buf, sizeof(buf),
"%s: Error detected by libpthread: %s.\n"
"Detected by file \"%s\", line %d%s%s%s.\n"
"See pthread(3) for information.\n",
- getprogname(), msg, file, line,
+ getprogname(), buf2, file, line,
function ? ", function \"" : "",
function ? function : "",
function ? "\"" : "");
@@ -1195,7 +1201,7 @@
break;
default:
pthread__errorfunc(__FILE__, __LINE__,
- __func__, "_lwp_park failed");
+ __func__, "_lwp_park failed: %d", errno);
break;
}
}
diff -r 7d0ade462c50 -r e9899e2eb010 lib/libpthread/pthread_int.h
--- a/lib/libpthread/pthread_int.h Mon Jun 01 22:58:06 2020 +0000
+++ b/lib/libpthread/pthread_int.h Tue Jun 02 00:29:53 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_int.h,v 1.105 2020/06/01 11:44:59 ad Exp $ */
+/* $NetBSD: pthread_int.h,v 1.106 2020/06/02 00:29:53 joerg Exp $ */
/*-
* Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008, 2020
@@ -300,8 +300,8 @@
__dead void pthread__assertfunc(const char *, int, const char *, const char *)
PTHREAD_HIDE;
-void pthread__errorfunc(const char *, int, const char *, const char *)
- PTHREAD_HIDE;
+void pthread__errorfunc(const char *, int, const char *, const char *, ...)
+ __printflike(4, 5) PTHREAD_HIDE;
char *pthread__getenv(const char *) PTHREAD_HIDE;
__dead void pthread__cancelled(void) PTHREAD_HIDE;
void pthread__mutex_deferwake(pthread_t, pthread_mutex_t *) PTHREAD_HIDE;
diff -r 7d0ade462c50 -r e9899e2eb010 lib/libpthread/pthread_rwlock.c
--- a/lib/libpthread/pthread_rwlock.c Mon Jun 01 22:58:06 2020 +0000
+++ b/lib/libpthread/pthread_rwlock.c Tue Jun 02 00:29:53 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_rwlock.c,v 1.41 2020/06/01 11:44:59 ad Exp $ */
+/* $NetBSD: pthread_rwlock.c,v 1.42 2020/06/02 00:29:53 joerg Exp $ */
/*-
* Copyright (c) 2002, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_rwlock.c,v 1.41 2020/06/01 11:44:59 ad Exp $");
+__RCSID("$NetBSD: pthread_rwlock.c,v 1.42 2020/06/02 00:29:53 joerg Exp $");
#include <sys/types.h>
#include <sys/lwpctl.h>
@@ -361,7 +361,7 @@
return error;
pthread__errorfunc(__FILE__, __LINE__, __func__,
- "direct handoff failure");
+ "direct handoff failure: %d", errno);
}
}
Home |
Main Index |
Thread Index |
Old Index