Subject: bug#5725: 23.1.94; list_system_processes for BSD_SYSTEM (with patch)

From: Leo <[email-masked]>
Date: Sat, 21 Apr 2012 23:29:09 +0800

On 2012-04-21 18:24 +0800, Chong Yidong wrote:
> [Disconnecting Bug#5725 from Bug#5243]
>
> I committed Eduard Wiebe's patch in Bug#5243 to trunk.  If his
> implementation of system_process_attributes does not compile on Darwin,
> and you have a separate one that works, could you add yours under a
> different #elif?
>
> Also, if the list_system_processes part works on Darwin, the relevant
> #elif, from his patch, should be changed to BSD_SYSTEM; please check
> that if you can, and amend as necessary.
>
> Thanks.

The difference is small. Are you happy with this change? I have tested
it in Snow Leopard 10.6.8.

=== modified file 'src/sysdep.c'
--- src/sysdep.c	2012-04-21 10:11:51 +0000
+++ src/sysdep.c	2012-04-21 15:25:18 +0000
@@ -44,6 +44,10 @@
 #include <math.h>
 #endif
 
+#ifdef DARWIN_OS
+#include <sys/sysctl.h>
+#endif
+
 #ifdef WINDOWSNT
 #define read sys_read
 #define write sys_write
@@ -2536,7 +2540,11 @@
   return proclist;
 }
 
-#elif defined (__FreeBSD__)
+#elif defined (BSD_SYSTEM)
+
+#ifdef DARWIN_OS
+#define KERN_PROC_PROC KERN_PROC_ALL
+#endif
 
 Lisp_Object
 list_system_processes ()
@@ -2562,7 +2570,13 @@
   GCPRO1 (proclist);
   len /= sizeof (struct kinfo_proc);
   for (i = 0; i < len; i++)
-    proclist = Fcons (make_fixnum_or_float (procs[i].ki_pid), proclist);
+    {
+#ifdef DARWIN_OS
+      proclist = Fcons (make_fixnum_or_float (procs[i].kp_proc.p_pid), proclist);
+#else
+      proclist = Fcons (make_fixnum_or_float (procs[i].ki_pid), proclist);
+#endif
+    }
   UNGCPRO;
   
   xfree (procs);