diff options
author | 2017-09-05 02:40:54 +0000 | |
---|---|---|
committer | 2017-09-05 02:40:54 +0000 | |
commit | a5511fa9f431600dbd6dc2b46fc4e6b73e7d239c (patch) | |
tree | bf9e27f29ab35e6599d4c1362a9902d7e7bfdc74 /lib/libc/thread/rthread_debug.c | |
parent | Serialize access to IP reassembly queue with a mutex. This lets (diff) | |
download | wireguard-openbsd-a5511fa9f431600dbd6dc2b46fc4e6b73e7d239c.tar.xz wireguard-openbsd-a5511fa9f431600dbd6dc2b46fc4e6b73e7d239c.zip |
Move mutex, condvar, and thread-specific data routes, pthread_once, and
pthread_exit from libpthread to libc, along with low-level bits to
support them. Major bump to both libc and libpthread.
Requested by libressl team. Ports testing by naddy@
ok kettenis@
Diffstat (limited to 'lib/libc/thread/rthread_debug.c')
-rw-r--r-- | lib/libc/thread/rthread_debug.c | 54 |
1 files changed, 3 insertions, 51 deletions
diff --git a/lib/libc/thread/rthread_debug.c b/lib/libc/thread/rthread_debug.c index 18d3a8567d6..67dca29e054 100644 --- a/lib/libc/thread/rthread_debug.c +++ b/lib/libc/thread/rthread_debug.c @@ -1,27 +1,14 @@ -/* $OpenBSD: rthread_debug.c,v 1.2 2017/08/15 06:38:41 guenther Exp $ */ +/* $OpenBSD: rthread_debug.c,v 1.3 2017/09/05 02:40:54 guenther Exp $ */ /* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */ #include <pthread.h> #include <stdarg.h> #include <stdio.h> -#include <stdlib.h> #include <unistd.h> #include "rthread.h" -REDIRECT_SYSCALL(issetugid); - -int _rthread_debug_level; - -/* - * Note: messages truncated at 255 characters. Could use vasprintf, - * but don't want to use malloc here so the function can be used - * in signal handlers. - */ -#define MAX_MSG_LEN 256 -#define RTHREAD_ENV_DEBUG "RTHREAD_DEBUG" - /* * format and send output to stderr if the given "level" is less than or * equal to the current debug level. Messages with a level <= 0 will @@ -30,47 +17,12 @@ int _rthread_debug_level; void _rthread_debug(int level, const char *fmt, ...) { - char msg[MAX_MSG_LEN]; - char *p; - int cnt; - ssize_t c; - if (_rthread_debug_level >= level) { va_list ap; va_start(ap, fmt); - cnt = vsnprintf(msg, MAX_MSG_LEN, fmt, ap); + vdprintf(STDERR_FILENO, fmt, ap); va_end(ap); - if (cnt > MAX_MSG_LEN - 1) - cnt = MAX_MSG_LEN - 1; - p = msg; - do { - c = write(STDERR_FILENO, p, cnt); - if (c == -1) - break; - if (c != cnt) - sched_yield(); - p += c; - cnt -= c; - } while (cnt > 0); } } +DEF_STRONG(_rthread_debug); -/* - * set the debug level from an environment string. Bogus values are - * silently ignored. - */ -void -_rthread_debug_init(void) -{ - char *envp; - char *rem; - - if (issetugid()) - return; - envp = getenv(RTHREAD_ENV_DEBUG); - if (envp) { - _rthread_debug_level = (int) strtol(envp, &rem, 0); - if (*rem || _rthread_debug_level < 0) - _rthread_debug_level = 0; - } -} |