GNU bug report logs - #16579
24.3.50; Implement system_process_attributes on Darwin

Previous Next

Package: emacs;

Reported by: Magnus Henoch <magnus.henoch <at> gmail.com>

Date: Tue, 28 Jan 2014 18:20:01 UTC

Severity: wishlist

Tags: fixed, patch

Found in version 24.3.50

Fixed in version 26.1

Done: Lars Magne Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 16579 in the body.
You can then email your comments to 16579 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#16579; Package emacs. (Tue, 28 Jan 2014 18:20:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Magnus Henoch <magnus.henoch <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 28 Jan 2014 18:20:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Magnus Henoch <magnus.henoch <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3.50; Implement system_process_attributes on Darwin
Date: Tue, 28 Jan 2014 18:19:22 +0000
[Message part 1 (text/plain, inline)]
Severity: wishlist
Tags: patch

The attached patch implements system_process_attributes on Darwin / Mac
OSX, and thus makes Proced show a list of processes on such systems.

The code is shared with FreeBSD, just like in list_system_processes,
though the differences between the two systems are so numerous that I'm
not sure if it's better this way or having a separate function for
Darwin.

This patch just "picks the low-hanging fruit", using the data that is
available in the kinfo_proc struct in a similar format to FreeBSD's.
Thus there are many things missing, in particular memory and CPU usage,
and command line arguments.  For the latter, you're apparently supposed
to use the undocumented KERN_PROCARGS and KERN_PROCARGS2 sysctls, but I
couldn't figure out how to get non-garbage from the result.

I haven't verified that this code still works on FreeBSD.

Regards,
Magnus

In GNU Emacs 24.3.50.15 (i386-apple-darwin12.5.0, NS apple-appkit-1187.40)
 of 2014-01-27 on poki-sona.local
Repository revision: 
Windowing system distributor `Apple', version 10.3.1187
Configured using:
 `configure --with-ns --without-rsvg --without-gsettings
 --without-file-notification'

[Message part 2 (text/x-patch, inline)]
diff --git a/src/sysdep.c b/src/sysdep.c
index 6ec8eec..78e23a0 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -3238,7 +3238,7 @@ system_process_attributes (Lisp_Object pid)
   return attrs;
 }
 
-#elif defined __FreeBSD__
+#elif defined __FreeBSD__ || defined DARWIN_OS
 
 static struct timespec
 timeval_to_timespec (struct timeval t)
@@ -3264,7 +3264,12 @@ system_process_attributes (Lisp_Object pid)
   char *ttyname;
   size_t len;
   char args[MAXPATHLEN];
+  struct timeval starttime;
   struct timespec t, now;
+  struct rusage *rusage;
+  dev_t tdev;
+  uid_t uid;
+  gid_t gid;
 
   int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID};
   struct kinfo_proc proc;
@@ -3283,30 +3288,52 @@ system_process_attributes (Lisp_Object pid)
 
   GCPRO2 (attrs, decoded_comm);
 
-  attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (proc.ki_uid)), attrs);
+#ifdef DARWIN_OS
+  uid = proc.kp_eproc.e_ucred.cr_uid;
+#else
+  uid = proc.ki_uid;
+#endif
+  attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid)), attrs);
 
   block_input ();
-  pw = getpwuid (proc.ki_uid);
+  pw = getpwuid (uid);
   unblock_input ();
   if (pw)
     attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs);
 
-  attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (proc.ki_svgid)), attrs);
+#ifdef DARWIN_OS
+  gid = proc.kp_eproc.e_pcred.p_svgid;
+#else
+  gid = proc.ki_svgid;
+#endif
+  attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid)), attrs);
 
   block_input ();
-  gr = getgrgid (proc.ki_svgid);
+  gr = getgrgid (gid);
   unblock_input ();
   if (gr)
     attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs);
 
+#ifdef DARWIN_OS
+  decoded_comm = (code_convert_string_norecord
+		  (build_unibyte_string (proc.kp_proc.p_comm),
+		   Vlocale_coding_system, 0));
+#else
   decoded_comm = (code_convert_string_norecord
 		  (build_unibyte_string (proc.ki_comm),
 		   Vlocale_coding_system, 0));
