diff --git a/kernel/exec.c b/kernel/exec.c index 9f9bc28a69..5cdc3079cb 100644 --- a/kernel/exec.c +++ b/kernel/exec.c @@ -598,11 +598,7 @@ int __do_execve(const char *file, struct exec_args argv, struct exec_args envp) char threadname[16]; strncpy(threadname, current->comm, sizeof(threadname)-1); threadname[15] = '\0'; -#if __APPLE__ - pthread_setname_np(threadname); -#else - pthread_setname_np(pthread_self(), threadname); -#endif + set_thread_name(threadname); // cloexec // consider putting this in fd.c? diff --git a/kernel/task.c b/kernel/task.c index f413325d39..5a10087ece 100644 --- a/kernel/task.c +++ b/kernel/task.c @@ -94,6 +94,7 @@ void (*task_run_hook)(void) = NULL; static void *task_run(void *task) { current = task; + set_thread_name(current->comm); if (task_run_hook) task_run_hook(); else diff --git a/util/sync.h b/util/sync.h index 29345b976a..21eba0cdbd 100644 --- a/util/sync.h +++ b/util/sync.h @@ -118,4 +118,10 @@ static inline void sigunwind_end() { should_unwind = false; } +#if __APPLE__ +#define set_thread_name(threadname) pthread_setname_np(threadname) +#else +#define set_thread_name(threadname) pthread_setname_np(pthread_self(), threadname) +#endif + #endif