From b4f05274c7a8facbf2a817ec14d234605959c4de Mon Sep 17 00:00:00 2001 From: Robert Pluim Date: Tue, 18 Aug 2020 20:31:37 +0200 Subject: [PATCH] Fix truncated command names in process-attributes under Macos * src/sysdep.c (system_process_attributes): Fix truncation of command names in process-attributes under Macos (bug#36287). --- src/sysdep.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/sysdep.c b/src/sysdep.c index b1371cd411b..a1050c4309a 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -53,6 +53,10 @@ along with GNU Emacs. If not, see . */ # include #endif +#ifdef DARWIN_OS +# include +#endif + #ifdef __FreeBSD__ /* Sparc/ARM machine/frame.h has 'struct frame' which conflicts with Emacs's 'struct frame', so rename it. */ @@ -3871,8 +3875,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);