From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ivan Andrus Newsgroups: gmane.emacs.bugs Subject: bug#16579: Nicer patch Date: Mon, 16 Nov 2015 21:07:12 -0700 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Mac OS X Mail 9.1 \(3096.5\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1447733300 24311 80.91.229.3 (17 Nov 2015 04:08:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 17 Nov 2015 04:08:20 +0000 (UTC) Cc: 16579@debbugs.gnu.org To: Magnus Henoch Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Nov 17 05:08:10 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZyXYw-0002kf-Ck for geb-bug-gnu-emacs@m.gmane.org; Tue, 17 Nov 2015 05:08:10 +0100 Original-Received: from localhost ([::1]:55565 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyXYv-0001Sb-UZ for geb-bug-gnu-emacs@m.gmane.org; Mon, 16 Nov 2015 23:08:09 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54368) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyXYr-0001S8-PO for bug-gnu-emacs@gnu.org; Mon, 16 Nov 2015 23:08:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZyXYo-0006z8-Hr for bug-gnu-emacs@gnu.org; Mon, 16 Nov 2015 23:08:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51000) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyXYo-0006z4-DZ for bug-gnu-emacs@gnu.org; Mon, 16 Nov 2015 23:08:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1ZyXYn-0006qu-V8 for bug-gnu-emacs@gnu.org; Mon, 16 Nov 2015 23:08:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Ivan Andrus Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 17 Nov 2015 04:08:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16579 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 16579-submit@debbugs.gnu.org id=B16579.144773323726289 (code B ref 16579); Tue, 17 Nov 2015 04:08:01 +0000 Original-Received: (at 16579) by debbugs.gnu.org; 17 Nov 2015 04:07:17 +0000 Original-Received: from localhost ([127.0.0.1]:40708 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZyXY4-0006px-H5 for submit@debbugs.gnu.org; Mon, 16 Nov 2015 23:07:17 -0500 Original-Received: from mail-ig0-f170.google.com ([209.85.213.170]:33632) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZyXY2-0006po-GD for 16579@debbugs.gnu.org; Mon, 16 Nov 2015 23:07:15 -0500 Original-Received: by igvi2 with SMTP id i2so89569937igv.0 for <16579@debbugs.gnu.org>; Mon, 16 Nov 2015 20:07:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=XyvFBwT+2d9PZIMSfZoAwGx7HRnSKaIKBGCBg+5MDGg=; b=KcZDkIdcE+pnlbnJu2jnbnSr5qQO055/GkCey6SfLO8rqGNQe2WsxKLbeYKYZyMNze /otmCaHsV54nonOZXUImHHZW/kq+dh77DtDf4Mlnh9gaYIZrYNBkz05FAoO9rHaJgjx2 PsDruyxDvMW4htilT9i/BH0uL5rSRfQ5bE8rWsd3cPsn0A7vrTSimqvgzmdNlXokMZIv xPoBl/GefyG1PDCqvWIPEdwUVDBdqSSz6SEOioxKRznwtPjRJIwhF2VLW7zo2CCREc1u agJ1MUvOlwgHPPWHf94vHm90hqyLTF0l9tvZhsj0rcNok0cQ7vQ0hrMMufSi56Axd0dc T2vQ== X-Received: by 10.50.46.36 with SMTP id s4mr20436501igm.84.1447733233883; Mon, 16 Nov 2015 20:07:13 -0800 (PST) Original-Received: from [192.168.0.3] (75-162-226-147.slkc.qwest.net. [75.162.226.147]) by smtp.gmail.com with ESMTPSA id om7sm7462903igb.21.2015.11.16.20.07.13 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Nov 2015 20:07:13 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.3096.5) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:108809 Archived-At: I=E2=80=99ve been using your previous patch for a while and I think it = would be great to have this feature in. I=E2=80=99m a very casual = contributor, so I can=E2=80=99t say go ahead, but I think it would be = great to have. I haven=E2=80=99t found any problems with it (though I = don=E2=80=99t use proced all that often=E2=80=94partly because it never = worked until I found this patch). -Ivan > On Nov 16, 2015, at 3:39 PM, Magnus Henoch = wrote: >=20 > So I had another look at this, and realised that the patch looks = pretty ugly, being all interleaved with the FreeBSD code... Here's = another patch, that just adds a new section for Darwin. I feel much = better about it now. >=20 > Any thoughts or objections? >=20 > Regards, > Magnus > =46rom 6ab30d39b18027e141000446561d7a211776c681 Mon Sep 17 00:00:00 = 2001 > From: Magnus Henoch > Date: Sun, 15 Nov 2015 02:05:00 +0000 > Subject: [PATCH] Implement process-attributes for Darwin >=20 > Mostly copied from the FreeBSD implementation, but it's different = enough > to warrant a separate preprocessor if clause. > --- > src/sysdep.c | 139 = +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 139 insertions(+) >=20 > diff --git a/src/sysdep.c b/src/sysdep.c > index 91036f0..f2b2b16 100644 > --- a/src/sysdep.c > +++ b/src/sysdep.c > @@ -3512,6 +3512,145 @@ system_process_attributes (Lisp_Object pid) > return attrs; > } >=20 > +#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 =3D 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] =3D {CTL_KERN, KERN_PROC, KERN_PROC_PID}; > + struct kinfo_proc proc; > + size_t proclen =3D sizeof proc; > + > + struct gcpro gcpro1, gcpro2; > + Lisp_Object attrs =3D Qnil; > + Lisp_Object decoded_comm; > + > + CHECK_NUMBER_OR_FLOAT (pid); > + CONS_TO_INTEGER (pid, int, proc_id); > + mib[3] =3D proc_id; > + > + if (sysctl (mib, 4, &proc, &proclen, NULL, 0) !=3D 0) > + return attrs; > + > + GCPRO2 (attrs, decoded_comm); > + > + uid =3D proc.kp_eproc.e_ucred.cr_uid; > + attrs =3D Fcons (Fcons (Qeuid, make_fixnum_or_float (uid)), attrs); > + > + block_input (); > + pw =3D getpwuid (uid); > + unblock_input (); > + if (pw) > + attrs =3D Fcons (Fcons (Quser, build_string (pw->pw_name)), = attrs); > + > + gid =3D proc.kp_eproc.e_pcred.p_svgid; > + attrs =3D Fcons (Fcons (Qegid, make_fixnum_or_float (gid)), attrs); > + > + block_input (); > + gr =3D getgrgid (gid); > + unblock_input (); > + if (gr) > + attrs =3D Fcons (Fcons (Qgroup, build_string (gr->gr_name)), = attrs); > + > + decoded_comm =3D (code_convert_string_norecord > + (build_unibyte_string (proc.kp_proc.p_comm), > + Vlocale_coding_system, 0)); > + > + attrs =3D Fcons (Fcons (Qcomm, decoded_comm), attrs); > + { > + char state[2] =3D {'\0', '\0'}; > + switch (proc.kp_proc.p_stat) > + { > + case SRUN: > + state[0] =3D 'R'; > + break; > + > + case SSLEEP: > + state[0] =3D 'S'; > + break; > + > + case SZOMB: > + state[0] =3D 'Z'; > + break; > + > + case SSTOP: > + state[0] =3D 'T'; > + break; > + > + case SIDL: > + state[0] =3D 'I'; > + break; > + } > + attrs =3D Fcons (Fcons (Qstate, build_string (state)), attrs); > + } > + > + attrs =3D Fcons (Fcons (Qppid, make_fixnum_or_float = (proc.kp_eproc.e_ppid)), attrs); > + attrs =3D Fcons (Fcons (Qpgrp, make_fixnum_or_float = (proc.kp_eproc.e_pgid)), attrs); > + > + tdev =3D proc.kp_eproc.e_tdev; > + block_input (); > + ttyname =3D tdev =3D=3D NODEV ? NULL : devname (tdev, S_IFCHR); > + unblock_input (); > + if (ttyname) > + attrs =3D Fcons (Fcons (Qtty, build_string (ttyname)), attrs); > + > + attrs =3D Fcons (Fcons (Qtpgid, make_fixnum_or_float = (proc.kp_eproc.e_tpgid)), attrs); > + > + rusage =3D proc.kp_proc.p_ru; > + if (rusage) > + { > + attrs =3D Fcons (Fcons (Qminflt, make_fixnum_or_float = (rusage->ru_minflt)), attrs); > + attrs =3D Fcons (Fcons (Qmajflt, make_fixnum_or_float = (rusage->ru_majflt)), attrs); > + > + attrs =3D Fcons (Fcons (Qutime, make_lisp_timeval = (rusage->ru_utime)), > + attrs); > + attrs =3D Fcons (Fcons (Qstime, make_lisp_timeval = (rusage->ru_stime)), > + attrs); > + t =3D timespec_add (timeval_to_timespec (rusage->ru_utime), > + timeval_to_timespec (rusage->ru_stime)); > + attrs =3D Fcons (Fcons (Qtime, make_lisp_time (t)), attrs); > + } > + > + starttime =3D proc.kp_proc.p_starttime; > + attrs =3D Fcons (Fcons (Qnice, make_number (proc.kp_proc.p_nice)), = attrs); > + attrs =3D Fcons (Fcons (Qstart, make_lisp_timeval (starttime)), = attrs); > + > + now =3D current_timespec (); > + t =3D timespec_sub (now, timeval_to_timespec (starttime)); > + attrs =3D Fcons (Fcons (Qetime, make_lisp_time (t)), attrs); > + > + UNGCPRO; > + return attrs; > +} > + > /* The WINDOWSNT implementation is in w32.c. > The MSDOS implementation is in dosfns.c. */ > #elif !defined (WINDOWSNT) && !defined (MSDOS) > --=20 > 2.2.1 >=20