+#endif
 
   attrs = Fcons (Fcons (Qcomm, decoded_comm), attrs);
   {
     char state[2] = {'\0', '\0'};
-    switch (proc.ki_stat)
+    char stat;
+#ifdef DARWIN_OS
+    stat = proc.kp_proc.p_stat;
+#else
+    stat = proc.ki_stat;
+#endif
+    switch (stat)
       {
       case SRUN:
 	state[0] = 'R';
@@ -3316,9 +3343,11 @@ system_process_attributes (Lisp_Object pid)
 	state[0] = 'S';
 	break;
 
+#ifdef SLOCK
       case SLOCK:
 	state[0] = 'D';
 	break;
+#endif
 
       case SZOMB:
 	state[0] = 'Z';
@@ -3327,34 +3356,66 @@ system_process_attributes (Lisp_Object pid)
       case SSTOP:
 	state[0] = 'T';
 	break;
+
+#ifdef SIDL
+      case SIDL:
+	state[0] = 'I';
+	break;
+#endif
       }
     attrs = Fcons (Fcons (Qstate, build_string (state)), attrs);
   }
 
+#ifdef DARWIN_OS
+  attrs = Fcons (Fcons (Qppid, make_fixnum_or_float (proc.kp_eproc.e_ppid)), attrs);
+  attrs = Fcons (Fcons (Qpgrp, make_fixnum_or_float (proc.kp_eproc.e_pgid)), attrs);
+#else
   attrs = Fcons (Fcons (Qppid, make_fixnum_or_float (proc.ki_ppid)), attrs);
   attrs = Fcons (Fcons (Qpgrp, make_fixnum_or_float (proc.ki_pgid)), attrs);
   attrs = Fcons (Fcons (Qsess, make_fixnum_or_float (proc.ki_sid)),  attrs);
+#endif
 
+#ifdef DARWIN_OS
+  tdev = proc.kp_eproc.e_tdev;
+#else
+  tdev = proc.ki_tdev;
+#endif
   block_input ();
-  ttyname = proc.ki_tdev == NODEV ? NULL : devname (proc.ki_tdev, S_IFCHR);
+  ttyname = tdev == NODEV ? NULL : devname (tdev, S_IFCHR);
   unblock_input ();
   if (ttyname)
     attrs = Fcons (Fcons (Qtty, build_string (ttyname)), attrs);
 
+#ifdef DARWIN_OS
+  attrs = Fcons (Fcons (Qtpgid,   make_fixnum_or_float (proc.kp_eproc.e_tpgid)), attrs);
+#else
   attrs = Fcons (Fcons (Qtpgid,   make_fixnum_or_float (proc.ki_tpgid)), attrs);
