pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

py-psutil: import version 5.4.3 with patches from DragonFly dports



Module Name:	pkgsrc-wip
Committed By:	Aleksej Lebedev <root%zta.lk@localhost>
Pushed By:	zhtw
Date:		Fri Feb 9 17:58:07 2018 +0100
Changeset:	f61c648eca2ca366682c22e7a5a685f58a136895

Added Files:
	py-psutil/DESCR
	py-psutil/Makefile
	py-psutil/PLIST
	py-psutil/distinfo
	py-psutil/patches/patch-psutil_____init____.py
	py-psutil/patches/patch-psutil___common.py
	py-psutil/patches/patch-psutil___psbsd.py
	py-psutil/patches/patch-psutil___psutil__bsd.c
	py-psutil/patches/patch-psutil_arch_bsd_dragonfly.c
	py-psutil/patches/patch-psutil_arch_bsd_dragonfly.h
	py-psutil/patches/patch-setup.py

Log Message:
py-psutil: import version 5.4.3 with patches from DragonFly dports

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=f61c648eca2ca366682c22e7a5a685f58a136895

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 py-psutil/DESCR                                    |   6 +
 py-psutil/Makefile                                 |  38 ++
 py-psutil/PLIST                                    |  90 ++++
 py-psutil/distinfo                                 |  13 +
 py-psutil/patches/patch-psutil_____init____.py     |  21 +
 py-psutil/patches/patch-psutil___common.py         |  23 +
 py-psutil/patches/patch-psutil___psbsd.py          |  12 +
 py-psutil/patches/patch-psutil___psutil__bsd.c     |  62 +++
 .../patches/patch-psutil_arch_bsd_dragonfly.c      | 567 +++++++++++++++++++++
 .../patches/patch-psutil_arch_bsd_dragonfly.h      |  32 ++
 py-psutil/patches/patch-setup.py                   |  30 ++
 11 files changed, 894 insertions(+)

