From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Magnus Henoch Newsgroups: gmane.emacs.bugs Subject: bug#16579: 24.3.50; Implement system_process_attributes on Darwin Date: Sat, 23 Apr 2016 01:53:18 +0100 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1461372865 21577 80.91.229.3 (23 Apr 2016 00:54:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 23 Apr 2016 00:54:25 +0000 (UTC) Cc: Lars Ingebrigtsen , Magnus Henoch , 16579@debbugs.gnu.org To: Steve Purcell Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Apr 23 02:54:14 2016 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 1atlpr-0007bV-FT for geb-bug-gnu-emacs@m.gmane.org; Sat, 23 Apr 2016 02:54:11 +0200 Original-Received: from localhost ([::1]:42912 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1atlpq-0001Vj-V1 for geb-bug-gnu-emacs@m.gmane.org; Fri, 22 Apr 2016 20:54:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54486) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1atlpm-0001S7-2w for bug-gnu-emacs@gnu.org; Fri, 22 Apr 2016 20:54:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1atlpi-0005Va-RS for bug-gnu-emacs@gnu.org; Fri, 22 Apr 2016 20:54:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:59405) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1atlpi-0005VW-GV for bug-gnu-emacs@gnu.org; Fri, 22 Apr 2016 20:54:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1atlpi-0007do-As for bug-gnu-emacs@gnu.org; Fri, 22 Apr 2016 20:54:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Magnus Henoch Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 23 Apr 2016 00:54:02 +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.146137280929331 (code B ref 16579); Sat, 23 Apr 2016 00:54:02 +0000 Original-Received: (at 16579) by debbugs.gnu.org; 23 Apr 2016 00:53:29 +0000 Original-Received: from localhost ([127.0.0.1]:43509 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1atlpB-0007d1-IJ for submit@debbugs.gnu.org; Fri, 22 Apr 2016 20:53:29 -0400 Original-Received: from mail-wm0-f66.google.com ([74.125.82.66]:34423) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1atlpA-0007co-3M for 16579@debbugs.gnu.org; Fri, 22 Apr 2016 20:53:28 -0400 Original-Received: by mail-wm0-f66.google.com with SMTP id n3so8803900wmn.1 for <16579@debbugs.gnu.org>; Fri, 22 Apr 2016 17:53:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:in-reply-to:message-id:mime-version; bh=oxvw86ziHOouYJ1G1d5Ji/ZF+uMTzgMoJRclspjXL3M=; b=A60GGwhu8V6pNxlsJKALsnfesQqJvI/7nHj7Tg9rpzbaT/WmoPCtH/EJwdV5BxItf9 RqPlT1akOJ7FqSZquTToM6S4p3t3vj8TyaARlYtDMmDA33ryQof6G+XJzG7zUIzuKAxr rGHnx0ZCS+OmEhjV1b3y6M8EDER19A1upFf2W0ZHJdTdE+FdPMHFYRNzeBoA+PkD2m6Y jH/07DYjr+xRP/kmDqoJSM+FN9PCAVdohmOxzE4iPdGqU+uObP4LKsHMOGAqLBAHjp/N DDfbOBOTJ1TMo9lJRwrm3rUnYkPQGKkjAROOlOKwQTJ2eJs247H6zoqOqiQKuly0Htr3 DOWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:in-reply-to:message-id :mime-version; bh=oxvw86ziHOouYJ1G1d5Ji/ZF+uMTzgMoJRclspjXL3M=; b=EQDDnQ6Lvbr41r1TiaEkqhziWIMauuCexOjvFPnPZrmNmzwu1JYTyi58tly1pFZgU4 Mt+mAh+FgmaHIXLAIU4wJJfQQgdhodKFTPR0vBjps7bz6Qr3AbVEBuWURhO8ONB9n4YO ATxaZOOC0wbYkd7NzwnkFmdjmoRWrczhv6D0YmSyt7bLml4TrWCIqoiEMVpXqBIHdpw1 gho5+Jj6s9mRXZg0nOy/++JH2GYsvvhuq+ViUrImeZOaKhvhkUxrfOTT76wNg2fliVX7 xWdjFOcpDlPVGhIrxq3J+gE7KBzoyFHlr+w8ioAeev/ruT40DDf4+aCZ2xB3mXINOLRQ Vugg== X-Gm-Message-State: AOPr4FWuJS583X7YIjaMBw2DqyUBC8AsW9VOQeG1DVdBHyMZzDDkeSgxQ2ooRMWyVAIgkw== X-Received: by 10.194.60.134 with SMTP id h6mr23028905wjr.115.1461372802379; Fri, 22 Apr 2016 17:53:22 -0700 (PDT) Original-Received: from poki-sona-sin.local ([176.52.163.106]) by smtp.gmail.com with ESMTPSA id e12sm5795729wma.15.2016.04.22.17.53.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Apr 2016 17:53:21 -0700 (PDT) In-Reply-To: Steve Purcell's message of "Sat\, 23 Apr 2016 11\:15\:41 +1200 \(1 hour\, 34 minutes\, 33 seconds ago\)" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] 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" Xref: news.gmane.org gmane.emacs.bugs:116687 Archived-At: --=-=-= Content-Type: text/plain; format=flowed Steve Purcell 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. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Implement-process-attributes-for-Darwin.patch >From 0bc6119d618bcfec99ab3ef16739472f8628abe4 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 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 --=-=-=--