GNU bug report logs -
#48548
28.0.50; Some process attributes on macOS are missing
Previous Next
Reported by: Filipp Gunbin <fgunbin <at> fastmail.fm>
Date: Thu, 20 May 2021 20:26:01 UTC
Severity: normal
Tags: fixed, patch
Found in version 28.0.50
Fixed in version 28.1
Done: Filipp Gunbin <fgunbin <at> fastmail.fm>
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 48548 in the body.
You can then email your comments to 48548 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#48548
; Package
emacs
.
(Thu, 20 May 2021 20:26:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Filipp Gunbin <fgunbin <at> fastmail.fm>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Thu, 20 May 2021 20:26:01 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
On macOS, system_process_attributes() could provide more attributes
("args", in particular). Will post patch here.
Thanks
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#48548
; Package
emacs
.
(Thu, 20 May 2021 20:36:02 GMT)
Full text and
rfc822 format available.
Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):
tags 48548 + patch
quit
On 20/05/2021 23:24 +0300, Filipp Gunbin wrote:
> On macOS, system_process_attributes() could provide more attributes
> ("args", in particular). Will post patch here.
>
> Thanks
Added tag(s) patch.
Request was from
Filipp Gunbin <fgunbin <at> fastmail.fm>
to
control <at> debbugs.gnu.org
.
(Thu, 20 May 2021 20:36:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#48548
; Package
emacs
.
(Thu, 20 May 2021 20:40:02 GMT)
Full text and
rfc822 format available.
Message #13 received at submit <at> debbugs.gnu.org (full text, mbox):
Improve system_process_attributes on macOS (Bug#48548)
* src/sysdep.c (system_process_attributes): Fix misprint in 'tty' attr
- should be 'ttname' instead. Change 'utime', 'stime', 'time',
'majflt' attrs to obtain them from proc_pid_rusage, as sysctl call
used before doesn't give correct values; remove 'minflt' because it's
not available. Obtain 'vsize' / 'rss' / 'thcount' from proc_pidinfo.
Use sysctl with KERN_PROCARGS2 to obtain args: value contains both
argc and argv, so argv can be reliably cut out.
diff --git a/src/sysdep.c b/src/sysdep.c
index d940acc4e0..f899bb7532 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -3898,20 +3898,19 @@ system_process_attributes (Lisp_Object pid)
Lisp_Object
system_process_attributes (Lisp_Object pid)
{
- int proc_id;
+ int proc_id, i;
struct passwd *pw;
struct group *gr;
char *ttyname;
struct timeval starttime;
struct timespec t, now;
- struct rusage *rusage;
dev_t tdev;
uid_t uid;
gid_t gid;
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID};
struct kinfo_proc proc;
- size_t proclen = sizeof proc;
+ size_t len = sizeof proc;
Lisp_Object attrs = Qnil;
Lisp_Object decoded_comm;
@@ -3920,7 +3919,7 @@ system_process_attributes (Lisp_Object pid)
CONS_TO_INTEGER (pid, int, proc_id);
mib[3] = proc_id;
- if (sysctl (mib, 4, &proc, &proclen, NULL, 0) != 0 || proclen == 0)
+ if (sysctl (mib, 4, &proc, &len, NULL, 0) != 0 || len == 0)
return attrs;
uid = proc.kp_eproc.e_ucred.cr_uid;
@@ -3957,8 +3956,8 @@ system_process_attributes (Lisp_Object pid)
decoded_comm = (code_convert_string_norecord
(build_unibyte_string (comm),
Vlocale_coding_system, 0));
-
attrs = Fcons (Fcons (Qcomm, decoded_comm), attrs);
+
{
char state[2] = {'\0', '\0'};
switch (proc.kp_proc.p_stat)
@@ -3994,27 +3993,24 @@ system_process_attributes (Lisp_Object pid)
ttyname = tdev == NODEV ? NULL : devname (tdev, S_IFCHR);
unblock_input ();
if (ttyname)
- attrs = Fcons (Fcons (Qtty, build_string (ttyname)), attrs);
+ attrs = Fcons (Fcons (Qttname, build_string (ttyname)), attrs);
attrs = Fcons (Fcons (Qtpgid, INT_TO_INTEGER (proc.kp_eproc.e_tpgid)),
attrs);
- rusage = proc.kp_proc.p_ru;
- if (rusage)
+ rusage_info_current ri;
+ if (proc_pid_rusage(proc_id, RUSAGE_INFO_CURRENT, (rusage_info_t *) &ri) == 0)
{
- attrs = Fcons (Fcons (Qminflt, INT_TO_INTEGER (rusage->ru_minflt)),
- attrs);
- attrs = Fcons (Fcons (Qmajflt, INT_TO_INTEGER (rusage->ru_majflt)),
- attrs);
-
- attrs = Fcons (Fcons (Qutime, make_lisp_timeval (rusage->ru_utime)),
- attrs);
- attrs = Fcons (Fcons (Qstime, make_lisp_timeval (rusage->ru_stime)),
- attrs);
- t = timespec_add (timeval_to_timespec (rusage->ru_utime),
- timeval_to_timespec (rusage->ru_stime));
- attrs = Fcons (Fcons (Qtime, make_lisp_time (t)), attrs);
- }
+ struct timespec utime = make_timespec (ri.ri_user_time / TIMESPEC_HZ,
+ ri.ri_user_time % TIMESPEC_HZ);
+ struct timespec stime = make_timespec (ri.ri_system_time / TIMESPEC_HZ,
+ ri.ri_system_time % TIMESPEC_HZ);
+ attrs = Fcons (Fcons (Qutime, make_lisp_time (utime)), attrs);
+ attrs = Fcons (Fcons (Qstime, make_lisp_time (stime)), attrs);
+ attrs = Fcons (Fcons (Qtime, make_lisp_time (timespec_add (utime, stime))), attrs);
+
+ attrs = Fcons (Fcons (Qmajflt, INT_TO_INTEGER (ri.ri_pageins)), attrs);
+ }
starttime = proc.kp_proc.p_starttime;
attrs = Fcons (Fcons (Qnice, make_fixnum (proc.kp_proc.p_nice)), attrs);
@@ -4024,6 +4020,50 @@ system_process_attributes (Lisp_Object pid)
t = timespec_sub (now, timeval_to_timespec (starttime));
attrs = Fcons (Fcons (Qetime, make_lisp_time (t)), attrs);
+ struct proc_taskinfo taskinfo;
+ if (proc_pidinfo (proc_id, PROC_PIDTASKINFO, 0, &taskinfo, sizeof (taskinfo)) > 0)
+ {
+ attrs = Fcons (Fcons (Qvsize, make_fixnum (taskinfo.pti_virtual_size / 1024)), attrs);
+ attrs = Fcons (Fcons (Qrss, make_fixnum (taskinfo.pti_resident_size / 1024)), attrs);
+ attrs = Fcons (Fcons (Qthcount, make_fixnum (taskinfo.pti_threadnum)), attrs);
+ }
+
+#ifdef KERN_PROCARGS2
+ char args[ARG_MAX];
+ mib[1] = KERN_PROCARGS2;
+ mib[2] = proc_id;
+ len = sizeof args;
+
+ if (sysctl (mib, 3, &args, &len, NULL, 0) == 0 && len != 0)
+ {
+ char *start, *end;
+
+ int argc = *(int*)args; /* argc is the first int */
+ start = args + sizeof (int);
+
+ start += strlen (start) + 1; /* skip executable name and any '\0's */
+ while ((start - args < len) && ! *start) start++;
+
+ /* skip argv to find real end */
+ for (i = 0, end = start; i < argc && (end - args) < len; i++)
+ {
+ end += strlen (end) + 1;
+ }
+
+ len = end - start;
+ for (int i = 0; i < len; i++)
+ {
+ if (! start[i] && i < len - 1)
+ start[i] = ' ';
+ }
+
+ AUTO_STRING (comm, start);
+ decoded_comm = code_convert_string_norecord (comm,
+ Vlocale_coding_system, 0);
+ attrs = Fcons (Fcons (Qargs, decoded_comm), attrs);
+ }
+#endif /* KERN_PROCARGS2 */
+
return attrs;
}
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#48548
; Package
emacs
.
(Thu, 20 May 2021 20:51:02 GMT)
Full text and
rfc822 format available.
Message #16 received at submit <at> debbugs.gnu.org (full text, mbox):
Hello, could someone please review this? (bug#48548)
I'm kinda sure in syscalls I make (tested them on latest Big Sur 11.3.1
and on Yosemite from several years ago; running with this patch for
several weeks now, using via M-x proced), but I'm not so sure in my C
:-)
Thanks.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#48548
; Package
emacs
.
(Fri, 21 May 2021 05:54:01 GMT)
Full text and
rfc822 format available.
Message #19 received at submit <at> debbugs.gnu.org (full text, mbox):
> From: Filipp Gunbin <fgunbin <at> fastmail.fm>
> Date: Thu, 20 May 2021 23:49:54 +0300
> Cc: bug-gnu-emacs <at> gnu.org
>
> Hello, could someone please review this? (bug#48548)
Please be more patient: you posted the patch just 10 minutes before
sending this ping. The patch will be reviewed soon enough, just give
us some time.
Thanks.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#48548
; Package
emacs
.
(Fri, 21 May 2021 09:52:01 GMT)
Full text and
rfc822 format available.
Message #22 received at submit <at> debbugs.gnu.org (full text, mbox):
On 21/05/2021 08:53 +0300, Eli Zaretskii wrote:
>> From: Filipp Gunbin <fgunbin <at> fastmail.fm>
>> Date: Thu, 20 May 2021 23:49:54 +0300
>> Cc: bug-gnu-emacs <at> gnu.org
>>
>> Hello, could someone please review this? (bug#48548)
>
> Please be more patient: you posted the patch just 10 minutes before
> sending this ping. The patch will be reviewed soon enough, just give
> us some time.
>
> Thanks.
Pinging wasn't my intent, I just wanted to ask for review on
emacs-devel..
Thanks.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#48548
; Package
emacs
.
(Tue, 25 May 2021 04:10:01 GMT)
Full text and
rfc822 format available.
Message #25 received at 48548 <at> debbugs.gnu.org (full text, mbox):
Filipp Gunbin <fgunbin <at> fastmail.fm> writes:
> Improve system_process_attributes on macOS (Bug#48548)
Looks good to me, but I've added Alan to the CCs -- perhaps he'll have
some comments.
Just one small comment:
> - size_t proclen = sizeof proc;
> + size_t len = sizeof proc;
Any reason for this change?
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#48548
; Package
emacs
.
(Tue, 25 May 2021 17:15:01 GMT)
Full text and
rfc822 format available.
Message #28 received at 48548 <at> debbugs.gnu.org (full text, mbox):
On 25/05/2021 06:08 +0200, Lars Ingebrigtsen wrote:
> Filipp Gunbin <fgunbin <at> fastmail.fm> writes:
>
>> Improve system_process_attributes on macOS (Bug#48548)
>
> Looks good to me, but I've added Alan to the CCs -- perhaps he'll have
> some comments.
Thanks, will wait.
> Just one small comment:
>
>> - size_t proclen = sizeof proc;
>> + size_t len = sizeof proc;
>
> Any reason for this change?
Yes, the usage of len for different purpose below:
+ len = sizeof args;
Filipp
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#48548
; Package
emacs
.
(Tue, 25 May 2021 19:33:01 GMT)
Full text and
rfc822 format available.
Message #31 received at 48548 <at> debbugs.gnu.org (full text, mbox):
Filipp Gunbin <fgunbin <at> fastmail.fm> writes:
>> Any reason for this change?
>
> Yes, the usage of len for different purpose below:
>
> + len = sizeof args;
Oops; didn't read the patch carefully enough.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#48548
; Package
emacs
.
(Wed, 26 May 2021 06:54:01 GMT)
Full text and
rfc822 format available.
Message #34 received at 48548 <at> debbugs.gnu.org (full text, mbox):
On Tue, May 25, 2021 at 06:08:56AM +0200, Lars Ingebrigtsen wrote:
> Filipp Gunbin <fgunbin <at> fastmail.fm> writes:
>
> > Improve system_process_attributes on macOS (Bug#48548)
>
> Looks good to me, but I've added Alan to the CCs -- perhaps he'll have
> some comments.
No comments from me.
--
Alan Third
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#48548
; Package
emacs
.
(Wed, 26 May 2021 14:13:01 GMT)
Full text and
rfc822 format available.
Message #37 received at 48548 <at> debbugs.gnu.org (full text, mbox):
tags 48548 fixed
close 48548 28.1
quit
On 26/05/2021 07:52 +0100, Alan Third wrote:
> On Tue, May 25, 2021 at 06:08:56AM +0200, Lars Ingebrigtsen wrote:
>> Filipp Gunbin <fgunbin <at> fastmail.fm> writes:
>>
>> > Improve system_process_attributes on macOS (Bug#48548)
>>
>> Looks good to me, but I've added Alan to the CCs -- perhaps he'll have
>> some comments.
>
> No comments from me.
> --
> Alan Third
Pushed to master.
6d51805154 2021-05-26T16:15:03+03:00 "Improve system_process_attributes on macOS (Bug#48548)"
https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=6d51805154ef7591917c5727b905b4080e18b888
Added tag(s) fixed.
Request was from
Filipp Gunbin <fgunbin <at> fastmail.fm>
to
control <at> debbugs.gnu.org
.
(Wed, 26 May 2021 14:13:02 GMT)
Full text and
rfc822 format available.
bug marked as fixed in version 28.1, send any further explanations to
48548 <at> debbugs.gnu.org and Filipp Gunbin <fgunbin <at> fastmail.fm>
Request was from
Filipp Gunbin <fgunbin <at> fastmail.fm>
to
control <at> debbugs.gnu.org
.
(Wed, 26 May 2021 14:13:02 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
.
(Thu, 24 Jun 2021 11:24:06 GMT)
Full text and
rfc822 format available.
This bug report was last modified 4 years and 10 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.