Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 1 Jun 2016 16:09:56 +0000 (UTC)
From:      "Conrad E. Meyer" <cem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r301134 - head/lib/libthr/thread
Message-ID:  <201606011609.u51G9ue8022253@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cem
Date: Wed Jun  1 16:09:56 2016
New Revision: 301134
URL: https://svnweb.freebsd.org/changeset/base/301134

Log:
  libthr: Add vprintf variant of _thread_printf, formatted PANIC()
  
  No ABI change.
  
  Reviewed by:	kib
  Sponsored by:	EMC / Isilon Storage Division
  Differential Revision:	https://reviews.freebsd.org/D6672

Modified:
  head/lib/libthr/thread/thr_exit.c
  head/lib/libthr/thread/thr_printf.c
  head/lib/libthr/thread/thr_private.h

Modified: head/lib/libthr/thread/thr_exit.c
==============================================================================
--- head/lib/libthr/thread/thr_exit.c	Wed Jun  1 15:56:07 2016	(r301133)
+++ head/lib/libthr/thread/thr_exit.c	Wed Jun  1 16:09:56 2016	(r301134)
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
 #ifdef _PTHREAD_FORCED_UNWIND
 #include <dlfcn.h>
 #endif
+#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <pthread.h>
@@ -172,18 +173,31 @@ thread_unwind(void)
 #endif
 
 void
-_thread_exit(const char *fname, int lineno, const char *msg)
+_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(2,
-	    "Fatal error '%s' at line %d in file %s (errno = %d)\n",
-	    msg, lineno, fname, errno);
+	_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)
+{
+
+	_thread_exitf(fname, lineno, "%s", msg);
+}
+
+void
 _pthread_exit(void *status)
 {
 	_pthread_exit_mask(status, NULL);

Modified: head/lib/libthr/thread/thr_printf.c
==============================================================================
--- head/lib/libthr/thread/thr_printf.c	Wed Jun  1 15:56:07 2016	(r301133)
+++ head/lib/libthr/thread/thr_printf.c	Wed Jun  1 16:09:56 2016	(r301134)
@@ -52,8 +52,17 @@ 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);
 }
 
 /*

Modified: head/lib/libthr/thread/thr_private.h
==============================================================================
--- head/lib/libthr/thread/thr_private.h	Wed Jun  1 15:56:07 2016	(r301133)
+++ head/lib/libthr/thread/thr_private.h	Wed Jun  1 16:09:56 2016	(r301134)
@@ -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 
 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
 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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201606011609.u51G9ue8022253>