From b267fa2867fd98d2f8864fd82efc8ad4b2276f39 Mon Sep 17 00:00:00 2001 From: Jason King Date: Fri, 5 May 2017 22:58:26 +0000 Subject: OS-7200 would like thread name API OS-7205 bhyve makefile uses wrong linker flags Reviewed by: Robert Mustacchi Reviewed by: Jason King Reviewed by: Patrick Mooney Approved by: Patrick Mooney --- usr/src/uts/common/disp/thread.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'usr/src/uts/common/disp/thread.c') diff --git a/usr/src/uts/common/disp/thread.c b/usr/src/uts/common/disp/thread.c index aece8faaff..d576738e75 100644 --- a/usr/src/uts/common/disp/thread.c +++ b/usr/src/uts/common/disp/thread.c @@ -74,6 +74,7 @@ #include #include #include +#include #include #ifndef STACK_GROWTH_DOWN @@ -2334,7 +2335,7 @@ stkinfo_percent(caddr_t t_stk, caddr_t t_stkbase, caddr_t sp) * It is also expected callers on behalf of userland clients have done * any necessary permission checks. */ -void +int thread_setname(kthread_t *t, const char *name) { char *buf = NULL; @@ -2355,6 +2356,11 @@ thread_setname(kthread_t *t, const char *name) * usage in highly constrained situations (e.g. dtrace). */ if (name != NULL && name[0] != '\0') { + for (size_t i = 0; name[i] != '\0'; i++) { + if (!isprint(name[i])) + return (EINVAL); + } + buf = kmem_zalloc(THREAD_NAME_MAX, KM_SLEEP); (void) strlcpy(buf, name, THREAD_NAME_MAX); } @@ -2371,4 +2377,25 @@ thread_setname(kthread_t *t, const char *name) } } mutex_exit(&ttoproc(t)->p_lock); + return (0); +} + +int +thread_vsetname(kthread_t *t, const char *fmt, ...) +{ + char name[THREAD_NAME_MAX]; + va_list va; + int rc; + + va_start(va, fmt); + rc = vsnprintf(name, sizeof (name), fmt, va); + va_end(va); + + if (rc < 0) + return (EINVAL); + + if (rc >= sizeof (name)) + return (ENAMETOOLONG); + + return (thread_setname(t, name)); } -- cgit v1.2.3