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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 36287 in the body.
You can then email your comments to 36287 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#36287; Package emacs. (Wed, 19 Jun 2019 07:47:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Xu Chunyang <mail <at> xuchunyang.me>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 19 Jun 2019 07:47:02 GMT) Full text and rfc822 format available.

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

From: Xu Chunyang <mail <at> xuchunyang.me>
To: bug-gnu-emacs <at> gnu.org
Subject: 26.2.90; On macOS, process-attributes returns truncated command name
Date: Wed, 19 Jun 2019 15:46:24 +0800
(alist-get 'comm (process-attributes 45329))
;; => "Google Chrome He"

But the command name is actually 'Google Chrome Helper' as the following
shows

~ $ ps -p 45329
  PID TTY           TIME CMD
45329 ??         8:15.90 /Applications/Google Chrome.app/Contents/Frameworks/Google Chrome Framework.framework/Versions/75.0.3770.100/Helpers/Google Chrome Helper.app/Contents/MacOS/Google Chrome Helper --type=gpu-process --field-trial-handle=1718379636,16071315400300348740,16333828044400969087,131072 --gpu-preferences=KAAAAAAAAAAgAAAAAQAAAAAAAAAAAGAAAAAAAAAAAAAIAAAAAAAAAAABAAAfAAAA+AAAAAAAAAAAAQAAAAAAAAgBAAAAAAAAEAEAAAAAAAAYAQAAAAAAACABAAAAAAAAKAEAAAAAAAAwAQAAAAAAADgBAAAAAAAAQAEAAAAAAABIAQAAAAAAAFABAAAAAAAAWAEAAAAAAABgAQAAAAAAAGgBAAAAAAAAcAEAAAAAAAB4AQAAAAAAAIABAAAAAAAAiAEAAAAAAACQAQAAAAAAAJgBAAAAAAAAoAEAAAAAAACoAQAAAAAAALABAAAAAAAAuAEAAAAAAADAAQAAAAAAAMgBAAAAAAAA0AEAAAAAAADYAQAAAAAAAOABAAAAAAAA6AEAAAAAAAAQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAABgAAABAAAAAAAAAAAAAAAAcAAAAQAAAAAAAAAAAAAAAIAAAAEAAAAAAAAAAAAAAACgAAABAAAAAAAAAAAAAAAAsAAAAQAAAAAAAAAAAAAAANAAAAEAAAAAAAAAAAAAAADgAAABAAAAAAAAAAAQAAAAAAAAAQAAAAAAAAAAEAAAAGAAAAEAAAAAAAAAABAAAABwAAABAAAAAAAAAAAQAAAAgAAAAQAAAAAAAAAAEAAAAKAAAAEAAAAAAAAAABAAAACwAAABAAAAAAAAAAAQAAAA0AAAAQAAAAAAAAAAEAAAAOAAAAEAAAAAAAAAAEAAAAAAAAABAAAAAAAAAABAAAAAYAAAAQAAAAAAAAAAQAAAAHAAAAEAAAAAAAAAAEAAAACAAAABAAAAAAAAAABAAAAAoAAAAQAAAAAAAAAAQAAAALAAAAEAAAAAAAAAAEAAAADQAAABAAAAAAAAAABAAAAA4AAAAQAAAAAAAAAAYAAAAAAAAAEAAAAAAAAAAGAAAABgAAABAAAAAAAAAABgAAAAgAAAAQAAAAAAAAAAYAAAAKAAAAEAAAAAAAAAAGAAAACwAAABAAAAAAAAAABgAAAA0AAAAQAAAAAAAAAAYAAAAOAAAA --service-request-channel-token=12474817198730077840
~ $

In GNU Emacs 26.2.90 (build 1, x86_64-apple-darwin18.6.0, Carbon Version 158 AppKit 1671.5)
 of 2019-06-13 built on Chunyangs-MacBook-Air.local
Repository revision: 7ba854289bd169f1e5f4fbdbc4ae2bef24b9811f
Windowing system distributor 'Apple Inc.', version 10.14.5




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#36287; Package emacs. (Wed, 19 Jun 2019 08:39:01 GMT) Full text and rfc822 format available.

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

From: Andreas Schwab <schwab <at> suse.de>
To: Xu Chunyang <mail <at> xuchunyang.me>
Cc: 36287 <at> debbugs.gnu.org
Subject: Re: bug#36287: 26.2.90;
 On macOS, process-attributes returns truncated command name
Date: Wed, 19 Jun 2019 10:38:15 +0200
On Jun 19 2019, Xu Chunyang <mail <at> xuchunyang.me> wrote:

> (alist-get 'comm (process-attributes 45329))
> ;; => "Google Chrome He"
>
> But the command name is actually 'Google Chrome Helper' as the following
> shows

That's probably a kernel limitation.  The Linux kernel also remembers no
more than 15 characters of the command name.  You need to peek that the
process's memory to retrieve the full name.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab <at> suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#36287; Package emacs. (Wed, 19 Jun 2019 10:16:02 GMT) Full text and rfc822 format available.

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

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




Added tag(s) patch. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Tue, 18 Aug 2020 11:22:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#36287; Package emacs. (Tue, 18 Aug 2020 18:31:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Xu Chunyang <mail <at> xuchunyang.me>,  36287 <at> debbugs.gnu.org
Subject: Re: bug#36287: 26.2.90; On macOS, process-attributes returns
 truncated command name
Date: Tue, 18 Aug 2020 20:30:20 +0200
Robert Pluim <rpluim <at> gmail.com> writes:

> 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).
>

[...]

>  #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)

[...]

> +  char pathbuf[PROC_PIDPATHINFO_MAXSIZE];
> +  char *comm;
> +
> +  if (proc_pidpath (proc_id, pathbuf, sizeof(pathbuf)) > 0)
> +    {

I've tested this on Catalina now, and it fixes the problem, so I'll just
go ahead and apply it to Emacs 28.

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




Added tag(s) fixed. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 18 Aug 2020 18:33:01 GMT) Full text and rfc822 format available.

bug marked as fixed in version 28.1, send any further explanations to 36287 <at> debbugs.gnu.org and Xu Chunyang <mail <at> xuchunyang.me> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 18 Aug 2020 18:33:01 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. (Wed, 16 Sep 2020 11:24:10 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 215 days ago.

Previous Next


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