From owner-svn-src-head@freebsd.org Sat Dec 3 01:14:22 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D1773C637FB; Sat, 3 Dec 2016 01:14:22 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id ABFC282E; Sat, 3 Dec 2016 01:14:22 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uB31ELrH023261; Sat, 3 Dec 2016 01:14:21 GMT (envelope-from vangyzen@FreeBSD.org) Received: (from vangyzen@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uB31EL1P023258; Sat, 3 Dec 2016 01:14:21 GMT (envelope-from vangyzen@FreeBSD.org) Message-Id: <201612030114.uB31EL1P023258@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: vangyzen set sender to vangyzen@FreeBSD.org using -f From: Eric van Gyzen Date: Sat, 3 Dec 2016 01:14:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r309460 - in head: lib/libc/sys share/man/man3 sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 Dec 2016 01:14:22 -0000 Author: vangyzen Date: Sat Dec 3 01:14:21 2016 New Revision: 309460 URL: https://svnweb.freebsd.org/changeset/base/309460 Log: thr_set_name(): silently truncate the given name as needed Instead of failing with ENAMETOOLONG, which is swallowed by pthread_set_name_np() anyway, truncate the given name to MAXCOMLEN+1 bytes. This is more likely what the user wants, and saves the caller from truncating it before the call (which was the only recourse). Polish pthread_set_name_np(3) and add a .Xr to thr_set_name(2) so the user might find the documentation for this behavior. Reviewed by: jilles MFC after: 3 days Sponsored by: Dell EMC Modified: head/lib/libc/sys/thr_set_name.2 head/share/man/man3/pthread_set_name_np.3 head/sys/kern/kern_thr.c Modified: head/lib/libc/sys/thr_set_name.2 ============================================================================== --- head/lib/libc/sys/thr_set_name.2 Sat Dec 3 01:10:45 2016 (r309459) +++ head/lib/libc/sys/thr_set_name.2 Sat Dec 3 01:14:21 2016 (r309460) @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd June 1, 2016 +.Dd December 2, 2016 .Dt THR_SET_NAME 2 .Os .Sh NAME @@ -43,37 +43,34 @@ .Sh DESCRIPTION The .Fn thr_set_name -sets the user-visible name for the kernel thread with the identifier +system call sets the user-visible name for the thread with the identifier .Va id -in the current process, to the NUL-terminated string +in the current process to the NUL-terminated string .Va name . +The name will be silently truncated to fit into a buffer of +.Dv MAXCOMLEN + 1 +bytes. The thread name can be seen in the output of the .Xr ps 1 and .Xr top 1 commands, in the kernel debuggers and kernel tracing facility outputs, -also in userland debuggers and program core files, as notes. +and in userland debuggers and program core files, as notes. .Sh RETURN VALUES If successful, .Fn thr_set_name -will return zero, otherwise \-1 is returned, and +returns zero; otherwise, \-1 is returned, and .Va errno is set to indicate the error. .Sh ERRORS The .Fn thr_set_name -operation may return the following errors: +system call may return the following errors: .Bl -tag -width Er .It Bq Er EFAULT The memory pointed to by the .Fa name argument is not valid. -.It Bq Er ENAMETOOLONG -The string pointed to by the -.Fa name -argument exceeds -.Dv MAXCOMLEN + 1 -bytes in length. .It Bq Er ESRCH The thread with the identifier .Fa id @@ -92,6 +89,6 @@ does not exist in the current process. .Xr ktr 9 .Sh STANDARDS The -.Fn thr_new -system call is non-standard and is used by +.Fn thr_set_name +system call is non-standard and is used by the .Lb libthr . Modified: head/share/man/man3/pthread_set_name_np.3 ============================================================================== --- head/share/man/man3/pthread_set_name_np.3 Sat Dec 3 01:10:45 2016 (r309459) +++ head/share/man/man3/pthread_set_name_np.3 Sat Dec 3 01:14:21 2016 (r309460) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd February 13, 2003 +.Dd December 2, 2016 .Dt PTHREAD_SET_NAME_NP 3 .Os .Sh NAME @@ -35,18 +35,19 @@ .Sh SYNOPSIS .In pthread_np.h .Ft void -.Fn pthread_set_name_np "pthread_t tid" "const char *name" +.Fn pthread_set_name_np "pthread_t thread" "const char *name" .Sh DESCRIPTION The .Fn pthread_set_name_np -function sets internal name for thread specified by -.Fa tid -argument to string value specified by +function applies a copy of the given .Fa name -argument. +to the given +.Fa thread . .Sh ERRORS Because of the debugging nature of this function, all errors that may appear inside are silently ignored. +.Sh SEE ALSO +.Xr thr_set_name 2 .Sh AUTHORS This manual page was written by .An Alexey Zelkin Aq Mt phantom@FreeBSD.org . Modified: head/sys/kern/kern_thr.c ============================================================================== --- head/sys/kern/kern_thr.c Sat Dec 3 01:10:45 2016 (r309459) +++ head/sys/kern/kern_thr.c Sat Dec 3 01:14:21 2016 (r309460) @@ -578,8 +578,11 @@ sys_thr_set_name(struct thread *td, stru error = 0; name[0] = '\0'; if (uap->name != NULL) { - error = copyinstr(uap->name, name, sizeof(name), - NULL); + error = copyinstr(uap->name, name, sizeof(name), NULL); + if (error == ENAMETOOLONG) { + error = copyin(uap->name, name, sizeof(name) - 1); + name[sizeof(name) - 1] = '\0'; + } if (error) return (error); }