diff options
author | Robert Pluim <rpluim@gmail.com> | 2019-12-19 17:33:16 +0100 |
---|---|---|
committer | Robert Pluim <rpluim@gmail.com> | 2020-01-06 15:27:26 +0100 |
commit | 9063124b9125ed5e2ad87bbb8bd6224526723a92 (patch) | |
tree | c21c1134698c8d2a131fd387dc3742645c3a1bd2 /src/systhread.c | |
parent | 088bfcc2d80eed44864147f3491eff69e4eb5cd8 (diff) | |
download | emacs-9063124b9125ed5e2ad87bbb8bd6224526723a92.tar.gz emacs-9063124b9125ed5e2ad87bbb8bd6224526723a92.tar.bz2 emacs-9063124b9125ed5e2ad87bbb8bd6224526723a92.zip |
Use pthread_setname_np to set thread name
* configure.ac: Remove check for sys/prctl.h and prctl, check for
pthread_setname_np instead.
* systhread.c: Remove sys/prctl.h include.
(sys_thread_create) [HAVE_PTHREAD_SETNAME_NP]: Use pthread_setname_np
to set the name of the newly created thread (Bug#38632).
* thread.c (Fmake_thread): Use ENCODE_SYSTEM instead of
ENCODE_UTF_8 on the thread name.
Diffstat (limited to 'src/systhread.c')
-rw-r--r-- | src/systhread.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/systhread.c b/src/systhread.c index c3e4e6a2c5a..1dda036cc2f 100644 --- a/src/systhread.c +++ b/src/systhread.c @@ -98,10 +98,6 @@ sys_thread_yield (void) #include <sched.h> -#ifdef HAVE_SYS_PRCTL_H -#include <sys/prctl.h> -#endif - void sys_mutex_init (sys_mutex_t *mutex) { @@ -227,9 +223,18 @@ sys_thread_create (sys_thread_t *thread_ptr, const char *name, if (!pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED)) { result = pthread_create (thread_ptr, &attr, func, arg) == 0; -#if defined (HAVE_SYS_PRCTL_H) && defined (HAVE_PRCTL) && defined (PR_SET_NAME) +#ifdef HAVE_PTHREAD_SETNAME_NP if (result && name != NULL) - prctl (PR_SET_NAME, name); + { + /* We need to truncate here otherwise pthread_setname_np + fails to set the name. TASK_COMM_LEN is what the length + is called in the Linux kernel headers (Bug#38632). */ +#define TASK_COMM_LEN 16 + char p_name[TASK_COMM_LEN]; + strncpy (p_name, name, TASK_COMM_LEN - 1); + p_name[TASK_COMM_LEN - 1] = '\0'; + pthread_setname_np (*thread_ptr, p_name); + } #endif } |