Re: [PATCH v5 07/24] util: set the name for the 'main' thread

Paolo Bonzini <[email protected]>
Newsgroups org.nongnu.qemu-rust,org.nongnu.qemu-devel
Message-ID <[email protected]>
On 1/8/26 18:03, Daniel P. Berrangé wrote:
> The default main thread name is undefined, so use a constructor to
> explicitly set it to 'main'. This constructor is marked to run early
> as the thread name is intended to be used in error reporting / logs
> which may be triggered very early in QEMU execution.

At least on Linux I don't think we want to call the pthread function.

Since pthread_setname_np writes to /proc/self/task/tid/comm, wouldn't 
that cause ps to show qemu processes as "main" instead of "qemu" or 
"qemu-kvm"?

Paolo

> Reviewed-by: Richard Henderson <[email protected]>
> Reviewed-by: Dr. David Alan Gilbert <[email protected]>
> Signed-off-by: Daniel P. Berrangé <[email protected]>
> ---
>   util/qemu-thread-posix.c | 6 ++++++
>   util/qemu-thread-win32.c | 6 ++++++
>   2 files changed, 12 insertions(+)
> 
> diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c
> index b1c127dbe3..afeac9ecad 100644
> --- a/util/qemu-thread-posix.c
> +++ b/util/qemu-thread-posix.c
> @@ -22,6 +22,12 @@
>   #include <pthread_np.h>
>   #endif
>   
> +static void __attribute__((__constructor__(QEMU_CONSTRUCTOR_EARLY)))
> +qemu_thread_init(void)
> +{
> +    qemu_thread_set_name("main");
> +}
> +
>   static void error_exit(int err, const char *msg)
>   {
>       fprintf(stderr, "qemu: %s: %s\n", msg, strerror(err));
> diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c
> index 4d2d663a9a..8ca6429ad3 100644
> --- a/util/qemu-thread-win32.c
> +++ b/util/qemu-thread-win32.c
> @@ -22,6 +22,12 @@ typedef HRESULT (WINAPI *pSetThreadDescription) (HANDLE hThread,
>   static pSetThreadDescription SetThreadDescriptionFunc;
>   static HMODULE kernel32_module;
>   
> +static void __attribute__((__constructor__(QEMU_CONSTRUCTOR_EARLY)))
> +qemu_thread_init(void)
> +{
> +    qemu_thread_set_name("main");
> +}
> +
>   static bool load_set_thread_description(void)
>   {
>       static gsize _init_once = 0;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.