aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Gunbin2021-04-14 21:45:16 +0300
committerFilipp Gunbin2021-04-16 01:34:52 +0300
commit1b79178db694c3dd4eedecdeffc1eaf62e656c96 (patch)
tree3e505880e80df72a8619d98d5b062bc49a7b786e
parent7893945cc8f9421d0be5b07b9ed404bdf25ce140 (diff)
downloademacs-scratch/macos-process-args.tar.gz
emacs-scratch/macos-process-args.zip
* src/sysdep.c (system_process_attributes): Support args attribute on macOSscratch/macos-process-args
-rw-r--r--src/sysdep.c82
1 files changed, 61 insertions, 21 deletions
diff --git a/src/sysdep.c b/src/sysdep.c
index d940acc4e05..f899bb7532d 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -3898,20 +3898,19 @@ system_process_attributes (Lisp_Object pid)
3898Lisp_Object 3898Lisp_Object
3899system_process_attributes (Lisp_Object pid) 3899system_process_attributes (Lisp_Object pid)
3900{ 3900{
3901 int proc_id; 3901 int proc_id, i;
3902 struct passwd *pw; 3902 struct passwd *pw;
3903 struct group *gr; 3903 struct group *gr;
3904 char *ttyname; 3904 char *ttyname;
3905 struct timeval starttime; 3905 struct timeval starttime;
3906 struct timespec t, now; 3906 struct timespec t, now;
3907 struct rusage *rusage;
3908 dev_t tdev; 3907 dev_t tdev;
3909 uid_t uid; 3908 uid_t uid;
3910 gid_t gid; 3909 gid_t gid;
3911 3910
3912 int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID}; 3911 int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID};
3913 struct kinfo_proc proc; 3912 struct kinfo_proc proc;
3914 size_t proclen = sizeof proc; 3913 size_t len = sizeof proc;
3915 3914
3916 Lisp_Object attrs = Qnil; 3915 Lisp_Object attrs = Qnil;
3917 Lisp_Object decoded_comm; 3916 Lisp_Object decoded_comm;
@@ -3920,7 +3919,7 @@ system_process_attributes (Lisp_Object pid)
3920 CONS_TO_INTEGER (pid, int, proc_id); 3919 CONS_TO_INTEGER (pid, int, proc_id);
3921 mib[3] = proc_id; 3920 mib[3] = proc_id;
3922 3921
3923 if (sysctl (mib, 4, &proc, &proclen, NULL, 0) != 0 || proclen == 0) 3922 if (sysctl (mib, 4, &proc, &len, NULL, 0) != 0 || len == 0)
3924 return attrs; 3923 return attrs;
3925 3924
3926 uid = proc.kp_eproc.e_ucred.cr_uid; 3925 uid = proc.kp_eproc.e_ucred.cr_uid;
@@ -3957,8 +3956,8 @@ system_process_attributes (Lisp_Object pid)
3957 decoded_comm = (code_convert_string_norecord 3956 decoded_comm = (code_convert_string_norecord
3958 (build_unibyte_string (comm), 3957 (build_unibyte_string (comm),
3959 Vlocale_coding_system, 0)); 3958 Vlocale_coding_system, 0));
3960
3961 attrs = Fcons (Fcons (Qcomm, decoded_comm), attrs); 3959 attrs = Fcons (Fcons (Qcomm, decoded_comm), attrs);
3960
3962 { 3961 {
3963 char state[2] = {'\0', '\0'}; 3962 char state[2] = {'\0', '\0'};
3964 switch (proc.kp_proc.p_stat) 3963 switch (proc.kp_proc.p_stat)
@@ -3994,27 +3993,24 @@ system_process_attributes (Lisp_Object pid)
3994 ttyname = tdev == NODEV ? NULL : devname (tdev, S_IFCHR); 3993 ttyname = tdev == NODEV ? NULL : devname (tdev, S_IFCHR);
3995 unblock_input (); 3994 unblock_input ();
3996 if (ttyname) 3995 if (ttyname)
3997 attrs = Fcons (Fcons (Qtty, build_string (ttyname)), attrs); 3996 attrs = Fcons (Fcons (Qttname, build_string (ttyname)), attrs);
3998 3997
3999 attrs = Fcons (Fcons (Qtpgid, INT_TO_INTEGER (proc.kp_eproc.e_tpgid)), 3998 attrs = Fcons (Fcons (Qtpgid, INT_TO_INTEGER (proc.kp_eproc.e_tpgid)),
4000 attrs); 3999 attrs);
4001 4000
4002 rusage = proc.kp_proc.p_ru; 4001 rusage_info_current ri;
4003 if (rusage) 4002 if (proc_pid_rusage(proc_id, RUSAGE_INFO_CURRENT, (rusage_info_t *) &ri) == 0)
4004 { 4003 {
4005 attrs = Fcons (Fcons (Qminflt, INT_TO_INTEGER (rusage->ru_minflt)), 4004 struct timespec utime = make_timespec (ri.ri_user_time / TIMESPEC_HZ,
4006 attrs); 4005 ri.ri_user_time % TIMESPEC_HZ);
4007 attrs = Fcons (Fcons (Qmajflt, INT_TO_INTEGER (rusage->ru_majflt)), 4006 struct timespec stime = make_timespec (ri.ri_system_time / TIMESPEC_HZ,
4008 attrs); 4007 ri.ri_system_time % TIMESPEC_HZ);
4009 4008 attrs = Fcons (Fcons (Qutime, make_lisp_time (utime)), attrs);
4010 attrs = Fcons (Fcons (Qutime, make_lisp_timeval (rusage->ru_utime)), 4009 attrs = Fcons (Fcons (Qstime, make_lisp_time (stime)), attrs);
4011 attrs); 4010 attrs = Fcons (Fcons (Qtime, make_lisp_time (timespec_add (utime, stime))), attrs);
4012 attrs = Fcons (Fcons (Qstime, make_lisp_timeval (rusage->ru_stime)), 4011
4013 attrs); 4012 attrs = Fcons (Fcons (Qmajflt, INT_TO_INTEGER (ri.ri_pageins)), attrs);
4014 t = timespec_add (timeval_to_timespec (rusage->ru_utime), 4013 }
4015 timeval_to_timespec (rusage->ru_stime));
4016 attrs = Fcons (Fcons (Qtime, make_lisp_time (t)), attrs);
4017 }
4018 4014
4019 starttime = proc.kp_proc.p_starttime; 4015 starttime = proc.kp_proc.p_starttime;
4020 attrs = Fcons (Fcons (Qnice, make_fixnum (proc.kp_proc.p_nice)), attrs); 4016 attrs = Fcons (Fcons (Qnice, make_fixnum (proc.kp_proc.p_nice)), attrs);
@@ -4024,6 +4020,50 @@ system_process_attributes (Lisp_Object pid)
4024 t = timespec_sub (now, timeval_to_timespec (starttime)); 4020 t = timespec_sub (now, timeval_to_timespec (starttime));
4025 attrs = Fcons (Fcons (Qetime, make_lisp_time (t)), attrs); 4021 attrs = Fcons (Fcons (Qetime, make_lisp_time (t)), attrs);
4026 4022
4023 struct proc_taskinfo taskinfo;
4024 if (proc_pidinfo (proc_id, PROC_PIDTASKINFO, 0, &taskinfo, sizeof (taskinfo)) > 0)
4025 {
4026 attrs = Fcons (Fcons (Qvsize, make_fixnum (taskinfo.pti_virtual_size / 1024)), attrs);
4027 attrs = Fcons (Fcons (Qrss, make_fixnum (taskinfo.pti_resident_size / 1024)), attrs);
4028 attrs = Fcons (Fcons (Qthcount, make_fixnum (taskinfo.pti_threadnum)), attrs);
4029 }
4030
4031#ifdef KERN_PROCARGS2
4032 char args[ARG_MAX];
4033 mib[1] = KERN_PROCARGS2;
4034 mib[2] = proc_id;
4035 len = sizeof args;
4036
4037 if (sysctl (mib, 3, &args, &len, NULL, 0) == 0 && len != 0)
4038 {
4039 char *start, *end;
4040
4041 int argc = *(int*)args; /* argc is the first int */
4042 start = args + sizeof (int);
4043
4044 start += strlen (start) + 1; /* skip executable name and any '\0's */
4045 while ((start - args < len) && ! *start) start++;
4046
4047 /* skip argv to find real end */
4048 for (i = 0, end = start; i < argc && (end - args) < len; i++)
4049 {
4050 end += strlen (end) + 1;
4051 }
4052
4053 len = end - start;
4054 for (int i = 0; i < len; i++)
4055 {
4056 if (! start[i] && i < len - 1)
4057 start[i] = ' ';
4058 }
4059
4060 AUTO_STRING (comm, start);
4061 decoded_comm = code_convert_string_norecord (comm,
4062 Vlocale_coding_system, 0);
4063 attrs = Fcons (Fcons (Qargs, decoded_comm), attrs);
4064 }
4065#endif /* KERN_PROCARGS2 */
4066
4027 return attrs; 4067 return attrs;
4028} 4068}
4029 4069