From 3e18fc3b205966c02459bd50f404e2b03152dad6 Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Thu, 6 Aug 2020 04:48:19 -0700 Subject: [PATCH] Mac: FIx screensaver coordinator to run properly under Mac OS 11 Big Sur --- clientscr/gfx_switcher.cpp | 28 ++++++++++++++++++++++++---- clientscr/screensaver.cpp | 13 +++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/clientscr/gfx_switcher.cpp b/clientscr/gfx_switcher.cpp index 6f9343e0a0..2c34494f3b 100644 --- a/clientscr/gfx_switcher.cpp +++ b/clientscr/gfx_switcher.cpp @@ -173,7 +173,7 @@ int main(int argc, char** argv) { return errno; } else { // if screensaverLoginUser #if VERBOSE // For debugging only - print_to_log_file("gfx_switcher using fork()");; + print_to_log_file("gfx_switcher using fork()"); #endif int pid = fork(); if (pid == 0) { @@ -182,10 +182,16 @@ int main(int argc, char** argv) { // full path twice in the argument list to execv. execv(resolved_path, argv+2); // If we got here execv failed +#if VERBOSE // For debugging only + print_to_log_file("gfx_switcher: Process creation (%s) failed: errno=%d\n", resolved_path, errno); +#endif fprintf(stderr, "Process creation (%s) failed: errno=%d\n", resolved_path, errno); return errno; } else { char shmem_name[MAXPATHLEN]; +#if VERBOSE // For debugging only + print_to_log_file("gfx_switcher: Child PID=%d", pid); +#endif snprintf(shmem_name, sizeof(shmem_name), "/tmp/boinc_ss_%s", screensaverLoginUser); retval = attach_shmem_mmap(shmem_name, (void**)&pid_for_shmem); if (pid_for_shmem != 0) { @@ -280,10 +286,24 @@ void * MonitorScreenSaverEngine(void* param) { while (true) { boinc_sleep(1.0); // Test every second ScreenSaverEngine_Pid = getPidIfRunning("com.apple.ScreenSaver.Engine"); - if (ScreenSaverEngine_Pid == 0) { - kill(graphics_Pid, SIGKILL); #if VERBOSE // For debugging only - print_to_log_file("MonitorScreenSaverEngine calling kill(%d, SIGKILL", graphics_Pid); + print_to_log_file("MonitorScreenSaverEngine: ScreenSaverEngine_Pid=%d", ScreenSaverEngine_Pid); +#endif + if (ScreenSaverEngine_Pid == 0) { +#ifdef __x86_64__ + ScreenSaverEngine_Pid = getPidIfRunning("com.apple.ScreenSaver.Engine.legacyScreenSaver.x86_64"); +#elif defined(__arm64__) + ScreenSaverEngine_Pid = getPidIfRunning("com.apple.ScreenSaver.Engine.legacyScreenSaver.arm64"); +#endif +#if VERBOSE // For debugging only + print_to_log_file("MonitorScreenSaverEngine: ScreenSaverEngine_legacyScreenSaver_Pid=%d", ScreenSaverEngine_Pid); +#endif + } + + if (ScreenSaverEngine_Pid == 0) { + kill(graphics_Pid, SIGKILL); +#if VERBOSE // For debugging only + print_to_log_file("MonitorScreenSaverEngine calling kill(%d, SIGKILL", graphics_Pid); #endif return 0; } diff --git a/clientscr/screensaver.cpp b/clientscr/screensaver.cpp index 2a79f93049..aa3cff9fb5 100644 --- a/clientscr/screensaver.cpp +++ b/clientscr/screensaver.cpp @@ -26,6 +26,8 @@ #endif #ifdef __APPLE__ +#define VERBOSE 0 + #include #include #include @@ -49,6 +51,17 @@ extern pthread_mutex_t saver_mutex; #include "str_replace.h" #include "screensaver.h" +#ifdef __APPLE__ +#undef BOINCTRACE +#if VERBOSE +#define BOINCTRACE print_to_log_file +#else +#define BOINCTRACE(...) +#endif + +#define _T +#endif + // Platform specific application includes // #if defined(_WIN32)