From: Magnus Henoch <magnus.henoch@gmail.com>
To: Steve Purcell <steve@sanityinc.com>
Cc: Lars Ingebrigtsen <larsi@gnus.org>,
Magnus Henoch <magnus.henoch@gmail.com>,
16579@debbugs.gnu.org
Subject: bug#16579: 24.3.50; Implement system_process_attributes on Darwin
Date: Sat, 23 Apr 2016 01:53:18 +0100 [thread overview]
Message-ID: <m1lh45qh6p.fsf@mail.gmail.com> (raw)
In-Reply-To: Steve Purcell's message of "Sat\, 23 Apr 2016 11\:15\:41 +1200 \(1 hour\, 34 minutes\, 33 seconds ago\)"
[-- Attachment #1: Type: text/plain, Size: 452 bytes --]
Steve Purcell <steve@sanityinc.com> writes:
> I'm on OS X 10.11.4, and the patch applies cleanly for me but
> doesn't compile:
>
> CC sysdep.o
> sysdep.c:3607:16: error: variable has incomplete type 'struct
> gcpro'
> struct gcpro gcpro1, gcpro2;
Right, here's a new version, without the gcpro stuff. If I
understand correctly, those things were removed since I wrote the
first version of the patch, and are not necessary any more.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Implement-process-attributes-for-Darwin.patch --]
[-- Type: text/x-patch, Size: 4368 bytes --]
From 0bc6119d618bcfec99ab3ef16739472f8628abe4 Mon Sep 17 00:00:00 2001
From: Magnus Henoch <magnus.henoch@gmail.com>
Date: Sun, 15 Nov 2015 02:05:00 +0000
Subject: [PATCH] Implement process-attributes for Darwin
Mostly copied from the FreeBSD implementation, but it's different enough
to warrant a separate preprocessor if clause.
---
src/sysdep.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 135 insertions(+)
diff --git a/src/sysdep.c b/src/sysdep.c
index 3faa696..50e0b01 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -3567,6 +3567,141 @@ system_process_attributes (Lisp_Object pid)
return attrs;
}
+#elif defined DARWIN_OS
+
+static struct timespec
+timeval_to_timespec (struct timeval t)
+{
+ return make_timespec (t.tv_sec, t.tv_usec * 1000);
+}
+
+static Lisp_Object
+make_lisp_timeval (struct timeval t)
+{
+ return make_lisp_time (timeval_to_timespec (t));
+}
+
+Lisp_Object
+system_process_attributes (Lisp_Object pid)
+{
+ int proc_id;
+ int pagesize = getpagesize ();
+ unsigned long npages;
+ int fscale;
+ struct passwd *pw;
+ struct group *gr;
+ char *ttyname;
+ size_t len;
+ char args[MAXPATHLEN];
+ 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;
+
+ Lisp_Object attrs = Qnil;
+ Lisp_Object decoded_comm;
+
+ CHECK_NUMBER_OR_FLOAT (pid);
+ CONS_TO_INTEGER (pid, int, proc_id);
+ mib[3] = proc_id;
+
+ if (sysctl (mib, 4, &proc, &proclen, NULL, 0) != 0)
+ return attrs;
+
+ uid = proc.kp_eproc.e_ucred.cr_uid;
+ attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid)), attrs);
+
+ block_input ();
+ pw = getpwuid (uid);
+ unblock_input ();
+ if (pw)
+ attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs);
+
+ gid = proc.kp_eproc.e_pcred.p_svgid;
+ attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid)), attrs);
+
+ block_input ();
+ gr = getgrgid (gid);
+ unblock_input ();
+ if (gr)
+ attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs);
+
+ decoded_comm = (code_convert_string_norecord
+ (build_unibyte_string (proc.kp_proc.p_comm),
+ Vlocale_coding_system, 0));
+
+ attrs = Fcons (Fcons (Qcomm, decoded_comm), attrs);
+ {
+ char state[2] = {'\0', '\0'};
+ switch (proc.kp_proc.p_stat)
+ {
+ case SRUN:
+ state[0] = 'R';
+ break;
+
+ case SSLEEP:
+ state[0] = 'S';
+ break;
+
+ case SZOMB:
+ state[0] = 'Z';
+ break;
+
+ case SSTOP:
+ state[0] = 'T';
+ break;
+
+ case SIDL:
+ state[0] = 'I';
+ break;
+ }
+ attrs = Fcons (Fcons (Qstate, build_string (state)), attrs);
+ }
+
+ attrs = Fcons (Fcons (Qppid, make_fixnum_or_float (proc.kp_eproc.e_ppid)), attrs);
+ attrs = Fcons (Fcons (Qpgrp, make_fixnum_or_float (proc.kp_eproc.e_pgid)), attrs);
+
+ tdev = proc.kp_eproc.e_tdev;
+ block_input ();
+ ttyname = tdev == NODEV ? NULL : devname (tdev, S_IFCHR);
+ unblock_input ();
+ if (ttyname)
+ attrs = Fcons (Fcons (Qtty, build_string (ttyname)), attrs);
+
+ attrs = Fcons (Fcons (Qtpgid, make_fixnum_or_float (proc.kp_eproc.e_tpgid)), attrs);
+
+ rusage = proc.kp_proc.p_ru;
+ if (rusage)
+ {
+ attrs = Fcons (Fcons (Qminflt, make_fixnum_or_float (rusage->ru_minflt)), attrs);
+ attrs = Fcons (Fcons (Qmajflt, make_fixnum_or_float (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);
+ }
+
+ starttime = proc.kp_proc.p_starttime;
+ attrs = Fcons (Fcons (Qnice, make_number (proc.kp_proc.p_nice)), attrs);
+ attrs = Fcons (Fcons (Qstart, make_lisp_timeval (starttime)), attrs);
+
+ now = current_timespec ();
+ t = timespec_sub (now, timeval_to_timespec (starttime));
+ attrs = Fcons (Fcons (Qetime, make_lisp_time (t)), attrs);
+
+ return attrs;
+}
+
/* The WINDOWSNT implementation is in w32.c.
The MSDOS implementation is in dosfns.c. */
#elif !defined (WINDOWSNT) && !defined (MSDOS)
--
2.8.1
next prev parent reply other threads:[~2016-04-23 0:53 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-28 18:19 bug#16579: 24.3.50; Implement system_process_attributes on Darwin Magnus Henoch
2015-11-16 22:39 ` bug#16579: Nicer patch Magnus Henoch
2015-11-17 4:07 ` Ivan Andrus
2016-02-24 3:29 ` bug#16579: 24.3.50; Implement system_process_attributes on Darwin Lars Ingebrigtsen
2016-04-22 23:15 ` Steve Purcell
2016-04-23 0:53 ` Magnus Henoch [this message]
2016-04-23 3:05 ` Steve Purcell
2016-04-24 12:33 ` Lars Magne Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m1lh45qh6p.fsf@mail.gmail.com \
--to=magnus.henoch@gmail.com \
--cc=16579@debbugs.gnu.org \
--cc=larsi@gnus.org \
--cc=steve@sanityinc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).