unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#36287: 26.2.90; On macOS, process-attributes returns truncated command name
@ 2019-06-19  7:46 Xu Chunyang
  2019-06-19  8:38 ` Andreas Schwab
  2019-06-19 10:15 ` Robert Pluim
  0 siblings, 2 replies; 4+ messages in thread
From: Xu Chunyang @ 2019-06-19  7:46 UTC (permalink / raw)
  To: 36287

(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





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#36287: 26.2.90; On macOS, process-attributes returns truncated command name
  2019-06-19  7:46 bug#36287: 26.2.90; On macOS, process-attributes returns truncated command name Xu Chunyang
@ 2019-06-19  8:38 ` Andreas Schwab
  2019-06-19 10:15 ` Robert Pluim
  1 sibling, 0 replies; 4+ messages in thread
From: Andreas Schwab @ 2019-06-19  8:38 UTC (permalink / raw)
  To: Xu Chunyang; +Cc: 36287

On Jun 19 2019, Xu Chunyang <mail@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@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#36287: 26.2.90; On macOS, process-attributes returns truncated command name
  2019-06-19  7:46 bug#36287: 26.2.90; On macOS, process-attributes returns truncated command name Xu Chunyang
  2019-06-19  8:38 ` Andreas Schwab
@ 2019-06-19 10:15 ` Robert Pluim
  2020-08-18 18:30   ` Lars Ingebrigtsen
  1 sibling, 1 reply; 4+ messages in thread
From: Robert Pluim @ 2019-06-19 10:15 UTC (permalink / raw)
  To: Xu Chunyang; +Cc: 36287

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





^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#36287: 26.2.90; On macOS, process-attributes returns truncated command name
  2019-06-19 10:15 ` Robert Pluim
@ 2020-08-18 18:30   ` Lars Ingebrigtsen
  0 siblings, 0 replies; 4+ messages in thread
From: Lars Ingebrigtsen @ 2020-08-18 18:30 UTC (permalink / raw)
  To: Xu Chunyang, 36287

Robert Pluim <rpluim@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





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-08-18 18:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-19  7:46 bug#36287: 26.2.90; On macOS, process-attributes returns truncated command name Xu Chunyang
2019-06-19  8:38 ` Andreas Schwab
2019-06-19 10:15 ` Robert Pluim
2020-08-18 18:30   ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).