diff --git a/lib/libthr/thread/thr_exit.c b/lib/libthr/thread/thr_exit.c index e76623cd4c8d..6feb909fe04b 100644 --- a/lib/libthr/thread/thr_exit.c +++ b/lib/libthr/thread/thr_exit.c @@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$"); #ifdef _PTHREAD_FORCED_UNWIND #include #endif +#include #include #include #include @@ -171,16 +172,29 @@ thread_unwind(void) #endif +void +_thread_exitf(const char *fname, int lineno, const char *fmt, ...) +{ + va_list ap; + + /* Write an error message to the standard error file descriptor: */ + _thread_printf(STDERR_FILENO, "Fatal error '"); + + va_start(ap, fmt); + _thread_vprintf(STDERR_FILENO, fmt, ap); + va_end(ap); + + _thread_printf(STDERR_FILENO, "' at line %d in file %s (errno = %d)\n", + lineno, fname, errno); + + abort(); +} + void _thread_exit(const char *fname, int lineno, const char *msg) { - /* Write an error message to the standard error file descriptor: */ - _thread_printf(2, - "Fatal error '%s' at line %d in file %s (errno = %d)\n", - msg, lineno, fname, errno); - - abort(); + _thread_exitf(fname, lineno, "%s", msg); } void diff --git a/lib/libthr/thread/thr_printf.c b/lib/libthr/thread/thr_printf.c index ed9428716f57..8e9a1518ba8b 100644 --- a/lib/libthr/thread/thr_printf.c +++ b/lib/libthr/thread/thr_printf.c @@ -51,9 +51,18 @@ static void pstr(int fd, const char *s); */ void _thread_printf(int fd, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + _thread_vprintf(fd, fmt, ap); + va_end(ap); +} + +void +_thread_vprintf(int fd, const char *fmt, va_list ap) { static const char digits[16] = "0123456789abcdef"; - va_list ap; char buf[20]; char *s; unsigned long r, u; @@ -61,13 +70,12 @@ _thread_printf(int fd, const char *fmt, ...) long d; int islong; - va_start(ap, fmt); while ((c = *fmt++)) { islong = 0; if (c == '%') { next: c = *fmt++; if (c == '\0') - goto out; + return; switch (c) { case 'c': pchar(fd, va_arg(ap, int)); @@ -111,8 +119,6 @@ next: c = *fmt++; } pchar(fd, c); } -out: - va_end(ap); } /* diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h index 7dd458098c7d..02b575da1e50 100644 --- a/lib/libthr/thread/thr_private.h +++ b/lib/libthr/thread/thr_private.h @@ -86,7 +86,7 @@ TAILQ_HEAD(mutex_queue, pthread_mutex); /* * Kernel fatal error handler macro. */ -#define PANIC(string) _thread_exit(__FILE__,__LINE__,string) +#define PANIC(args...) _thread_exitf(__FILE__, __LINE__, ##args) /* Output debug messages like this: */ #define stdout_debug(args...) _thread_printf(STDOUT_FILENO, ##args) @@ -778,6 +778,8 @@ void _mutex_leave_robust(struct pthread *curthread, struct pthread_mutex *m) void _libpthread_init(struct pthread *) __hidden; struct pthread *_thr_alloc(struct pthread *) __hidden; void _thread_exit(const char *, int, const char *) __hidden __dead2; +void _thread_exitf(const char *, int, const char *, ...) __hidden __dead2 + __printflike(3, 4); int _thr_ref_add(struct pthread *, struct pthread *, int) __hidden; void _thr_ref_delete(struct pthread *, struct pthread *) __hidden; void _thr_ref_delete_unlocked(struct pthread *, struct pthread *) __hidden; @@ -789,7 +791,8 @@ void _thr_stack_free(struct pthread_attr *) __hidden; void _thr_free(struct pthread *, struct pthread *) __hidden; void _thr_gc(struct pthread *) __hidden; void _thread_cleanupspecific(void) __hidden; -void _thread_printf(int, const char *, ...) __hidden; +void _thread_printf(int, const char *, ...) __hidden __printflike(2, 3); +void _thread_vprintf(int, const char *, va_list) __hidden; void _thr_spinlock_init(void) __hidden; void _thr_cancel_enter(struct pthread *) __hidden; void _thr_cancel_enter2(struct pthread *, int) __hidden;