diffs:
diff --git a/py-psutil/DESCR b/py-psutil/DESCR
new file mode 100644
index 0000000000..83fd074786
--- /dev/null
+++ b/py-psutil/DESCR
@@ -0,0 +1,6 @@
+util is a module providing an interface for retrieving information,
+on all running processes and system utilization (CPU, memory, disks,
+network, users) in a portable way by using Python, implementing
+many functionalities offered by command line tools such as ps, top,
+df, netstat, who, kill, uptime, free, lsof, ifconfig, nice, ionice,
+iostat, iotop, pidof, tty, taskset, or pmap.
diff --git a/py-psutil/Makefile b/py-psutil/Makefile
new file mode 100644
index 0000000000..b7cf772c8e
--- /dev/null
+++ b/py-psutil/Makefile
@@ -0,0 +1,38 @@
+# $NetBSD: Makefile,v 1.20 2017/05/29 16:02:40 adam Exp $
+
+DISTNAME=	psutil-5.4.3
+PKGNAME=	${PYPKGPREFIX}-${DISTNAME}
+CATEGORIES=	sysutils
+MASTER_SITES=	${MASTER_SITE_PYPI:=p/psutil/}
+
+MAINTAINER=	pkgsrc-users%NetBSD.org@localhost
+HOMEPAGE=	https://github.com/giampaolo/psutil
+COMMENT=	Cross-platform process and system utilities module for Python
+LICENSE=	modified-bsd
+
+USE_LANGUAGES=		c
+
+.include "../../lang/python/pyversion.mk"
+
+.if "${PYPKGPREFIX}" == "py27"
+BUILD_DEPENDS+=	${PYPKGPREFIX}-ipaddress-[0-9]*:../../net/py-ipaddress
+.endif
+BUILD_DEPENDS+=	${PYPKGPREFIX}-mock-[0-9]*:../../devel/py-mock
+BUILD_DEPENDS+=	${PYPKGPREFIX}-unittest2-[0-9]*:../../devel/py-unittest2
+
+REPLACE_PYTHON=	psutil/*py
+
+.include "../../mk/bsd.prefs.mk"
+
+# facilitate PLIST processing
+.if ${OPSYS} == "Darwin"
+PLIST_SUBST+=	SYSTEM=osx
+.elif !empty(OPSYS:M*BSD) || ${OPSYS} == "DragonFly"
+PLIST_SUBST+=	SYSTEM=bsd
+.else
+PLIST_SUBST+=	SYSTEM=${OPSYS:tl}
+.endif
+
+.include "../../lang/python/application.mk"
+.include "../../lang/python/egg.mk"
+.include "../../mk/bsd.pkg.mk"
diff --git a/py-psutil/PLIST b/py-psutil/PLIST
new file mode 100644
index 0000000000..fe14343968
--- /dev/null
+++ b/py-psutil/PLIST
@@ -0,0 +1,90 @@
+@comment $NetBSD$
+${PYSITELIB}/${EGG_INFODIR}/PKG-INFO
+${PYSITELIB}/${EGG_INFODIR}/SOURCES.txt
+${PYSITELIB}/${EGG_INFODIR}/dependency_links.txt
+${PYSITELIB}/${EGG_INFODIR}/not-zip-safe
+${PYSITELIB}/${EGG_INFODIR}/requires.txt
+${PYSITELIB}/${EGG_INFODIR}/top_level.txt
+${PYSITELIB}/psutil/__init__.py
+${PYSITELIB}/psutil/__init__.pyc
+${PYSITELIB}/psutil/__init__.pyo
+${PYSITELIB}/psutil/_common.py
+${PYSITELIB}/psutil/_common.pyc
+${PYSITELIB}/psutil/_common.pyo
+${PYSITELIB}/psutil/_compat.py
+${PYSITELIB}/psutil/_compat.pyc
+${PYSITELIB}/psutil/_compat.pyo
+${PYSITELIB}/psutil/_exceptions.py
+${PYSITELIB}/psutil/_exceptions.pyc
+${PYSITELIB}/psutil/_exceptions.pyo
+${PYSITELIB}/psutil/_psaix.py
+${PYSITELIB}/psutil/_psaix.pyc
+${PYSITELIB}/psutil/_psaix.pyo
+${PYSITELIB}/psutil/_psbsd.py
+${PYSITELIB}/psutil/_psbsd.pyc
+${PYSITELIB}/psutil/_psbsd.pyo
+${PYSITELIB}/psutil/_pslinux.py
+${PYSITELIB}/psutil/_pslinux.pyc
+${PYSITELIB}/psutil/_pslinux.pyo
+${PYSITELIB}/psutil/_psosx.py
+${PYSITELIB}/psutil/_psosx.pyc
+${PYSITELIB}/psutil/_psosx.pyo
+${PYSITELIB}/psutil/_psposix.py
+${PYSITELIB}/psutil/_psposix.pyc
+${PYSITELIB}/psutil/_psposix.pyo
+${PYSITELIB}/psutil/_pssunos.py
+${PYSITELIB}/psutil/_pssunos.pyc
+${PYSITELIB}/psutil/_pssunos.pyo
+${PYSITELIB}/psutil/_psutil_${SYSTEM}.so
+${PYSITELIB}/psutil/_psutil_posix.so
+${PYSITELIB}/psutil/_pswindows.py
+${PYSITELIB}/psutil/_pswindows.pyc
+${PYSITELIB}/psutil/_pswindows.pyo
+${PYSITELIB}/psutil/tests/__init__.py
+${PYSITELIB}/psutil/tests/__init__.pyc
+${PYSITELIB}/psutil/tests/__init__.pyo
+${PYSITELIB}/psutil/tests/__main__.py
+${PYSITELIB}/psutil/tests/__main__.pyc
+${PYSITELIB}/psutil/tests/__main__.pyo
+${PYSITELIB}/psutil/tests/test_aix.py
+${PYSITELIB}/psutil/tests/test_aix.pyc
+${PYSITELIB}/psutil/tests/test_aix.pyo
+${PYSITELIB}/psutil/tests/test_bsd.py
+${PYSITELIB}/psutil/tests/test_bsd.pyc
+${PYSITELIB}/psutil/tests/test_bsd.pyo
+${PYSITELIB}/psutil/tests/test_connections.py
+${PYSITELIB}/psutil/tests/test_connections.pyc
+${PYSITELIB}/psutil/tests/test_connections.pyo
+${PYSITELIB}/psutil/tests/test_contracts.py
+${PYSITELIB}/psutil/tests/test_contracts.pyc
+${PYSITELIB}/psutil/tests/test_contracts.pyo
+${PYSITELIB}/psutil/tests/test_linux.py
+${PYSITELIB}/psutil/tests/test_linux.pyc
+${PYSITELIB}/psutil/tests/test_linux.pyo
+${PYSITELIB}/psutil/tests/test_memory_leaks.py
+${PYSITELIB}/psutil/tests/test_memory_leaks.pyc
+${PYSITELIB}/psutil/tests/test_memory_leaks.pyo
+${PYSITELIB}/psutil/tests/test_misc.py
+${PYSITELIB}/psutil/tests/test_misc.pyc
+${PYSITELIB}/psutil/tests/test_misc.pyo
+${PYSITELIB}/psutil/tests/test_osx.py
+${PYSITELIB}/psutil/tests/test_osx.pyc
+${PYSITELIB}/psutil/tests/test_osx.pyo
+${PYSITELIB}/psutil/tests/test_posix.py
+${PYSITELIB}/psutil/tests/test_posix.pyc
+${PYSITELIB}/psutil/tests/test_posix.pyo
+${PYSITELIB}/psutil/tests/test_process.py
+${PYSITELIB}/psutil/tests/test_process.pyc
+${PYSITELIB}/psutil/tests/test_process.pyo
+${PYSITELIB}/psutil/tests/test_sunos.py
+${PYSITELIB}/psutil/tests/test_sunos.pyc
+${PYSITELIB}/psutil/tests/test_sunos.pyo
+${PYSITELIB}/psutil/tests/test_system.py
+${PYSITELIB}/psutil/tests/test_system.pyc
+${PYSITELIB}/psutil/tests/test_system.pyo
+${PYSITELIB}/psutil/tests/test_unicode.py
+${PYSITELIB}/psutil/tests/test_unicode.pyc
+${PYSITELIB}/psutil/tests/test_unicode.pyo
+${PYSITELIB}/psutil/tests/test_windows.py
+${PYSITELIB}/psutil/tests/test_windows.pyc
+${PYSITELIB}/psutil/tests/test_windows.pyo
diff --git a/py-psutil/distinfo b/py-psutil/distinfo
new file mode 100644
index 0000000000..8251033b4b
--- /dev/null
+++ b/py-psutil/distinfo
@@ -0,0 +1,13 @@
+$NetBSD: distinfo,v 1.20 2017/06/24 08:03:35 adam Exp $
+
+SHA1 (psutil-5.4.3.tar.gz) = 51ce815e89073bcbcd73c2a5e0e852d18f3a7b6d
+RMD160 (psutil-5.4.3.tar.gz) = 5e213c1ed1ed454bf41996069d0602dff629acf2
+SHA512 (psutil-5.4.3.tar.gz) = f2a0f3089c3436df52d509576795e1de14c4127918fbe63b8f116f7c097ba4d67e3b55a8da167a88c6ffd340bb443109d4887c03371810997ced4478b295f960
+Size (psutil-5.4.3.tar.gz) = 412550 bytes
+SHA1 (patch-psutil_____init____.py) = 5adb9779e4bbefef3e5cbb67c86cc1c3b0d09a7b
+SHA1 (patch-psutil___common.py) = e3835f65f14aa28f8b8c9ad72a54cc77432b4d1e
+SHA1 (patch-psutil___psbsd.py) = 6d30e3b2a2e8f34e65fcbc34dc7b497849b1d7f7
+SHA1 (patch-psutil___psutil__bsd.c) = 205abeddb453cbcf4e23cba41fbacfbc97815aea
+SHA1 (patch-psutil_arch_bsd_dragonfly.c) = e7b55b6097e3c4ba84d59e5ff9e9f0fe16853df1
+SHA1 (patch-psutil_arch_bsd_dragonfly.h) = b39e28cfcbc1ed5b121ea1c1c8efdb306361254f
+SHA1 (patch-setup.py) = d2e4bf22a733889f74c3959894bda10e478bc186
diff --git a/py-psutil/patches/patch-psutil_____init____.py b/py-psutil/patches/patch-psutil_____init____.py
new file mode 100644
index 0000000000..4f8c694a79
--- /dev/null
+++ b/py-psutil/patches/patch-psutil_____init____.py
@@ -0,0 +1,21 @@
+$NetBSD$
+
+--- psutil/__init__.py.orig	2017-12-09 11:29:06.000000000 +0000
++++ psutil/__init__.py
+@@ -81,6 +81,7 @@ from ._common import FREEBSD  # NOQA
+ from ._common import LINUX
+ from ._common import NETBSD  # NOQA
+ from ._common import OPENBSD  # NOQA
++from ._common import DRAGONFLY # NOQA
+ from ._common import OSX
+ from ._common import POSIX  # NOQA
+ from ._common import SUNOS
+@@ -201,7 +202,7 @@ __all__ = [
+     "POWER_TIME_UNKNOWN", "POWER_TIME_UNLIMITED",
+ 
+     "BSD", "FREEBSD", "LINUX", "NETBSD", "OPENBSD", "OSX", "POSIX", "SUNOS",
+-    "WINDOWS", "AIX",
++    "WINDOWS", "AIX", "DRAGONFLY"
+ 
+     # classes
+     "Process", "Popen",
diff --git a/py-psutil/patches/patch-psutil___common.py b/py-psutil/patches/patch-psutil___common.py
new file mode 100644
index 0000000000..ff1b2e3d57
--- /dev/null
+++ b/py-psutil/patches/patch-psutil___common.py
@@ -0,0 +1,23 @@
+$NetBSD$
+
+--- psutil/_common.py.orig	2017-12-07 10:02:52.000000000 +0000
++++ psutil/_common.py
+@@ -43,7 +43,7 @@ PY3 = sys.version_info[0] == 3
+ __all__ = [
+     # constants
+     'FREEBSD', 'BSD', 'LINUX', 'NETBSD', 'OPENBSD', 'OSX', 'POSIX', 'SUNOS',
+-    'WINDOWS',
++    'WINDOWS', 'DRAGONFLY',
+     'ENCODING', 'ENCODING_ERRS', 'AF_INET6',
+     # connection constants
+     'CONN_CLOSE', 'CONN_CLOSE_WAIT', 'CONN_CLOSING', 'CONN_ESTABLISHED',
+@@ -79,7 +79,8 @@ OSX = sys.platform.startswith("darwin")
+ FREEBSD = sys.platform.startswith("freebsd")
+ OPENBSD = sys.platform.startswith("openbsd")
+ NETBSD = sys.platform.startswith("netbsd")
+-BSD = FREEBSD or OPENBSD or NETBSD
++DRAGONFLY = sys.platform.startswith("dragonfly")
++BSD = FREEBSD or OPENBSD or NETBSD or DRAGONFLY
+ SUNOS = sys.platform.startswith("sunos") or sys.platform.startswith("solaris")
+ AIX = sys.platform.startswith("aix")
+ 
diff --git a/py-psutil/patches/patch-psutil___psbsd.py b/py-psutil/patches/patch-psutil___psbsd.py
new file mode 100644
index 0000000000..70f9f29306
--- /dev/null
+++ b/py-psutil/patches/patch-psutil___psbsd.py
@@ -0,0 +1,12 @@
+$NetBSD$
+
+--- psutil/_psbsd.py.orig	2017-11-12 23:27:06.000000000 +0000
++++ psutil/_psbsd.py
+@@ -23,6 +23,7 @@ from ._common import memoize
+ from ._common import memoize_when_activated
+ from ._common import NETBSD
+ from ._common import OPENBSD
++from ._common import DRAGONFLY
+ from ._common import sockfam_to_enum
+ from ._common import socktype_to_enum
+ from ._common import usage_percent
diff --git a/py-psutil/patches/patch-psutil___psutil__bsd.c b/py-psutil/patches/patch-psutil___psutil__bsd.c
new file mode 100644
index 0000000000..5d22e699c1
--- /dev/null
+++ b/py-psutil/patches/patch-psutil___psutil__bsd.c
@@ -0,0 +1,62 @@
+$NetBSD$
+
+--- psutil/_psutil_bsd.c.orig	2017-11-14 22:49:09.000000000 +0000
++++ psutil/_psutil_bsd.c
+@@ -19,6 +19,7 @@
+     #define _KMEMUSER
+ #endif
+ 
++#include <netinet/in.h>
+ #include <Python.h>
+ #include <assert.h>
+ #include <errno.h>
+@@ -39,7 +40,6 @@
+ #include <sys/un.h>
+ #include <sys/unpcb.h>
+ // for xinpcb struct
+-#include <netinet/in.h>
+ #include <netinet/in_systm.h>
+ #include <netinet/ip.h>
+ #include <netinet/in_pcb.h>
+@@ -94,6 +94,11 @@
+     #ifndef DTYPE_VNODE
+         #define DTYPE_VNODE 1
+     #endif
++#elif PSUTIL_DRAGONFLY
++    #include "arch/bsd/dragonfly.h"
++    #include <sys/resource.h>
++
++    #include <utmpx.h>
+ #endif
+ 
+ 
+@@ -231,6 +236,12 @@ psutil_proc_oneshot_info(PyObject *self,
+     memtext = (long)kp.ki_tsize * pagesize;
+     memdata = (long)kp.ki_dsize * pagesize;
+     memstack = (long)kp.ki_ssize * pagesize;
++#elif PSUTIL_DRAGONFLY
++    rss = (long)kp.kp_vm_rssize * pagesize;
++    vms = (long)kp.kp_vm_map_size;
++    memtext = (long)kp.kp_vm_tsize * pagesize;
++    memdata = (long)kp.kp_vm_dsize * pagesize;
++    memstack = (long)kp.kp_vm_ssize * pagesize;
+ #else
+     rss = (long)kp.p_vm_rssize * pagesize;
+     #ifdef PSUTIL_OPENBSD
+@@ -425,7 +436,7 @@ psutil_cpu_times(PyObject *self, PyObjec
+     size_t size = sizeof(cpu_time);
+     int ret;
+ 
+-#if defined(PSUTIL_FREEBSD) || defined(PSUTIL_NETBSD)
++#if defined(PSUTIL_FREEBSD) || defined(PSUTIL_NETBSD) || defined(PSUTIL_DRAGONFLY)
+     ret = sysctlbyname("kern.cp_time", &cpu_time, &size, NULL, 0);
+ #elif PSUTIL_OPENBSD
+     int mib[] = {CTL_KERN, KERN_CPTIME};
+@@ -433,6 +444,7 @@ psutil_cpu_times(PyObject *self, PyObjec
+ #endif
+     if (ret == -1)
+         return PyErr_SetFromErrno(PyExc_OSError);
++
+     return Py_BuildValue("(ddddd)",
+                          (double)cpu_time[CP_USER] / CLOCKS_PER_SEC,
+                          (double)cpu_time[CP_NICE] / CLOCKS_PER_SEC,
diff --git a/py-psutil/patches/patch-psutil_arch_bsd_dragonfly.c b/py-psutil/patches/patch-psutil_arch_bsd_dragonfly.c
new file mode 100644
index 0000000000..9a5332da58
--- /dev/null
+++ b/py-psutil/patches/patch-psutil_arch_bsd_dragonfly.c
@@ -0,0 +1,567 @@
+$NetBSD$
+
+--- psutil/arch/bsd/dragonfly.c.orig	2018-02-09 16:11:41.557735000 +0000
++++ psutil/arch/bsd/dragonfly.c
+@@ -0,0 +1,562 @@
++/*
++ * Copyright (c) 2009, Jay Loden, Giampaolo Rodola'. All rights reserved.
++ * Use of this source code is governed by a BSD-style license that can be
++ * found in the LICENSE file.
++ *
++ * Platform-specific module methods for DragonFly BSD.
++ */
++
++#include <Python.h>
++#include <assert.h>
++#include <errno.h>
++#include <stdlib.h>
++#include <stdio.h>
++#include <string.h>
++#include <sys/types.h>
++#include <sys/sysctl.h>
++#include <sys/param.h>
++#include <sys/user.h>
++#include <sys/proc.h>
++#include <signal.h>
++#include <fcntl.h>
++#include <sys/vmmeter.h>  // needed for vmtotal struct
++#include <devstat.h>  // for swap mem
++#include <libutil.h>  // process open files, shared libs (kinfo_getvmmap), cwd
++#include <kvm.h>
++
++#include "../../_psutil_common.h"
++#include "../../_psutil_posix.h"
++
++#define PSUTIL_TV2DOUBLE(t)    ((t).tv_sec + (t).tv_usec / 1000000.0)
++#define PSUTIL_BT2MSEC(bt) (bt.sec * 1000 + (((uint64_t) 1000000000 * (uint32_t) \
++        (bt.frac >> 32) ) >> 32 ) / 1000000)
++#ifndef _PATH_DEVNULL
++#define _PATH_DEVNULL "/dev/null"
++#endif
++
++
++// ============================================================================
++// Utility functions
++// ============================================================================
++
++
++int
++psutil_kinfo_proc(const pid_t pid, struct kinfo_proc *proc) {
++    // Fills a kinfo_proc struct based on process pid.
++    int mib[4];
++    size_t size;
++    mib[0] = CTL_KERN;
++    mib[1] = KERN_PROC;
++    mib[2] = KERN_PROC_PID;
++    mib[3] = pid;
++
++    size = sizeof(struct kinfo_proc);
++    if (sysctl((int *)mib, 4, proc, &size, NULL, 0) == -1) {
++        PyErr_SetFromErrno(PyExc_OSError);
++        return -1;
++    }
++
++    // sysctl stores 0 in the size if we can't find the process information.
++    if (size == 0) {
++        NoSuchProcess("");
++        return -1;
++    }
++    return 0;
++}
++
++
++// remove spaces from string
++static void psutil_remove_spaces(char *str) {
++    char *p1 = str;
++    char *p2 = str;
++    do
++        while (*p2 == ' ')
++            p2++;
++    while ((*p1++ = *p2++));
++}
++
++
++// ============================================================================
++// APIS
++// ============================================================================
++
++int
++psutil_get_proc_list(struct kinfo_proc **procList, size_t *procCount) {
++    // Returns a list of all BSD processes on the system.  This routine
++    // allocates the list and puts it in *procList and a count of the
++    // number of entries in *procCount.  You are responsible for freeing
++    // this list (use "free" from System framework).
++    // On success, the function returns 0.
++    // On error, the function returns a BSD errno value.
++
++    /* XXX: not implemented */
++
++    *procList = NULL;
++    *procCount = 0;
++
++    return 0;
++}
++
++
++/*
++ * XXX no longer used; it probably makese sense to remove it.
++ * Borrowed from psi Python System Information project
++ *
++ * Get command arguments and environment variables.
++ *
++ * Based on code from ps.
++ *
++ * Returns:
++ *      0 for success;
++ *      -1 for failure (Exception raised);
++ *      1 for insufficient privileges.
++ */
++static char
++*psutil_get_cmd_args(long pid, size_t *argsize) {
++    int mib[4], argmax;
++    size_t size = sizeof(argmax);
++    char *procargs = NULL;
++
++    // Get the maximum process arguments size.
++    mib[0] = CTL_KERN;
++    mib[1] = KERN_ARGMAX;
++
++    size = sizeof(argmax);
++    if (sysctl(mib, 2, &argmax, &size, NULL, 0) == -1)
++        return NULL;
++
++    // Allocate space for the arguments.
++    procargs = (char *)malloc(argmax);
++    if (procargs == NULL) {
++        PyErr_NoMemory();
++        return NULL;
++    }
++
++    /*
++     * Make a sysctl() call to get the raw argument space of the process.
++     */
++    mib[0] = CTL_KERN;
++    mib[1] = KERN_PROC;
++    mib[2] = KERN_PROC_ARGS;
++    mib[3] = pid;
++
++    size = argmax;
++    if (sysctl(mib, 4, procargs, &size, NULL, 0) == -1) {
++        free(procargs);
++        return NULL;       // Insufficient privileges
++    }
++
++    // return string and set the length of arguments
++    *argsize = size;
++    return procargs;
++}
++
++
++// returns the command line as a python list object
++PyObject *
++psutil_get_cmdline(long pid) {
++    char *argstr = NULL;
++    int pos = 0;
++    size_t argsize = 0;
++    PyObject *py_retlist = Py_BuildValue("[]");
++    PyObject *py_arg = NULL;
++
++    if (pid < 0)
++        return py_retlist;
++    argstr = psutil_get_cmd_args(pid, &argsize);
++    if (argstr == NULL)
++        goto error;
++
++    // args are returned as a flattened string with \0 separators between
++    // arguments add each string to the list then step forward to the next
++    // separator
++    if (argsize > 0) {
++        while (pos < argsize) {
++#if PY_MAJOR_VERSION >= 3
++            py_arg = PyUnicode_DecodeFSDefault(&argstr[pos]);
++#else
++            py_arg = Py_BuildValue("s", &argstr[pos]);
++#endif
++            if (!py_arg)
++                goto error;
++            if (PyList_Append(py_retlist, py_arg))
++                goto error;
++            Py_DECREF(py_arg);
++            pos = pos + strlen(&argstr[pos]) + 1;
++        }
++    }
++
++    free(argstr);
++    return py_retlist;
++
++error:
++    Py_XDECREF(py_arg);
++    Py_DECREF(py_retlist);
++    if (argstr != NULL)
++        free(argstr);
++    return NULL;
++}
++
++
++/*
++ * Return process pathname executable.
++ * Thanks to Robert N. M. Watson:
++ * http://fxr.googlebit.com/source/usr.bin/procstat/procstat_bin.c?v=8-CURRENT
++ */
++PyObject *
++psutil_proc_exe(PyObject *self, PyObject *args) {
++    long pid;
++    char pathname[PATH_MAX];
++    int error;
++    int mib[4];
++    int ret;
++    size_t size;
++    const char *encoding_errs;
++
++    if (! PyArg_ParseTuple(args, "l", &pid))
++        return NULL;
++
++    mib[0] = CTL_KERN;
++    mib[1] = KERN_PROC;
++    mib[2] = KERN_PROC_PATHNAME;
++    mib[3] = pid;
++
++    size = sizeof(pathname);
++    error = sysctl(mib, 4, pathname, &size, NULL, 0);
++    if (error == -1) {
++        if (errno == ENOENT) {
++            // see: https://github.com/giampaolo/psutil/issues/907
++            return Py_BuildValue("s", "");
++        }
++        else {
++            PyErr_SetFromErrno(PyExc_OSError);
++            return NULL;
++        }
++    }
++    if (size == 0 || strlen(pathname) == 0) {
++        ret = psutil_pid_exists(pid);
++        if (ret == -1)
++            return NULL;
++        else if (ret == 0)
++            return NoSuchProcess("");
++        else
++            strcpy(pathname, "");
++    }
++
++#if PY_MAJOR_VERSION >= 3
++    return PyUnicode_DecodeFSDefault(pathname);
++#else
++    return Py_BuildValue("s", pathname);
++#endif
++
++}
++
++
++PyObject *
++psutil_proc_num_threads(PyObject *self, PyObject *args) {
++    // Return number of threads used by process as a Python integer.
++    long pid;
++    struct kinfo_proc kp;
++    if (! PyArg_ParseTuple(args, "l", &pid))
++        return NULL;
++    if (psutil_kinfo_proc(pid, &kp) == -1)
++        return NULL;
++    return Py_BuildValue("l", (long)kp.kp_nthreads);
++}
++
++PyObject *
++psutil_proc_connections(PyObject *self, PyObject *args) {
++    /* XXX: not implemented */
++
++    return NULL;
++}
++
++PyObject *
++psutil_proc_threads(PyObject *self, PyObject *args) {
++    // Retrieves all threads used by process returning a list of tuples
++    // including thread id, user time and system time.
++
++    /* XXX: not implemented */
++    return NULL;
++}
++
++
++PyObject *
++psutil_cpu_count_phys(PyObject *self, PyObject *args) {
++    // Return an XML string from which we'll determine the number of
++    // physical CPU cores in the system.
++
++    /* XXX: not implemented */
++    return NULL;
++}
++
++
++/*
++ * Return virtual memory usage statistics.
++ */
++PyObject *
++psutil_virtual_mem(PyObject *self, PyObject *args) {
++    unsigned long  total;
++    unsigned int   active, inactive, wired, cached, free;
++    size_t         size = sizeof(total);
++    struct vmtotal vm;
++    long           pagesize = getpagesize();
++    long buffers;
++    size_t buffers_size = sizeof(buffers);
++
++    if (sysctlbyname("hw.physmem", &total, &size, NULL, 0))
++        goto error;
++    if (sysctlbyname("vm.stats.vm.v_active_count", &active, &size, NULL, 0))
++        goto error;
++    if (sysctlbyname("vm.stats.vm.v_inactive_count",
++                     &inactive, &size, NULL, 0))
++        goto error;
++    if (sysctlbyname("vm.stats.vm.v_wire_count", &wired, &size, NULL, 0))
++        goto error;
++    // https://github.com/giampaolo/psutil/issues/997
++    if (sysctlbyname("vm.stats.vm.v_cache_count", &cached, &size, NULL, 0))
++        cached = 0;
++    if (sysctlbyname("vm.stats.vm.v_free_count", &free, &size, NULL, 0))
++        goto error;
++    if (sysctlbyname("vfs.bufspace", &buffers, &buffers_size, NULL, 0))
++        goto error;
++
++    size = sizeof(vm);
++    if (sysctlbyname("vm.vmtotal", &vm, &size, NULL, 0))
++        goto error;
++
++    return Py_BuildValue("KKKKKKKK",
++        (unsigned long long) total,
++        (unsigned long long) free     * pagesize,
++        (unsigned long long) active   * pagesize,
++        (unsigned long long) inactive * pagesize,
++        (unsigned long long) wired    * pagesize,
++        (unsigned long long) cached   * pagesize,
++        (unsigned long long) buffers,
++        (unsigned long long) (vm.t_vmshr + vm.t_rmshr) * pagesize  // shared
++    );
++
++error:
++    PyErr_SetFromErrno(PyExc_OSError);
++    return NULL;
++}
++
++
++PyObject *
++psutil_swap_mem(PyObject *self, PyObject *args) {
++    // Return swap memory stats (see 'swapinfo' cmdline tool)
++    kvm_t *kd;
++    struct kvm_swap kvmsw[1];
++    unsigned int swapin, swapout, nodein, nodeout;
++    size_t size = sizeof(unsigned int);
++
++    kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, "kvm_open failed");
++    if (kd == NULL) {
++        PyErr_SetString(PyExc_RuntimeError, "kvm_open() syscall failed");
++        return NULL;
++    }
++
++    if (kvm_getswapinfo(kd, kvmsw, 1, 0) < 0) {
++        kvm_close(kd);
++        PyErr_SetString(PyExc_RuntimeError,
++                        "kvm_getswapinfo() syscall failed");
++        return NULL;
++    }
++
++    kvm_close(kd);
++
++    if (sysctlbyname("vm.stats.vm.v_swapin", &swapin, &size, NULL, 0) == -1)
++        goto sbn_error;
++    if (sysctlbyname("vm.stats.vm.v_swapout", &swapout, &size, NULL, 0) == -1)
++        goto sbn_error;
++    if (sysctlbyname("vm.stats.vm.v_vnodein", &nodein, &size, NULL, 0) == -1)
++        goto sbn_error;
++    if (sysctlbyname("vm.stats.vm.v_vnodeout", &nodeout, &size, NULL, 0) == -1)
++        goto sbn_error;
++
++    return Py_BuildValue("(iiiII)",
++                         kvmsw[0].ksw_total,                     // total
++                         kvmsw[0].ksw_used,                      // used
++                         kvmsw[0].ksw_total - kvmsw[0].ksw_used, // free
++                         swapin + swapout,                       // swap in
++                         nodein + nodeout);                      // swap out
++
++sbn_error:
++    PyErr_SetFromErrno(PyExc_OSError);
++    return NULL;
++}
++
++
++PyObject *
++psutil_proc_cwd(PyObject *self, PyObject *args) {
++    /* XXX: not implemented */
++
++    return NULL;
++}
++
++PyObject *
++psutil_proc_num_fds(PyObject *self, PyObject *args) {
++    /* XXX: not implemented */
++
++    return NULL;
++}
++
++PyObject *
++psutil_per_cpu_times(PyObject *self, PyObject *args) {
++    static int maxcpus;
++    int mib[2];
++    int ncpu;
++    size_t len;
++    size_t size;
++    int i;
++    PyObject *py_retlist = PyList_New(0);
++    PyObject *py_cputime = NULL;
++
++    if (py_retlist == NULL)
++        return NULL;
++
++    // retrieve maxcpus value
++    size = sizeof(maxcpus);
++    if (sysctlbyname("hw.ncpu", &maxcpus, &size, NULL, 0) < 0) {
++        Py_DECREF(py_retlist);
++        PyErr_SetFromErrno(PyExc_OSError);
++        return NULL;
++    }
++    long cpu_time[maxcpus][CPUSTATES];
++
++    // retrieve the number of cpus
++    mib[0] = CTL_HW;
++    mib[1] = HW_NCPU;
++    len = sizeof(ncpu);
++    if (sysctl(mib, 2, &ncpu, &len, NULL, 0) == -1) {
++        PyErr_SetFromErrno(PyExc_OSError);
++        goto error;
++    }
++
++    // per-cpu info
++    size = sizeof(cpu_time);
++    if (sysctlbyname("kern.cp_times", &cpu_time, &size, NULL, 0) == -1) {
++        PyErr_SetFromErrno(PyExc_OSError);
++        goto error;
++    }
++
++    for (i = 0; i < ncpu; i++) {
++        py_cputime = Py_BuildValue(
++            "(ddddd)",
++            (double)cpu_time[i][CP_USER] / CLOCKS_PER_SEC,
++            (double)cpu_time[i][CP_NICE] / CLOCKS_PER_SEC,
++            (double)cpu_time[i][CP_SYS] / CLOCKS_PER_SEC,
++            (double)cpu_time[i][CP_IDLE] / CLOCKS_PER_SEC,
++            (double)cpu_time[i][CP_INTR] / CLOCKS_PER_SEC);
++        if (!py_cputime)
++            goto error;
++        if (PyList_Append(py_retlist, py_cputime))
++            goto error;
++        Py_DECREF(py_cputime);
++    }
++
++    return py_retlist;
++
++error:
++    Py_XDECREF(py_cputime);
++    Py_DECREF(py_retlist);
++    return NULL;
++}
++
++
++PyObject *
++psutil_disk_io_counters(PyObject *self, PyObject *args) {
++    /* XXX: not implemented */
++    return NULL;
++}
++
++
++PyObject *
++psutil_proc_memory_maps(PyObject *self, PyObject *args) {
++    // Return a list of tuples for every process memory maps.
++    //'procstat' cmdline utility has been used as an example.
++
++    /* XXX: not implemented */
++    return NULL;
++}
++
++
++PyObject*
++psutil_proc_cpu_affinity_get(PyObject* self, PyObject* args) {
++    // Get process CPU affinity.
++    // Reference:
++    // http://sources.freebsd.org/RELENG_9/src/usr.bin/cpuset/cpuset.c
++
++    /* XXX: not implemented */
++    return NULL;
++}
++
++
++PyObject *
++psutil_proc_cpu_affinity_set(PyObject *self, PyObject *args) {
++    // Set process CPU affinity.
++    // Reference:
++    // http://sources.freebsd.org/RELENG_9/src/usr.bin/cpuset/cpuset.c
++
++    /* XXX: not implemented */
++    return NULL;
++}
++
++
++PyObject *
++psutil_cpu_stats(PyObject *self, PyObject *args) {
++    unsigned int v_soft;
++    unsigned int v_intr;
++    unsigned int v_syscall;
++    unsigned int v_trap;
++    unsigned int v_swtch;
++    size_t size = sizeof(v_soft);
++
++    if (sysctlbyname("vm.stats.sys.v_soft", &v_soft, &size, NULL, 0))
++        goto error;
++    if (sysctlbyname("vm.stats.sys.v_intr", &v_intr, &size, NULL, 0))
++        goto error;
++    if (sysctlbyname("vm.stats.sys.v_syscall", &v_syscall, &size, NULL, 0))
++        goto error;
++    if (sysctlbyname("vm.stats.sys.v_trap", &v_trap, &size, NULL, 0))
++        goto error;
++    if (sysctlbyname("vm.stats.sys.v_swtch", &v_swtch, &size, NULL, 0))
++        goto error;
++
++    return Py_BuildValue(
++        "IIIII",
++        v_swtch,  // ctx switches
++        v_intr,  // interrupts
++        v_soft,  // software interrupts
++        v_syscall,  // syscalls
++        v_trap  // traps
++    );
++
++error:
++    PyErr_SetFromErrno(PyExc_OSError);
++    return NULL;
++}
++
++
++/*
++ * Return battery information.
++ */
++PyObject *
++psutil_sensors_battery(PyObject *self, PyObject *args) {
++    int percent;
++    int minsleft;
++    int power_plugged;
++    size_t size = sizeof(percent);
++
++    if (sysctlbyname("hw.acpi.battery.life", &percent, &size, NULL, 0))
++        goto error;
++    if (sysctlbyname("hw.acpi.battery.time", &minsleft, &size, NULL, 0))
++        goto error;
++    if (sysctlbyname("hw.acpi.acline", &power_plugged, &size, NULL, 0))
++        goto error;
++    return Py_BuildValue("iii", percent, minsleft, power_plugged);
++
++error:
++    PyErr_SetFromErrno(PyExc_OSError);
++    return NULL;
++}
diff --git a/py-psutil/patches/patch-psutil_arch_bsd_dragonfly.h b/py-psutil/patches/patch-psutil_arch_bsd_dragonfly.h
new file mode 100644
index 0000000000..6e2885cea5
--- /dev/null
+++ b/py-psutil/patches/patch-psutil_arch_bsd_dragonfly.h
@@ -0,0 +1,32 @@
+$NetBSD$
+
+--- psutil/arch/bsd/dragonfly.h.orig	2018-02-09 16:11:41.567735000 +0000
++++ psutil/arch/bsd/dragonfly.h
+@@ -0,0 +1,27 @@
++/*
++ * Copyright (c) 2009, Giampaolo Rodola', Landry Breuil.
++ * All rights reserved.
++ * Use of this source code is governed by a BSD-style license that can be
++ * found in the LICENSE file.
++ */
++
++#include <Python.h>
++
++typedef struct kinfo_proc kinfo_proc;
++
++int psutil_kinfo_proc(pid_t pid, struct kinfo_proc *proc);
++struct kinfo_file * kinfo_getfile(long pid, int* cnt);
++int psutil_get_proc_list(struct kinfo_proc **procList, size_t *procCount);
++char **_psutil_get_argv(long pid);
++PyObject * psutil_get_cmdline(long pid);
++
++//
++PyObject *psutil_proc_threads(PyObject *self, PyObject *args);
++PyObject *psutil_virtual_mem(PyObject *self, PyObject *args);
++PyObject *psutil_swap_mem(PyObject *self, PyObject *args);
++PyObject *psutil_proc_num_fds(PyObject *self, PyObject *args);
++PyObject *psutil_proc_cwd(PyObject *self, PyObject *args);
++PyObject *psutil_proc_connections(PyObject *self, PyObject *args);
++PyObject *psutil_per_cpu_times(PyObject *self, PyObject *args);
++PyObject* psutil_disk_io_counters(PyObject* self, PyObject* args);
++PyObject* psutil_cpu_stats(PyObject* self, PyObject* args);
diff --git a/py-psutil/patches/patch-setup.py b/py-psutil/patches/patch-setup.py
new file mode 100644
index 0000000000..29935a9532
--- /dev/null
+++ b/py-psutil/patches/patch-setup.py
@@ -0,0 +1,30 @@
+$NetBSD$
+
+--- setup.py.orig	2017-11-08 11:29:08.000000000 +0000
++++ setup.py
+@@ -33,6 +33,7 @@ from _common import FREEBSD  # NOQA
+ from _common import LINUX  # NOQA
+ from _common import NETBSD  # NOQA
+ from _common import OPENBSD  # NOQA
++from _common import DRAGONFLY  # NOQA
+ from _common import OSX  # NOQA
+ from _common import POSIX  # NOQA
+ from _common import SUNOS  # NOQA
+@@ -194,6 +195,17 @@ elif NETBSD:
+         ],
+         define_macros=macros,
+         libraries=["kvm"])
++
++elif DRAGONFLY:
++    macros.append(("PSUTIL_DRAGONFLY", 1))
++    ext = Extension(
++        'psutil._psutil_bsd',
++        sources=sources + [
++            'psutil/_psutil_bsd.c',
++            'psutil/arch/bsd/dragonfly.c',
++        ],
++        define_macros=macros,
++        libraries=["kvm"])
+ 
+ elif LINUX:
+     def get_ethtool_macro():


Home | Main Index | Thread Index | Old Index