From 1f2f148c89b2bbb8b0378e109ae150e069ee6bde Mon Sep 17 00:00:00 2001 From: H William Welliver <william@welliver.org> Date: Wed, 25 Nov 2020 14:43:17 -0500 Subject: [PATCH] rusage: reinitialize mach clock service after fork() on darwin --- src/rusage.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/rusage.c b/src/rusage.c index 6de7593664..15577e79d0 100644 --- a/src/rusage.c +++ b/src/rusage.c @@ -49,6 +49,7 @@ #endif #include "pike_error.h" +#include "pike_threadlib.h" /* * Here comes a long blob with stuff to see how to find out about * cpu usage. @@ -832,6 +833,12 @@ void init_rusage (void) { #ifdef HAVE_HOST_GET_CLOCK_SERVICE init_mach_clock(); + + /* mach ports are invalid across fork() so we should re-initialize + the mach clock service in the child. macOS 10.12+ enforce + this requirement + */ + th_atfork(NULL, NULL, init_mach_clock); #elif defined (MIGHT_HAVE_POSIX_REALTIME_GRT) /* Always exists according to POSIX - no need to check with sysconf. */ get_real_time_impl = posix_realtime_grt_impl; -- GitLab