From 6e3e422c2d0720452e3255e29c4e91718b843e19 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 21 Jan 2020 09:24:10 +0100 Subject: [PATCH] darwin: stop calling SetApplicationIsDaemon() It's been reported that calling this function causes the Core Graphics framework to start reporting bogus values. Commit 565cdd16 ('Revert "darwin: speed up uv_set_process_title()"') attempted to fix this but apparently merely postponed the moment when `CGDisplayPixelsWide()` and friends start reporting bogus values. The Chromium code base mentions that calling `SetApplicationIsDaemon()` prevents the HIServices framework from terminating the process when it can't connect to launchservicesd. Libuv itself doesn't use HIServices but it's possible that the libuv user does. If said user doesn't call `SetApplicationIsDaemon()`, it's possible this commit introduces an observable change in behavior. The `SetApplicationIsDaemon()` call was introduced in commit 08e0e63f ("darwin: avoid calling GetCurrentProcess") from October 2013 to work around a bug in macos 10.9 where the Activity Monitor showed the program as "Not responding." Fixes: https://github.com/libuv/libuv/issues/2566 (for real, hopefully) Fixes: https://github.com/nodejs/node/issues/31328 PR-URL: https://github.com/libuv/libuv/pull/2593 Refs: https://cs.chromium.org/chromium/src/sandbox/mac/system_services.cc?l=26&rcl=a06d2fe5a279ddecd358d919d461080e2c53c92e Reviewed-By: Colin Ihrig --- src/unix/darwin-proctitle.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/unix/darwin-proctitle.c b/src/unix/darwin-proctitle.c index 97eaa053..2daf3e34 100644 --- a/src/unix/darwin-proctitle.c +++ b/src/unix/darwin-proctitle.c @@ -72,8 +72,6 @@ int uv__set_process_title(const char* title) { CFStringRef* display_name_key; CFDictionaryRef (*pCFBundleGetInfoDictionary)(CFBundleRef); CFBundleRef (*pCFBundleGetMainBundle)(void); - CFBundleRef hi_services_bundle; - OSStatus (*pSetApplicationIsDaemon)(int); CFDictionaryRef (*pLSApplicationCheckIn)(int, CFDictionaryRef); void (*pLSSetApplicationLaunchServicesServerConnectionStatus)(uint64_t, void*); @@ -144,30 +142,19 @@ int uv__set_process_title(const char* title) { if (pCFBundleGetInfoDictionary == NULL || pCFBundleGetMainBundle == NULL) goto out; - /* Black 10.9 magic, to remove (Not responding) mark in Activity Monitor */ - hi_services_bundle = - pCFBundleGetBundleWithIdentifier(S("com.apple.HIServices")); - err = UV_ENOENT; - if (hi_services_bundle == NULL) - goto out; - - *(void **)(&pSetApplicationIsDaemon) = pCFBundleGetFunctionPointerForName( - hi_services_bundle, - S("SetApplicationIsDaemon")); *(void **)(&pLSApplicationCheckIn) = pCFBundleGetFunctionPointerForName( launch_services_bundle, S("_LSApplicationCheckIn")); + + if (pLSApplicationCheckIn == NULL) + goto out; + *(void **)(&pLSSetApplicationLaunchServicesServerConnectionStatus) = pCFBundleGetFunctionPointerForName( launch_services_bundle, S("_LSSetApplicationLaunchServicesServerConnectionStatus")); - if (pSetApplicationIsDaemon == NULL || - pLSApplicationCheckIn == NULL || - pLSSetApplicationLaunchServicesServerConnectionStatus == NULL) { - goto out; - } - if (pSetApplicationIsDaemon(1) != noErr) + if (pLSSetApplicationLaunchServicesServerConnectionStatus == NULL) goto out; pLSSetApplicationLaunchServicesServerConnectionStatus(0, NULL); @@ -178,6 +165,10 @@ int uv__set_process_title(const char* title) { asn = pLSGetCurrentApplicationASN(); + err = UV_EBUSY; + if (asn == NULL) + goto out; + err = UV_EINVAL; if (pLSSetApplicationInformationItem(-2, /* Magic value. */ asn,