summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-04-25 10:05:24 -0700
committerElliott Hughes <enh@google.com>2015-04-25 10:05:24 -0700
commitd1aea30b2ade504550f7bb7996c808b9af1c415d (patch)
tree5510d43664f9693ccab80e9b68be854d2ce9f859
parent2bb93482a7793640205ade2f7316db5b3f5cac19 (diff)
downloadbionic-d1aea30b2ade504550f7bb7996c808b9af1c415d.zip
bionic-d1aea30b2ade504550f7bb7996c808b9af1c415d.tar.gz
bionic-d1aea30b2ade504550f7bb7996c808b9af1c415d.tar.bz2
Fix POSIX timer thread naming.
Spencer Low points out that we never actually set a name because the constant part of the string was longer than the kernel's maximum, and the kernel rejects long names rather than truncate. Shorten the fixed part of the string while still keeping it meaningful. 9999 POSIX timers should be enough for any process... Bug: https://code.google.com/p/android/issues/detail?id=170089 Change-Id: Ic05f07584c1eac160743519091a540ebbf8d7eb1
-rw-r--r--libc/bionic/posix_timers.cpp6
-rw-r--r--tests/pthread_test.cpp4
2 files changed, 6 insertions, 4 deletions
diff --git a/libc/bionic/posix_timers.cpp b/libc/bionic/posix_timers.cpp
index bc3aeb2..c8f71c8 100644
--- a/libc/bionic/posix_timers.cpp
+++ b/libc/bionic/posix_timers.cpp
@@ -174,10 +174,10 @@ int timer_create(clockid_t clock_id, sigevent* evp, timer_t* timer_id) {
return -1;
}
- // Give the thread a meaningful name.
+ // Give the thread a specific meaningful name.
// It can't do this itself because the kernel timer isn't created until after it's running.
- char name[32];
- snprintf(name, sizeof(name), "POSIX interval timer %d", to_kernel_timer_id(timer));
+ char name[16]; // 16 is the kernel-imposed limit.
+ snprintf(name, sizeof(name), "POSIX timer %d", to_kernel_timer_id(timer));
pthread_setname_np(timer->callback_thread, name);
*timer_id = timer;
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index a299f02..a9d1097 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -403,7 +403,9 @@ TEST(pthread, pthread_sigmask) {
}
TEST(pthread, pthread_setname_np__too_long) {
- ASSERT_EQ(ERANGE, pthread_setname_np(pthread_self(), "this name is far too long for linux"));
+ // The limit is 15 characters --- the kernel's buffer is 16, but includes a NUL.
+ ASSERT_EQ(0, pthread_setname_np(pthread_self(), "123456789012345"));
+ ASSERT_EQ(ERANGE, pthread_setname_np(pthread_self(), "1234567890123456"));
}
TEST(pthread, pthread_setname_np__self) {