-  attrs = Fcons (Fcons (Qminflt,  make_fixnum_or_float (proc.ki_rusage.ru_minflt)), attrs);
-  attrs = Fcons (Fcons (Qmajflt,  make_fixnum_or_float (proc.ki_rusage.ru_majflt)), attrs);
+#endif
+
+#ifdef DARWIN_OS
+  rusage = proc.kp_proc.p_ru;
+#else
+  rusage = &proc.ki_rusage;
+#endif
+  if (rusage)
+    {
+      attrs = Fcons (Fcons (Qminflt,  make_fixnum_or_float (rusage->ru_minflt)), attrs);
+      attrs = Fcons (Fcons (Qmajflt,  make_fixnum_or_float (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);
+      t = timespec_add (timeval_to_timespec (rusage->ru_utime),
+			timeval_to_timespec (rusage->ru_stime));
+      attrs = Fcons (Fcons (Qtime, make_lisp_time (t)), attrs);
+    }
+#ifndef DARWIN_OS
   attrs = Fcons (Fcons (Qcminflt, make_number (proc.ki_rusage_ch.ru_minflt)), attrs);
   attrs = Fcons (Fcons (Qcmajflt, make_number (proc.ki_rusage_ch.ru_majflt)), attrs);
+#endif
 
-  attrs = Fcons (Fcons (Qutime, make_lisp_timeval (proc.ki_rusage.ru_utime)),
-		 attrs);
-  attrs = Fcons (Fcons (Qstime, make_lisp_timeval (proc.ki_rusage.ru_stime)),
-		 attrs);
-  t = timespec_add (timeval_to_timespec (proc.ki_rusage.ru_utime),
-		    timeval_to_timespec (proc.ki_rusage.ru_stime));
-  attrs = Fcons (Fcons (Qtime, make_lisp_time (t)), attrs);
-
+#ifndef DARWIN_OS
   attrs = Fcons (Fcons (Qcutime,
 			make_lisp_timeval (proc.ki_rusage_ch.ru_utime)),
 		 attrs);
@@ -3368,16 +3429,24 @@ system_process_attributes (Lisp_Object pid)
   attrs = Fcons (Fcons (Qthcount, make_fixnum_or_float (proc.ki_numthreads)),
 		 attrs);
   attrs = Fcons (Fcons (Qpri,   make_number (proc.ki_pri.pri_native)), attrs);
+#endif
+#ifdef DARWIN_OS
+  starttime = proc.kp_proc.p_starttime;
+  attrs = Fcons (Fcons (Qnice,  make_number (proc.kp_proc.p_nice)), attrs);
+#else
+  starttime = proc.ki_start;
   attrs = Fcons (Fcons (Qnice,  make_number (proc.ki_nice)), attrs);
-  attrs = Fcons (Fcons (Qstart, make_lisp_timeval (proc.ki_start)), attrs);
   attrs = Fcons (Fcons (Qvsize, make_number (proc.ki_size >> 10)), attrs);
   attrs = Fcons (Fcons (Qrss,   make_number (proc.ki_rssize * pagesize >> 10)),
 		 attrs);
+#endif
+  attrs = Fcons (Fcons (Qstart, make_lisp_timeval (starttime)), attrs);
 
   now = current_timespec ();
-  t = timespec_sub (now, timeval_to_timespec (proc.ki_start));
+  t = timespec_sub (now, timeval_to_timespec (starttime));
   attrs = Fcons (Fcons (Qetime, make_lisp_time (t)), attrs);
 
+#ifndef DARWIN_OS
   len = sizeof fscale;
   if (sysctlbyname ("kern.fscale", &fscale, &len, NULL, 0) == 0)
     {
@@ -3419,6 +3488,7 @@ system_process_attributes (Lisp_Object pid)
 
       attrs = Fcons (Fcons (Qargs, decoded_comm), attrs);
     }
+#endif
 
   UNGCPRO;
   return attrs;

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16579; Package emacs. (Mon, 16 Nov 2015 22:40:02 GMT) Full text and rfc822 format available.

Message #8 received at 16579 <at> debbugs.gnu.org (full text, mbox):

From: Magnus Henoch <magnus.henoch <at> gmail.com>
To: 16579 <at> debbugs.gnu.org
Subject: Nicer patch
Date: Mon, 16 Nov 2015 22:39:19 +0000
[Message part 1 (text/plain, inline)]
So I had another look at this, and realised that the patch looks 
pretty ugly, being all interleaved with the FreeBSD code... 
Here's another patch, that just adds a new section for Darwin.  I 
feel much better about it now.

Any thoughts or objections?

Regards,
Magnus
[0001-Implement-process-attributes-for-Darwin.patch (text/x-patch, inline)]
From 6ab30d39b18027e141000446561d7a211776c681 Mon Sep 17 00:00:00 2001
From: Magnus Henoch <magnus.henoch <at> gmail.com>
Date: Sun, 15 Nov 2015 02:05:00 +0000
Subject: [PATCH] Implement process-attributes for Darwin

Mostly copied from the FreeBSD implementation, but it's different enough
to warrant a separate preprocessor if clause.
---
 src/sysdep.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 139 insertions(+)

diff --git a/src/sysdep.c b/src/sysdep.c
index 91036f0..f2b2b16 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -3512,6 +3512,145 @@ system_process_attributes (Lisp_Object pid)
   return attrs;
 }
 
+#elif defined DARWIN_OS
+
+static struct timespec
+timeval_to_timespec (struct timeval t)
+{
+  return make_timespec (t.tv_sec, t.tv_usec * 1000);
+}
+
+static Lisp_Object
+make_lisp_timeval (struct timeval t)
+{
+  return make_lisp_time (timeval_to_timespec (t));
+}
+
+Lisp_Object
+system_process_attributes (Lisp_Object pid)
+{
+  int proc_id;
+  int pagesize = getpagesize ();
+  unsigned long npages;
+  int fscale;
+  struct passwd *pw;
+  struct group  *gr;
+  char *ttyname;
+  size_t len;
+  char args[MAXPATHLEN];
+  struct timeval starttime;
+  struct timespec t, now;
+  struct rusage *rusage;
+  dev_t tdev;
+  uid_t uid;
+  gid_t gid;
+
+  int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID};
+  struct kinfo_proc proc;
+  size_t proclen = sizeof proc;
+
+  struct gcpro gcpro1, gcpro2;
+  Lisp_Object attrs = Qnil;
+  Lisp_Object decoded_comm;
+
+  CHECK_NUMBER_OR_FLOAT (pid);
+  CONS_TO_INTEGER (pid, int, proc_id);
+  mib[3] = proc_id;
+
+  if (sysctl (mib, 4, &proc, &proclen, NULL, 0) != 0)
+    return attrs;
+
+  GCPRO2 (attrs, decoded_comm);
+
+  uid = proc.kp_eproc.e_ucred.cr_uid;
+  attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid)), attrs);
+
+  block_input ();
+  pw = getpwuid (uid);
+  unblock_input ();
+  if (pw)
+    attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs);
+
+  gid = proc.kp_eproc.e_pcred.p_svgid;
+  attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid)), attrs);
+
+  block_input ();
+  gr = getgrgid (gid);
+  unblock_input ();
+  if (gr)
+    attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs);
+
+  decoded_comm = (code_convert_string_norecord
+		  (build_unibyte_string (proc.kp_proc.p_comm),
+		   Vlocale_coding_system, 0));
+
+  attrs = Fcons (Fcons (Qcomm, decoded_comm), attrs);
+  {
+    char state[2] = {'\0', '\0'};
+    switch (proc.kp_proc.p_stat)
+      {
+      case SRUN:
+	state[0] = 'R';
+	break;
+
+      case SSLEEP:
+	state[0] = 'S';
+	break;
+
+      case SZOMB:
+	state[0] = 'Z';
+	break;
+
+      case SSTOP:
+	state[0] = 'T';
+	break;
+
+      case SIDL:
+	state[0] = 'I';
+	break;
+      }
+    attrs = Fcons (Fcons (Qstate, build_string (state)), attrs);
+  }
+
+  attrs = Fcons (Fcons (Qppid, make_fixnum_or_float (proc.kp_eproc.e_ppid)), attrs);
+  attrs = Fcons (Fcons (Qpgrp, make_fixnum_or_float (proc.kp_eproc.e_pgid)), attrs);
+
+  tdev = proc.kp_eproc.e_tdev;
+  block_input ();
+  ttyname = tdev == NODEV ? NULL : devname (tdev, S_IFCHR);
+  unblock_input ();
+  if (ttyname)
+    attrs = Fcons (Fcons (Qtty, build_string (ttyname)), attrs);
+
+  attrs = Fcons (Fcons (Qtpgid,   make_fixnum_or_float (proc.kp_eproc.e_tpgid)), attrs);
+
+  rusage = proc.kp_proc.p_ru;
+  if (rusage)
+    {
+      attrs = Fcons (Fcons (Qminflt,  make_fixnum_or_float (rusage->ru_minflt)), attrs);
+      attrs = Fcons (Fcons (Qmajflt,  make_fixnum_or_float (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);
+      t = timespec_add (timeval_to_timespec (rusage->ru_utime),
+			timeval_to_timespec (rusage->ru_stime));
+      attrs = Fcons (Fcons (Qtime, make_lisp_time (t)), attrs);
+    }
+
+  starttime = proc.kp_proc.p_starttime;
+  attrs = Fcons (Fcons (Qnice,  make_number (proc.kp_proc.p_nice)), attrs);
+  attrs = Fcons (Fcons (Qstart, make_lisp_timeval (starttime)), attrs);
+
+  now = current_timespec ();
+  t = timespec_sub (now, timeval_to_timespec (starttime));
+  attrs = Fcons (Fcons (Qetime, make_lisp_time (t)), attrs);
+
+  UNGCPRO;
+  return attrs;
+}
+
 /* The WINDOWSNT implementation is in w32.c.
    The MSDOS implementation is in dosfns.c.  */
 #elif !defined (WINDOWSNT) && !defined (MSDOS)
-- 
2.2.1


Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16579; Package emacs. (Tue, 17 Nov 2015 04:08:01 GMT) Full text and rfc822 format available.

Message #11 received at 16579 <at> debbugs.gnu.org (full text, mbox):

From: Ivan Andrus <darthandrus <at> gmail.com>
To: Magnus Henoch <magnus.henoch <at> gmail.com>
Cc: 16579 <at> debbugs.gnu.org
Subject: Re: bug#16579: Nicer patch
Date: Mon, 16 Nov 2015 21:07:12 -0700
I’ve been using your previous patch for a while and I think it would be great to have this feature in.  I’m a very casual contributor, so I can’t say go ahead, but I think it would be great to have.  I haven’t found any problems with it (though I don’t use proced all that often—partly because it never worked until I found this patch).

-Ivan

> On Nov 16, 2015, at 3:39 PM, Magnus Henoch <magnus.henoch <at> gmail.com> wrote:
> 
> So I had another look at this, and realised that the patch looks pretty ugly, being all interleaved with the FreeBSD code... Here's another patch, that just adds a new section for Darwin.  I feel much better about it now.
> 
> Any thoughts or objections?
> 
> Regards,
> Magnus
> From 6ab30d39b18027e141000446561d7a211776c681 Mon Sep 17 00:00:00 2001
> From: Magnus Henoch <magnus.henoch <at> gmail.com>
> Date: Sun, 15 Nov 2015 02:05:00 +0000
> Subject: [PATCH] Implement process-attributes for Darwin
> 
> Mostly copied from the FreeBSD implementation, but it's different enough
> to warrant a separate preprocessor if clause.
> ---
> src/sysdep.c | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 139 insertions(+)
> 
> diff --git a/src/sysdep.c b/src/sysdep.c
> index 91036f0..f2b2b16 100644
> --- a/src/sysdep.c
> +++ b/src/sysdep.c
> @@ -3512,6 +3512,145 @@ system_process_attributes (Lisp_Object pid)
>   return attrs;
> }
> 
> +#elif defined DARWIN_OS
> +
> +static struct timespec
> +timeval_to_timespec (struct timeval t)
> +{
> +  return make_timespec (t.tv_sec, t.tv_usec * 1000);
> +}
> +
> +static Lisp_Object
> +make_lisp_timeval (struct timeval t)
> +{
> +  return make_lisp_time (timeval_to_timespec (t));
> +}
> +
> +Lisp_Object
> +system_process_attributes (Lisp_Object pid)
> +{
> +  int proc_id;
> +  int pagesize = getpagesize ();
> +  unsigned long npages;
> +  int fscale;
> +  struct passwd *pw;
> +  struct group  *gr;
> +  char *ttyname;
> +  size_t len;
> +  char args[MAXPATHLEN];
> +  struct timeval starttime;
> +  struct timespec t, now;
> +  struct rusage *rusage;
> +  dev_t tdev;
> +  uid_t uid;
> +  gid_t gid;
> +
> +  int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID};
> +  struct kinfo_proc proc;
> +  size_t proclen = sizeof proc;
> +
> +  struct gcpro gcpro1, gcpro2;
> +  Lisp_Object attrs = Qnil;
> +  Lisp_Object decoded_comm;
> +
> +  CHECK_NUMBER_OR_FLOAT (pid);
> +  CONS_TO_INTEGER (pid, int, proc_id);
> +  mib[3] = proc_id;
> +
> +  if (sysctl (mib, 4, &proc, &proclen, NULL, 0) != 0)
> +    return attrs;
> +
> +  GCPRO2 (attrs, decoded_comm);
> +
> +  uid = proc.kp_eproc.e_ucred.cr_uid;
> +  attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid)), attrs);
> +
> +  block_input ();
> +  pw = getpwuid (uid);
> +  unblock_input ();
> +  if (pw)
> +    attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs);
> +
> +  gid = proc.kp_eproc.e_pcred.p_svgid;
> +  attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid)), attrs);
> +
> +  block_input ();
> +  gr = getgrgid (gid);
> +  unblock_input ();
> +  if (gr)
> +    attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs);
> +
> +  decoded_comm = (code_convert_string_norecord
> +		  (build_unibyte_string (proc.kp_proc.p_comm),
> +		   Vlocale_coding_system, 0));
> +
> +  attrs = Fcons (Fcons (Qcomm, decoded_comm), attrs);
> +  {
> +    char state[2] = {'\0', '\0'};
> +    switch (proc.kp_proc.p_stat)
> +      {
> +      case SRUN:
> +	state[0] = 'R';
> +	break;
> +
> +      case SSLEEP:
> +	state[0] = 'S';
> +	break;
> +
> +      case SZOMB:
> +	state[0] = 'Z';
> +	break;
> +
> +      case SSTOP:
> +	state[0] = 'T';
> +	break;
> +
> +      case SIDL:
> +	state[0] = 'I';
> +	break;
> +      }
> +    attrs = Fcons (Fcons (Qstate, build_string (state)), attrs);
> +  }
> +
> +  attrs = Fcons (Fcons (Qppid, make_fixnum_or_float (proc.kp_eproc.e_ppid)), attrs);
> +  attrs = Fcons (Fcons (Qpgrp, make_fixnum_or_float (proc.kp_eproc.e_pgid)), attrs);
> +
> +  tdev = proc.kp_eproc.e_tdev;
> +  block_input ();
> +  ttyname = tdev == NODEV ? NULL : devname (tdev, S_IFCHR);
> +  unblock_input ();
> +  if (ttyname)
> +    attrs = Fcons (Fcons (Qtty, build_string (ttyname)), attrs);
> +
> +  attrs = Fcons (Fcons (Qtpgid,   make_fixnum_or_float (proc.kp_eproc.e_tpgid)), attrs);
> +
> +  rusage = proc.kp_proc.p_ru;
> +  if (rusage)
> +    {
> +      attrs = Fcons (Fcons (Qminflt,  make_fixnum_or_float (rusage->ru_minflt)), attrs);
> +      attrs = Fcons (Fcons (Qmajflt,  make_fixnum_or_float (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);
> +      t = timespec_add (timeval_to_timespec (rusage->ru_utime),
> +			timeval_to_timespec (rusage->ru_stime));
> +      attrs = Fcons (Fcons (Qtime, make_lisp_time (t)), attrs);
> +    }
> +
> +  starttime = proc.kp_proc.p_starttime;
> +  attrs = Fcons (Fcons (Qnice,  make_number (proc.kp_proc.p_nice)), attrs);
> +  attrs = Fcons (Fcons (Qstart, make_lisp_timeval (starttime)), attrs);
> +
> +  now = current_timespec ();
> +  t = timespec_sub (now, timeval_to_timespec (starttime));
> +  attrs = Fcons (Fcons (Qetime, make_lisp_time (t)), attrs);
> +
> +  UNGCPRO;
> +  return attrs;
> +}
> +
> /* The WINDOWSNT implementation is in w32.c.
>    The MSDOS implementation is in dosfns.c.  */
> #elif !defined (WINDOWSNT) && !defined (MSDOS)
> -- 
> 2.2.1
> 





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16579; Package emacs. (Wed, 24 Feb 2016 03:31:02 GMT) Full text and rfc822 format available.

Message #14 received at 16579 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Magnus Henoch <magnus.henoch <at> gmail.com>
Cc: 16579 <at> debbugs.gnu.org
Subject: Re: bug#16579: 24.3.50; Implement system_process_attributes on Darwin
Date: Wed, 24 Feb 2016 14:29:34 +1100
Magnus Henoch <magnus.henoch <at> gmail.com> writes:

> The attached patch implements system_process_attributes on Darwin / Mac
> OSX, and thus makes Proced show a list of processes on such systems.

[...]

> So I had another look at this, and realised that the patch looks
> pretty ugly, being all interleaved with the FreeBSD code... Here's
> another patch, that just adds a new section for Darwin.  I feel much
> better about it now.
>
> Any thoughts or objections?

It looks fine to me, and that sounds like useful functionality, but I
don't have access to any Darwin systems, so I can't even compile it.
Could somebody try applying it and see whether it (still) works?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16579; Package emacs. (Fri, 22 Apr 2016 23:17:01 GMT) Full text and rfc822 format available.

Message #17 received at 16579 <at> debbugs.gnu.org (full text, mbox):

From: Steve Purcell <steve <at> sanityinc.com>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Magnus Henoch <magnus.henoch <at> gmail.com>, 16579 <at> debbugs.gnu.org
Subject: Re: bug#16579: 24.3.50; Implement system_process_attributes on Darwin
Date: Sat, 23 Apr 2016 11:15:41 +1200
I'm on OS X 10.11.4, and the patch applies cleanly for me but doesn't
compile:


  CC       sysdep.o
sysdep.c:3607:16: error: variable has incomplete type 'struct gcpro'
  struct gcpro gcpro1, gcpro2;
               ^
sysdep.c:3607:10: note: forward declaration of 'struct gcpro'
  struct gcpro gcpro1, gcpro2;
         ^
sysdep.c:3607:24: error: variable has incomplete type 'struct gcpro'
  struct gcpro gcpro1, gcpro2;
                       ^
sysdep.c:3607:10: note: forward declaration of 'struct gcpro'
  struct gcpro gcpro1, gcpro2;
         ^
sysdep.c:3618:3: warning: implicit declaration of function 'GCPRO2' is invalid in C99
      [-Wimplicit-function-declaration]
  GCPRO2 (attrs, decoded_comm);
  ^
sysdep.c:3705:3: error: use of undeclared identifier 'UNGCPRO'
  UNGCPRO;
  ^
1 warning and 3 errors generated.
make[2]: *** [sysdep.o] Error 1
make[1]: *** [src] Error 2
make: *** [bootstrap] Error 2




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16579; Package emacs. (Sat, 23 Apr 2016 00:54:02 GMT) Full text and rfc822 format available.

Message #20 received at 16579 <at> debbugs.gnu.org (full text, mbox):

From: Magnus Henoch <magnus.henoch <at> gmail.com>
To: Steve Purcell <steve <at> sanityinc.com>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, Magnus Henoch <magnus.henoch <at> gmail.com>,
 16579 <at> debbugs.gnu.org
Subject: Re: bug#16579: 24.3.50; Implement system_process_attributes on Darwin
Date: Sat, 23 Apr 2016 01:53:18 +0100
[Message part 1 (text/plain, inline)]
Steve Purcell <steve <at> sanityinc.com> writes:

> I'm on OS X 10.11.4, and the patch applies cleanly for me but 
> doesn't compile:
>  
>   CC       sysdep.o
> sysdep.c:3607:16: error: variable has incomplete type 'struct 
> gcpro'
>   struct gcpro gcpro1, gcpro2;

Right, here's a new version, without the gcpro stuff.  If I 
understand correctly, those things were removed since I wrote the 
first version of the patch, and are not necessary any more.

[0001-Implement-process-attributes-for-Darwin.patch (text/x-patch, inline)]
From 0bc6119d618bcfec99ab3ef16739472f8628abe4 Mon Sep 17 00:00:00 2001
From: Magnus Henoch <magnus.henoch <at> gmail.com>
Date: Sun, 15 Nov 2015 02:05:00 +0000
Subject: [PATCH] Implement process-attributes for Darwin

Mostly copied from the FreeBSD implementation, but it's different enough
to warrant a separate preprocessor if clause.
---
 src/sysdep.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 135 insertions(+)

diff --git a/src/sysdep.c b/src/sysdep.c
index 3faa696..50e0b01 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -3567,6 +3567,141 @@ system_process_attributes (Lisp_Object pid)
   return attrs;
 }
 
