Skip to content

Commit

Permalink
Merge pull request #3963 from BOINC/mac_screensaver_fixes_for_MacOS_1…
Browse files Browse the repository at this point in the history
…1_Big_Sur

Mac: FIx screensaver coordinator to run properly under Mac OS 11 Big Sur
  • Loading branch information
davidpanderson authored Aug 7, 2020
2 parents 01a9853 + 3e18fc3 commit 4fc5f7c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
26 changes: 23 additions & 3 deletions clientscr/gfx_switcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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 VERBOSE // For debugging only
print_to_log_file("MonitorScreenSaverEngine: ScreenSaverEngine_Pid=%d", ScreenSaverEngine_Pid);
#endif
if (ScreenSaverEngine_Pid == 0) {
kill(graphics_Pid, SIGKILL);
#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);
print_to_log_file("MonitorScreenSaverEngine calling kill(%d, SIGKILL", graphics_Pid);
#endif
return 0;
}
Expand Down
13 changes: 13 additions & 0 deletions clientscr/screensaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#endif

#ifdef __APPLE__
#define VERBOSE 0

#include <Carbon/Carbon.h>
#include <sys/wait.h>
#include <app_ipc.h>
Expand All @@ -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)
Expand Down

0 comments on commit 4fc5f7c

Please sign in to comment.