diff options
Diffstat (limited to 'libgcompat')
-rw-r--r-- | libgcompat/pthread.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/libgcompat/pthread.c b/libgcompat/pthread.c index 4ebbe6b..0456c40 100644 --- a/libgcompat/pthread.c +++ b/libgcompat/pthread.c @@ -1,4 +1,8 @@ -#include <pthread.h> +#define _GNU_SOURCE +#include <errno.h> /* errno */ +#include <fcntl.h> /* O_CLOEXEC, O_RDONLY */ +#include <pthread.h> /* pthread_atfork */ +#include <unistd.h> /* open, read */ #include "alias.h" /* weak_alias */ @@ -27,3 +31,22 @@ int __register_atfork(void (*prepare)(void), void (*parent)(void), return pthread_atfork(prepare, parent, child); } weak_alias(__register_atfork, register_atfork); + +/** + * Get the name of a thread. + */ +int pthread_getname_np(pthread_t thread, char *name, size_t len) +{ + int fd = open("/proc/thread-self/comm", O_RDONLY | O_CLOEXEC); + char dummy; + + if (fd < 0) + return errno; + if (read(fd, name, len) < 0) + return errno; + /* If there's more to read, the buffer was too small. */ + if (read(fd, &dummy, 1) > 0) + return ERANGE; + + return 0; +} |