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

From: [email-masked] (GNU bug Tracking System)
Date: Sun, 22 Apr 2012 03:07:02 +0000

Your bug report

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

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
5725: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=5725
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#5725: 23.1.94; list_system_processes for BSD_SYSTEM (with patch)
From: Leo <[email-masked]>
To: Chong Yidong <[email-masked]>
Cc: [email-masked]
Date: Sun, 22 Apr 2012 11:05:10 +0800
List-Id: <debbugs-submit.debbugs.gnu.org>

I pushed the commit as in revno 107988 after successfully testing it in
Snow Leopard with emacs built with X11. Thanks.

Leo

Subject: 23.1.94; list_system_processes for BSD_SYSTEM (with patch)
From: Leo <[email-masked]>
To: [email-masked]
Date: Mon, 15 Mar 2010 17:01:10 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

The included patch implements list_system_processes through sysctl.h
which I guess is available on all BSD systems. I have also implemented
process_attributes and will send it in after more testing.

diff --git a/src/sysdep.c b/src/sysdep.c
index 2f79a71..5cefc75 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -3200,6 +3200,45 @@ list_system_processes ()
   return proclist;
 }
 
+#elif defined (BSD_SYSTEM)
+#include <sys/sysctl.h>
+
+Lisp_Object
+list_system_processes ()
+{
+  struct gcpro        gcpro1;
+  Lisp_Object         proclist = Qnil;
+  struct kinfo_proc * procinfo;
+  const int name[4]            = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0};
+  size_t              length;
+  int                 err;
+  int                 i;
+  EMACS_INT           pid;
+
+  GCPRO1 (proclist);
+  err = sysctl((int *)name, 4, NULL, &length, NULL, 0);
+  if (err == 0 && length > 0)
+    {
+      procinfo = malloc (length);
+      if (procinfo != NULL)
+        {
+          err = sysctl((int *)name, 4, procinfo, &length, NULL, 0);
+          if (err == 0 && length > 0)
+            {
+              for (i=0; i < (length/sizeof(*procinfo)); i++)
+                {
+                  pid = procinfo[i].kp_proc.p_pid;
+                  proclist = Fcons (make_fixnum_or_float(pid), proclist);
+                }
+            }
+          free(procinfo);
+        }
+    }
+  UNGCPRO;
+
+  return proclist;
+}
+
 /* The WINDOWSNT implementation is in w32.c.
    The MSDOS implementation is in dosfns.c.  */
 #elif !defined (WINDOWSNT) && !defined (MSDOS)

Leo