diff options
author | Eric van Gyzen <vangyzen@FreeBSD.org> | 2016-12-03 01:14:21 +0000 |
---|---|---|
committer | Eric van Gyzen <vangyzen@FreeBSD.org> | 2016-12-03 01:14:21 +0000 |
commit | ff07dd913e2788f22cf2999f42b8a2d3bc7da220 (patch) | |
tree | d20ada1d7b19b1e36a9410d7353f063307500d11 /sys/kern/kern_thr.c | |
parent | 86bd08e9ee24812240e144fba570f88d31dd0b97 (diff) | |
download | src-ff07dd913e2788f22cf2999f42b8a2d3bc7da220.tar.gz src-ff07dd913e2788f22cf2999f42b8a2d3bc7da220.zip |
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
Notes
Notes:
svn path=/head/; revision=309460
Diffstat (limited to 'sys/kern/kern_thr.c')
-rw-r--r-- | sys/kern/kern_thr.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/sys/kern/kern_thr.c b/sys/kern/kern_thr.c index 10e7b2d0ecd1..55c4ae4007ce 100644 --- a/sys/kern/kern_thr.c +++ b/sys/kern/kern_thr.c @@ -578,8 +578,11 @@ sys_thr_set_name(struct thread *td, struct thr_set_name_args *uap) 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); } |