From 7fe60600b4ab2497b53a7ea02e18b8685f6e2db7 Mon Sep 17 00:00:00 2001 From: tmds Date: Wed, 6 May 2020 18:28:23 +0000 Subject: [PATCH] Ensure Process.ProcessName doesn't change when setting Thread.Name on Linux Fixes https://github.com/dotnet/runtime/issues/33673 This issue is a side-effect of adding support for setting thread names on Linux in https://github.com/dotnet/coreclr/pull/27182. cc @janvorli @lpereira @SteveL-MSFT --- mono/utils/mono-threads-posix.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mono/utils/mono-threads-posix.c b/mono/utils/mono-threads-posix.c index 33afc458a792..f8f21ca67700 100644 --- a/mono/utils/mono-threads-posix.c +++ b/mono/utils/mono-threads-posix.c @@ -282,6 +282,15 @@ mono_native_thread_set_name (MonoNativeThreadId tid, const char *name) if (tid != mono_native_thread_id_get ()) return; +#if defined(__linux__) + /* + * Ignore requests to set the main thread name because + * it causes the value returned by Process.ProcessName to change. + */ + if (mono_native_thread_os_id_get () == (guint64)getpid ()) + return; +#endif + if (!name) { pthread_setname_np (""); } else {