bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#36287: 26.2.90; On macOS, process-attributes returns truncated comma


From: Robert Pluim
Subject: bug#36287: 26.2.90; On macOS, process-attributes returns truncated command name
Date: Wed, 19 Jun 2019 12:15:10 +0200

>>>>> On Wed, 19 Jun 2019 15:46:24 +0800, Xu Chunyang <mail@xuchunyang.me> said:

    Xu> (alist-get 'comm (process-attributes 45329))
    Xu> ;; => "Google Chrome He"

The sysctl interface will never return more than 16 characters. A
quick google leads me to the following (there may well be utility
functions in emacs for the full-path => command name munging already).

diff --git a/src/sysdep.c b/src/sysdep.c
index b2aecc0dda..c1cc89451b 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -50,6 +50,10 @@
 # include <sys/sysctl.h>
 #endif
 
+#ifdef DARWIN_OS
+# include <libproc.h>
+#endif
+
 #ifdef __FreeBSD__
 /* Sparc/ARM machine/frame.h has 'struct frame' which conflicts with Emacs's
    'struct frame', so rename it.  */
@@ -3819,8 +3823,21 @@ system_process_attributes (Lisp_Object pid)
   if (gr)
     attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs);
 
+  char pathbuf[PROC_PIDPATHINFO_MAXSIZE];
+  char *comm;
+
+  if (proc_pidpath (proc_id, pathbuf, sizeof(pathbuf)) > 0)
+    {
+      if ((comm = strrchr (pathbuf, '/')))
+        comm++;
+      else
+        comm = pathbuf;
+    }
+  else
+    comm = proc.kp_proc.p_comm;
+
   decoded_comm = (code_convert_string_norecord
-                 (build_unibyte_string (proc.kp_proc.p_comm),
+                 (build_unibyte_string (comm),
                   Vlocale_coding_system, 0));
 
   attrs = Fcons (Fcons (Qcomm, decoded_comm), attrs);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]