Linux thread name limitation: test for ERANGE (see bug #5283)

This commit is contained in:
Sylvain 2022-02-02 15:09:29 +01:00
parent daea9fa19e
commit 87b02d3795
No known key found for this signature in database
GPG key ID: 5F87E02E5BC0939E

View file

@ -137,18 +137,22 @@ SDL_SYS_SetupThread(const char *name)
#if defined(__MACOSX__) || defined(__IPHONEOS__) #if defined(__MACOSX__) || defined(__IPHONEOS__)
ppthread_setname_np(name); ppthread_setname_np(name);
#elif defined(__LINUX__) #elif defined(__LINUX__)
char namebuf[16]; /* Limited to 16 char */ if (ppthread_setname_np(pthread_self(), name) == ERANGE) {
SDL_strlcpy(namebuf, name, sizeof (namebuf)); char namebuf[16]; /* Limited to 16 char */
ppthread_setname_np(pthread_self(), namebuf); SDL_strlcpy(namebuf, name, sizeof (namebuf));
ppthread_setname_np(pthread_self(), namebuf);
}
#endif #endif
} }
#elif HAVE_PTHREAD_SETNAME_NP #elif HAVE_PTHREAD_SETNAME_NP
#if defined(__NETBSD__) #if defined(__NETBSD__)
pthread_setname_np(pthread_self(), "%s", name); pthread_setname_np(pthread_self(), "%s", name);
#else #else
char namebuf[16]; /* Limited to 16 char */ if (pthread_setname_np(pthread_self(), name) == ERANGE) {
SDL_strlcpy(namebuf, name, sizeof (namebuf)); char namebuf[16]; /* Limited to 16 char */
pthread_setname_np(pthread_self(), namebuf); SDL_strlcpy(namebuf, name, sizeof (namebuf));
pthread_setname_np(pthread_self(), namebuf);
}
#endif #endif
#elif HAVE_PTHREAD_SET_NAME_NP #elif HAVE_PTHREAD_SET_NAME_NP
pthread_set_name_np(pthread_self(), name); pthread_set_name_np(pthread_self(), name);