From e7e3690db4874fabfc6c2805ad5baa944e156517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Arboleda?= Date: Fri, 5 Sep 2025 09:44:23 -0500 Subject: [PATCH] darwin: remove process title setting via LaunchServices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Chromium removed the same functionality because it could trigger “Application Not Responding” notifications for child processes and was never supported by Apple. Refs: * https://codereview.chromium.org/45253002 * https://issues.chromium.org/issues/41063805 Fixes: https://github.com/nodejs/node/issues/59678 Signed-off-by: Juan José Arboleda --- src/unix/darwin-proctitle.c | 152 +----------------------------------- src/unix/proctitle.c | 3 + src/win/util.c | 3 + test/test-process-title.c | 11 ++- 4 files changed, 19 insertions(+), 150 deletions(-) diff --git a/src/unix/darwin-proctitle.c b/src/unix/darwin-proctitle.c index 5e5642972..265443001 100644 --- a/src/unix/darwin-proctitle.c +++ b/src/unix/darwin-proctitle.c @@ -21,156 +21,10 @@ #include "uv.h" #include "internal.h" -#include -#include -#include -#include -#include - -#include - -#if !TARGET_OS_IPHONE -#include "darwin-stub.h" -#endif +#include int uv__set_process_title(const char* title) { -#if TARGET_OS_IPHONE + assert(title != NULL && *title != '\0'); + return uv__thread_setname(title); -#else - CFStringRef (*pCFStringCreateWithCString)(CFAllocatorRef, - const char*, - CFStringEncoding); - CFBundleRef (*pCFBundleGetBundleWithIdentifier)(CFStringRef); - void *(*pCFBundleGetDataPointerForName)(CFBundleRef, CFStringRef); - void *(*pCFBundleGetFunctionPointerForName)(CFBundleRef, CFStringRef); - CFTypeRef (*pLSGetCurrentApplicationASN)(void); - OSStatus (*pLSSetApplicationInformationItem)(int, - CFTypeRef, - CFStringRef, - CFStringRef, - CFDictionaryRef*); - void* application_services_handle; - void* core_foundation_handle; - CFBundleRef launch_services_bundle; - CFStringRef* display_name_key; - CFDictionaryRef (*pCFBundleGetInfoDictionary)(CFBundleRef); - CFBundleRef (*pCFBundleGetMainBundle)(void); - CFDictionaryRef (*pLSApplicationCheckIn)(int, CFDictionaryRef); - void (*pLSSetApplicationLaunchServicesServerConnectionStatus)(uint64_t, - void*); - CFTypeRef asn; - int err; - - err = UV_ENOENT; - application_services_handle = dlopen("/System/Library/Frameworks/" - "ApplicationServices.framework/" - "Versions/A/ApplicationServices", - RTLD_LAZY | RTLD_LOCAL); - core_foundation_handle = dlopen("/System/Library/Frameworks/" - "CoreFoundation.framework/" - "Versions/A/CoreFoundation", - RTLD_LAZY | RTLD_LOCAL); - - if (application_services_handle == NULL || core_foundation_handle == NULL) - goto out; - - *(void **)(&pCFStringCreateWithCString) = - dlsym(core_foundation_handle, "CFStringCreateWithCString"); - *(void **)(&pCFBundleGetBundleWithIdentifier) = - dlsym(core_foundation_handle, "CFBundleGetBundleWithIdentifier"); - *(void **)(&pCFBundleGetDataPointerForName) = - dlsym(core_foundation_handle, "CFBundleGetDataPointerForName"); - *(void **)(&pCFBundleGetFunctionPointerForName) = - dlsym(core_foundation_handle, "CFBundleGetFunctionPointerForName"); - - if (pCFStringCreateWithCString == NULL || - pCFBundleGetBundleWithIdentifier == NULL || - pCFBundleGetDataPointerForName == NULL || - pCFBundleGetFunctionPointerForName == NULL) { - goto out; - } - -#define S(s) pCFStringCreateWithCString(NULL, (s), kCFStringEncodingUTF8) - - launch_services_bundle = - pCFBundleGetBundleWithIdentifier(S("com.apple.LaunchServices")); - - if (launch_services_bundle == NULL) - goto out; - - *(void **)(&pLSGetCurrentApplicationASN) = - pCFBundleGetFunctionPointerForName(launch_services_bundle, - S("_LSGetCurrentApplicationASN")); - - if (pLSGetCurrentApplicationASN == NULL) - goto out; - - *(void **)(&pLSSetApplicationInformationItem) = - pCFBundleGetFunctionPointerForName(launch_services_bundle, - S("_LSSetApplicationInformationItem")); - - if (pLSSetApplicationInformationItem == NULL) - goto out; - - display_name_key = pCFBundleGetDataPointerForName(launch_services_bundle, - S("_kLSDisplayNameKey")); - - if (display_name_key == NULL || *display_name_key == NULL) - goto out; - - *(void **)(&pCFBundleGetInfoDictionary) = dlsym(core_foundation_handle, - "CFBundleGetInfoDictionary"); - *(void **)(&pCFBundleGetMainBundle) = dlsym(core_foundation_handle, - "CFBundleGetMainBundle"); - if (pCFBundleGetInfoDictionary == NULL || pCFBundleGetMainBundle == NULL) - goto out; - - *(void **)(&pLSApplicationCheckIn) = pCFBundleGetFunctionPointerForName( - launch_services_bundle, - S("_LSApplicationCheckIn")); - - if (pLSApplicationCheckIn == NULL) - goto out; - - *(void **)(&pLSSetApplicationLaunchServicesServerConnectionStatus) = - pCFBundleGetFunctionPointerForName( - launch_services_bundle, - S("_LSSetApplicationLaunchServicesServerConnectionStatus")); - - if (pLSSetApplicationLaunchServicesServerConnectionStatus == NULL) - goto out; - - pLSSetApplicationLaunchServicesServerConnectionStatus(0, NULL); - - /* Check into process manager?! */ - pLSApplicationCheckIn(-2, - pCFBundleGetInfoDictionary(pCFBundleGetMainBundle())); - - asn = pLSGetCurrentApplicationASN(); - - err = UV_EBUSY; - if (asn == NULL) - goto out; - - err = UV_EINVAL; - if (pLSSetApplicationInformationItem(-2, /* Magic value. */ - asn, - *display_name_key, - S(title), - NULL) != noErr) { - goto out; - } - - uv__thread_setname(title); /* Don't care if it fails. */ - err = 0; - -out: - if (core_foundation_handle != NULL) - dlclose(core_foundation_handle); - - if (application_services_handle != NULL) - dlclose(application_services_handle); - - return err; -#endif /* !TARGET_OS_IPHONE */ } diff --git a/src/unix/proctitle.c b/src/unix/proctitle.c index 9d1f00ddf..5988cd928 100644 --- a/src/unix/proctitle.c +++ b/src/unix/proctitle.c @@ -97,6 +97,9 @@ int uv_set_process_title(const char* title) { struct uv__process_title* pt; size_t len; + if (title == NULL || *title == '\0') + return UV_EINVAL; + /* If uv_setup_args wasn't called or failed, we can't continue. */ if (args_mem == NULL) return UV_ENOBUFS; diff --git a/src/win/util.c b/src/win/util.c index 9fb5694c9..7b6263dff 100644 --- a/src/win/util.c +++ b/src/win/util.c @@ -346,6 +346,9 @@ int uv_set_process_title(const char* title) { int length; WCHAR* title_w = NULL; + if (title == NULL || title[0] == '\0') + return UV_EINVAL; + uv__once_init(); err = uv__convert_utf8_to_utf16(title, &title_w); diff --git a/test/test-process-title.c b/test/test-process-title.c index 3478033a9..727c13efe 100644 --- a/test/test-process-title.c +++ b/test/test-process-title.c @@ -41,6 +41,14 @@ static void set_title(const char* title) { } +static void uv_set_process_title_edge_cases(void) { + /* Test a NULL buffer */ + ASSERT_EQ(uv_set_process_title(NULL), UV_EINVAL); + /* Test an empty string */ + ASSERT_EQ(uv_set_process_title("\0"), UV_EINVAL); + +} + static void uv_get_process_title_edge_cases(void) { char buffer[512]; int r; @@ -69,8 +77,9 @@ TEST_IMPL(process_title) { set_title("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s"); set_title("new title"); - /* Check uv_get_process_title() edge cases */ + /* Check uv_get|set_process_title() edge cases */ uv_get_process_title_edge_cases(); + uv_set_process_title_edge_cases(); return 0; }