+#elif defined DARWIN_OS
+
+static struct timespec
+timeval_to_timespec (struct timeval t)
+{
+  return make_timespec (t.tv_sec, t.tv_usec * 1000);
+}
+
+static Lisp_Object
+make_lisp_timeval (struct timeval t)
+{
+  return make_lisp_time (timeval_to_timespec (t));
+}
+
+Lisp_Object
+system_process_attributes (Lisp_Object pid)
+{
+  int proc_id;
+  int pagesize = getpagesize ();
+  unsigned long npages;
+  int fscale;
+  struct passwd *pw;
+  struct group  *gr;
+  char *ttyname;
+  size_t len;
+  char args[MAXPATHLEN];
+  struct timeval starttime;
+  struct timespec t, now;
+  struct rusage *rusage;
+  dev_t tdev;
+  uid_t uid;
+  gid_t gid;
+
+  int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID};
+  struct kinfo_proc proc;
+  size_t proclen = sizeof proc;
+
+  Lisp_Object attrs = Qnil;
+  Lisp_Object decoded_comm;
+
+  CHECK_NUMBER_OR_FLOAT (pid);
+  CONS_TO_INTEGER (pid, int, proc_id);
+  mib[3] = proc_id;
+
+  if (sysctl (mib, 4, &proc, &proclen, NULL, 0) != 0)
+    return attrs;
+
+  uid = proc.kp_eproc.e_ucred.cr_uid;
+  attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid)), attrs);
+
+  block_input ();
+  pw = getpwuid (uid);
+  unblock_input ();
+  if (pw)
+    attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs);
+
+  gid = proc.kp_eproc.e_pcred.p_svgid;
+  attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid)), attrs);
+
+  block_input ();
+  gr = getgrgid (gid);
+  unblock_input ();
+  if (gr)
+    attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs);
+
+  decoded_comm = (code_convert_string_norecord
+		  (build_unibyte_string (proc.kp_proc.p_comm),
+		   Vlocale_coding_system, 0));
+
+  attrs = Fcons (Fcons (Qcomm, decoded_comm), attrs);
+  {
+    char state[2] = {'\0', '\0'};
+    switch (proc.kp_proc.p_stat)
+      {
+      case SRUN:
+	state[0] = 'R';
+	break;
+
+      case SSLEEP:
+	state[0] = 'S';
+	break;
+
+      case SZOMB:
+	state[0] = 'Z';
+	break;
+
+      case SSTOP:
+	state[0] = 'T';
+	break;
+
+      case SIDL:
+	state[0] = 'I';
+	break;
+      }
+    attrs = Fcons (Fcons (Qstate, build_string (state)), attrs);
+  }
+
+  attrs = Fcons (Fcons (Qppid, make_fixnum_or_float (proc.kp_eproc.e_ppid)), attrs);
+  attrs = Fcons (Fcons (Qpgrp, make_fixnum_or_float (proc.kp_eproc.e_pgid)), attrs);
+
+  tdev = proc.kp_eproc.e_tdev;
+  block_input ();
+  ttyname = tdev == NODEV ? NULL : devname (tdev, S_IFCHR);
+  unblock_input ();
+  if (ttyname)
+    attrs = Fcons (Fcons (Qtty, build_string (ttyname)), attrs);
+
+  attrs = Fcons (Fcons (Qtpgid,   make_fixnum_or_float (proc.kp_eproc.e_tpgid)), attrs);
+
+  rusage = proc.kp_proc.p_ru;
+  if (rusage)
+    {
+      attrs = Fcons (Fcons (Qminflt,  make_fixnum_or_float (rusage->ru_minflt)), attrs);
+      attrs = Fcons (Fcons (Qmajflt,  make_fixnum_or_float (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);
+      t = timespec_add (timeval_to_timespec (rusage->ru_utime),
+			timeval_to_timespec (rusage->ru_stime));
+      attrs = Fcons (Fcons (Qtime, make_lisp_time (t)), attrs);
+    }
+
+  starttime = proc.kp_proc.p_starttime;
+  attrs = Fcons (Fcons (Qnice,  make_number (proc.kp_proc.p_nice)), attrs);
+  attrs = Fcons (Fcons (Qstart, make_lisp_timeval (starttime)), attrs);
+
+  now = current_timespec ();
+  t = timespec_sub (now, timeval_to_timespec (starttime));
+  attrs = Fcons (Fcons (Qetime, make_lisp_time (t)), attrs);
+
+  return attrs;
+}
+
 /* The WINDOWSNT implementation is in w32.c.
    The MSDOS implementation is in dosfns.c.  */
 #elif !defined (WINDOWSNT) && !defined (MSDOS)
-- 
2.8.1


Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16579; Package emacs. (Sat, 23 Apr 2016 03:06:01 GMT) Full text and rfc822 format available.

Message #23 received at 16579 <at> debbugs.gnu.org (full text, mbox):

From: Steve Purcell <steve <at> sanityinc.com>
To: Magnus Henoch <magnus.henoch <at> gmail.com>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 16579 <at> debbugs.gnu.org
Subject: Re: bug#16579: 24.3.50; Implement system_process_attributes on Darwin
Date: Sat, 23 Apr 2016 15:05:35 +1200
Just tried that revised patch and it works great for me! Would be great if this could be merged.



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16579; Package emacs. (Sun, 24 Apr 2016 12:34:02 GMT) Full text and rfc822 format available.

Message #26 received at 16579 <at> debbugs.gnu.org (full text, mbox):

From: Lars Magne Ingebrigtsen <larsi <at> gnus.org>
To: Steve Purcell <steve <at> sanityinc.com>
Cc: Magnus Henoch <magnus.henoch <at> gmail.com>, 16579 <at> debbugs.gnu.org
Subject: Re: bug#16579: 24.3.50; Implement system_process_attributes on Darwin
Date: Sun, 24 Apr 2016 14:33:18 +0200
Steve Purcell <steve <at> sanityinc.com> writes:

> Just tried that revised patch and it works great for me! Would be
> great if this could be merged.

Ok; applied to the trunk.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) fixed. Request was from Lars Magne Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sun, 24 Apr 2016 12:34:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 25.2, send any further explanations to 16579 <at> debbugs.gnu.org and Magnus Henoch <magnus.henoch <at> gmail.com> Request was from Lars Magne Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Sun, 24 Apr 2016 12:34:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 23 May 2016 11:24:04 GMT) Full text and rfc822 format available.

bug unarchived. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 04 Dec 2016 02:50:05 GMT) Full text and rfc822 format available.

bug Marked as fixed in versions 26.1. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 04 Dec 2016 02:50:05 GMT) Full text and rfc822 format available.

bug No longer marked as fixed in versions 25.2. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 04 Dec 2016 02:50:05 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 01 Jan 2017 12:24:23 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 169 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.