From 855e15dbf10a6aac42b860fdb28711f979e2bf22 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mattias=20Engdeg=C3=A5rd?= Date: Sat, 16 Apr 2022 11:33:14 +0200 Subject: [PATCH] Fix builds on older versions of macOS This adds back macOS-specific code replaced earlier (bug#48548), specifically to fix build errors on macOS 10.7.5. See discussion at https://lists.gnu.org/archive/html/emacs-devel/2022-04/msg00779.html . * src/sysdep.c (HAVE_RUSAGE_INFO_CURRENT, HAVE_PROC_PIDINFO): New. (system_process_attributes): Use alternative code or exclude features when building on older macOS versions. --- src/sysdep.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/sysdep.c b/src/sysdep.c index 1e630835add..f6d7d3920bd 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -4027,6 +4027,9 @@ system_process_attributes (Lisp_Object pid) #elif defined DARWIN_OS +#define HAVE_RUSAGE_INFO_CURRENT (MAC_OS_X_VERSION_MIN_REQUIRED >= 101000) +#define HAVE_PROC_PIDINFO (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050) + Lisp_Object system_process_attributes (Lisp_Object pid) { @@ -4130,6 +4133,7 @@ system_process_attributes (Lisp_Object pid) attrs = Fcons (Fcons (Qtpgid, INT_TO_INTEGER (proc.kp_eproc.e_tpgid)), attrs); +#if HAVE_RUSAGE_INFO_CURRENT rusage_info_current ri; if (proc_pid_rusage(proc_id, RUSAGE_INFO_CURRENT, (rusage_info_t *) &ri) == 0) { @@ -4143,6 +4147,24 @@ system_process_attributes (Lisp_Object pid) attrs = Fcons (Fcons (Qmajflt, INT_TO_INTEGER (ri.ri_pageins)), attrs); } +#else /* !HAVE_RUSAGE_INFO_CURRENT */ + struct rusage *rusage = proc.kp_proc.p_ru; + if (rusage) + { + attrs = Fcons (Fcons (Qminflt, INT_TO_INTEGER (rusage->ru_minflt)), + attrs); + attrs = Fcons (Fcons (Qmajflt, INT_TO_INTEGER (rusage->ru_majflt)), + attrs); + + attrs = Fcons (Fcons (Qutime, make_lisp_timeval (rusage->ru_utime)), + attrs); + attrs = Fcons (Fcons (Qstime, make_lisp_timeval (rusage->ru_stime)), + attrs); + struct timespec t = timespec_add (timeval_to_timespec (rusage->ru_utime), + timeval_to_timespec (rusage->ru_stime)); + attrs = Fcons (Fcons (Qtime, make_lisp_time (t)), attrs); + } +#endif /* !HAVE_RUSAGE_INFO_CURRENT */ starttime = proc.kp_proc.p_starttime; attrs = Fcons (Fcons (Qnice, make_fixnum (proc.kp_proc.p_nice)), attrs); @@ -4152,6 +4174,7 @@ system_process_attributes (Lisp_Object pid) t = timespec_sub (now, timeval_to_timespec (starttime)); attrs = Fcons (Fcons (Qetime, make_lisp_time (t)), attrs); +#if HAVE_PROC_PIDINFO struct proc_taskinfo taskinfo; if (proc_pidinfo (proc_id, PROC_PIDTASKINFO, 0, &taskinfo, sizeof (taskinfo)) > 0) { @@ -4159,6 +4182,7 @@ system_process_attributes (Lisp_Object pid) attrs = Fcons (Fcons (Qrss, make_fixnum (taskinfo.pti_resident_size / 1024)), attrs); attrs = Fcons (Fcons (Qthcount, make_fixnum (taskinfo.pti_threadnum)), attrs); } +#endif /* HAVE_PROC_PIDINFO */ #ifdef KERN_PROCARGS2 char args[ARG_MAX]; -- 2.39.5