GNU bug report logs - #36287
26.2.90; On macOS, process-attributes returns truncated command name

Previous Next

Package: emacs;

Reported by: Xu Chunyang <mail <at> xuchunyang.me>

Date: Wed, 19 Jun 2019 07:47:02 UTC

Severity: minor

Tags: fixed, patch

Found in version 26.2.90

Fixed in version 28.1

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

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Robert Pluim <rpluim <at> gmail.com>
To: Xu Chunyang <mail <at> xuchunyang.me>
Cc: 36287 <at> debbugs.gnu.org
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 <at> 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);




This bug report was last modified 4 years and 281 days ago.

Previous Next


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