From owner-freebsd-ports-bugs@FreeBSD.ORG Sat Jul 28 19:10:02 2012 Return-Path: Delivered-To: freebsd-ports-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3CE3B1065670 for ; Sat, 28 Jul 2012 19:10:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 0D01A8FC12 for ; Sat, 28 Jul 2012 19:10:02 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q6SJA1X4095958 for ; Sat, 28 Jul 2012 19:10:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q6SJA1eM095957; Sat, 28 Jul 2012 19:10:01 GMT (envelope-from gnats) Resent-Date: Sat, 28 Jul 2012 19:10:01 GMT Resent-Message-Id: <201207281910.q6SJA1eM095957@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-ports-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Olivier Duchateau Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 01D2D106564A for ; Sat, 28 Jul 2012 19:04:45 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id A436C8FC0C for ; Sat, 28 Jul 2012 19:04:45 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q6SJ4jF6043786 for ; Sat, 28 Jul 2012 19:04:45 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id q6SJ4ji4043785; Sat, 28 Jul 2012 19:04:45 GMT (envelope-from nobody) Message-Id: <201207281904.q6SJ4ji4043785@red.freebsd.org> Date: Sat, 28 Jul 2012 19:04:45 GMT From: Olivier Duchateau To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: ports/170237: [UPDATE] sysutils/py-psutil to 0.5.1 X-BeenThere: freebsd-ports-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Ports bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Jul 2012 19:10:02 -0000 >Number: 170237 >Category: ports >Synopsis: [UPDATE] sysutils/py-psutil to 0.5.1 >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Jul 28 19:10:01 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Olivier Duchateau >Release: FreeBSD 8.3-RELEASE-p3 i386 >Organization: >Environment: >Description: - Add patch, taken from trunk version (r1470) to compile under FreeBSD >= 9.x Build logs: https://redports.org/buildarchive/20120728175821-6623/ >How-To-Repeat: >Fix: Patch attached with submission follows: Index: distinfo =================================================================== --- distinfo (révision 301667) +++ distinfo (copie de travail) @@ -1,2 +1,2 @@ -SHA256 (psutil-0.4.1.tar.gz) = f051d2f965bcf63067c45449ab128b26e01587f0bc68e4141c355d28a55c71ee -SIZE (psutil-0.4.1.tar.gz) = 176640 +SHA256 (psutil-0.5.1.tar.gz) = 2de897263fa4f00e4e8316dff53f8e3631780f7567b2035129b7400d477858d6 +SIZE (psutil-0.5.1.tar.gz) = 125636 Index: files/patch-psutil__psutil_bsd.c =================================================================== --- files/patch-psutil__psutil_bsd.c (révision 0) +++ files/patch-psutil__psutil_bsd.c (copie de travail) @@ -0,0 +1,1052 @@ +--- psutil/_psutil_bsd.c.orig 2012-06-27 18:30:32.000000000 +0000 ++++ psutil/_psutil_bsd.c 2012-07-28 19:43:33.000000000 +0000 +@@ -1,5 +1,5 @@ + /* +- * $Id: _psutil_bsd.c 1353 2012-06-18 13:01:08Z g.rodola $ ++ * $Id$ + * + * 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 +@@ -20,8 +20,31 @@ + #include + #include + #include ++#include ++#include ++ + #include +-#include /* system users */ ++#include /* for struct socket */ ++#include /* for struct proto */ ++#include /* for struct domain */ ++ ++#include /* for unpcb struct (UNIX sockets) */ ++#include /* for unpcb struct (UNIX sockets) */ ++#include /* for mbuf struct (UNIX sockets) */ ++/* for in_pcb struct */ ++#include ++#include ++#include ++#include ++#include /* for struct tcpcb */ ++#include /* for TCP connection states */ ++#include /* for inet_ntop() */ ++ ++#if __FreeBSD_version < 900000 ++ #include /* system users */ ++#else ++ #include ++#endif + #include /* get io counters */ + #include /* needed for vmtotal struct */ + #include /* process open files, shared libs (kinfo_getvmmap) */ +@@ -85,26 +108,36 @@ + size_t num_processes; + size_t idx; + PyObject* retlist = PyList_New(0); +- PyObject* pid; ++ PyObject* pid = NULL; + + if (get_proc_list(&proclist, &num_processes) != 0) { +- Py_DECREF(retlist); + PyErr_SetString(PyExc_RuntimeError, "failed to retrieve process list."); +- return NULL; ++ goto error; + } + + if (num_processes > 0) { + orig_address = proclist; // save so we can free it after we're done + for (idx=0; idx < num_processes; idx++) { + pid = Py_BuildValue("i", proclist->ki_pid); +- PyList_Append(retlist, pid); +- Py_XDECREF(pid); ++ if (!pid) ++ goto error; ++ if (PyList_Append(retlist, pid)) ++ goto error; ++ Py_DECREF(pid); + proclist++; + } + free(orig_address); + } + + return retlist; ++ ++error: ++ Py_XDECREF(pid); ++ Py_DECREF(retlist); ++ if (orig_address != NULL) { ++ free(orig_address); ++ } ++ return NULL; + } + + +@@ -312,6 +345,26 @@ + + + /* ++ * Return the number of context switches performed by process as a tuple. ++ */ ++static PyObject* ++get_process_num_ctx_switches(PyObject* self, PyObject* args) ++{ ++ long pid; ++ struct kinfo_proc kp; ++ if (! PyArg_ParseTuple(args, "l", &pid)) { ++ return NULL; ++ } ++ if (get_kinfo_proc(pid, &kp) == -1) { ++ return NULL; ++ } ++ return Py_BuildValue("(ll)", kp.ki_rusage.ru_nvcsw, ++ kp.ki_rusage.ru_nivcsw); ++} ++ ++ ++ ++/* + * Return number of threads used by process as a Python integer. + */ + static PyObject* +@@ -340,7 +393,7 @@ + { + long pid; + int mib[4]; +- struct kinfo_proc *kip; ++ struct kinfo_proc *kip = NULL; + struct kinfo_proc *kipp; + int error; + unsigned int i; +@@ -349,7 +402,7 @@ + PyObject* pyTuple = NULL; + + if (! PyArg_ParseTuple(args, "l", &pid)) { +- return NULL; ++ goto error; + } + + /* +@@ -364,25 +417,27 @@ + error = sysctl(mib, 4, NULL, &size, NULL, 0); + if (error == -1) { + PyErr_SetFromErrno(PyExc_OSError); +- return NULL; ++ goto error; + } + if (size == 0) { +- return NoSuchProcess(); ++ NoSuchProcess(); ++ goto error; + } + + kip = malloc(size); + if (kip == NULL) { + PyErr_SetFromErrno(PyExc_OSError); +- return NULL; ++ goto error; + } + + error = sysctl(mib, 4, kip, &size, NULL, 0); + if (error == -1) { + PyErr_SetFromErrno(PyExc_OSError); +- return NULL; ++ goto error; + } + if (size == 0) { +- return NoSuchProcess(); ++ NoSuchProcess(); ++ goto error; + } + + for (i = 0; i < size / sizeof(*kipp); i++) { +@@ -391,11 +446,22 @@ + TV2DOUBLE(kipp->ki_rusage.ru_utime), + TV2DOUBLE(kipp->ki_rusage.ru_stime) + ); +- PyList_Append(retList, pyTuple); +- Py_XDECREF(pyTuple); ++ if (pyTuple == NULL) ++ goto error; ++ if (PyList_Append(retList, pyTuple)) ++ goto error; ++ Py_DECREF(pyTuple); + } + free(kip); + return retList; ++ ++error: ++ Py_XDECREF(pyTuple); ++ Py_DECREF(retList); ++ if (kip != NULL) { ++ free(kip); ++ } ++ return NULL; + } + + +@@ -403,7 +469,7 @@ + * Return a Python tuple (user_time, kernel_time) + */ + static PyObject* +-get_cpu_times(PyObject* self, PyObject* args) ++get_process_cpu_times(PyObject* self, PyObject* args) + { + long pid; + double user_t, sys_t; +@@ -485,12 +551,11 @@ + } + + +- + /* +- * Return the RSS and VMS as a Python tuple. ++ * Return extended memory info for a process as a Python tuple. + */ + static PyObject* +-get_memory_info(PyObject* self, PyObject* args) ++get_process_memory_info(PyObject* self, PyObject* args) + { + long pid; + struct kinfo_proc kp; +@@ -500,7 +565,11 @@ + if (get_kinfo_proc(pid, &kp) == -1) { + return NULL; + } +- return Py_BuildValue("(ll)", ptoa(kp.ki_rssize), (long)kp.ki_size); ++ return Py_BuildValue("(lllll)", ptoa(kp.ki_rssize), // rss ++ (long)kp.ki_size, // vms ++ ptoa(kp.ki_tsize), // text ++ ptoa(kp.ki_dsize), // data ++ ptoa(kp.ki_ssize)); // stack + } + + +@@ -671,18 +740,19 @@ + PyObject *retList = PyList_New(0); + PyObject *tuple = NULL; + +- struct kinfo_file *freep, *kif; ++ struct kinfo_file *freep = NULL; ++ struct kinfo_file *kif; + struct kinfo_proc kipp; + + if (! PyArg_ParseTuple(args, "l", &pid)) +- return NULL; ++ goto error; + if (get_kinfo_proc(pid, &kipp) == -1) +- return NULL; ++ goto error; + + freep = kinfo_getfile(pid, &cnt); + if (freep == NULL) { + PyErr_SetFromErrno(0); +- return NULL; ++ goto error; + } + + for (i = 0; i < cnt; i++) { +@@ -691,13 +761,22 @@ + (kif->kf_vnode_type == KF_VTYPE_VREG)) + { + tuple = Py_BuildValue("(si)", kif->kf_path, kif->kf_fd); +- PyList_Append(retList, tuple); ++ if (tuple == NULL) ++ goto error; ++ if (PyList_Append(retList, tuple)) ++ goto error; + Py_DECREF(tuple); + } + } + free(freep); +- + return retList; ++ ++error: ++ Py_XDECREF(tuple); ++ Py_DECREF(retList); ++ if (freep != NULL) ++ free(freep); ++ return NULL; + } + + +@@ -710,7 +789,7 @@ + long pid; + int cnt; + +- struct kinfo_file *freep, *kif; ++ struct kinfo_file *freep; + struct kinfo_proc kipp; + + if (! PyArg_ParseTuple(args, "l", &pid)) +@@ -723,6 +802,7 @@ + PyErr_SetFromErrno(0); + return NULL; + } ++ free(freep); + + return Py_BuildValue("i", cnt); + } +@@ -736,26 +816,29 @@ + { + long pid; + PyObject *path = NULL; +- struct kinfo_file *freep, *kif; ++ struct kinfo_file *freep = NULL; ++ struct kinfo_file *kif; + struct kinfo_proc kipp; + + int i, cnt; + + if (! PyArg_ParseTuple(args, "l", &pid)) +- return NULL; ++ goto error; + if (get_kinfo_proc(pid, &kipp) == -1) +- return NULL; ++ goto error; + + freep = kinfo_getfile(pid, &cnt); + if (freep == NULL) { + PyErr_SetFromErrno(0); +- return NULL; ++ goto error; + } + + for (i = 0; i < cnt; i++) { + kif = &freep[i]; + if (kif->kf_fd == KF_FD_TYPE_CWD) { + path = Py_BuildValue("s", kif->kf_path); ++ if (!path) ++ goto error; + break; + } + } +@@ -769,6 +852,315 @@ + } + free(freep); + return path; ++ ++error: ++ Py_XDECREF(path); ++ if (freep != NULL) ++ free(freep); ++ return NULL; ++} ++ ++ ++/* ++ * mathes Linux net/tcp_states.h: ++ * http://students.mimuw.edu.pl/lxr/source/include/net/tcp_states.h ++ */ ++static char * ++get_connection_status(int st) { ++ switch (st) { ++ case TCPS_CLOSED: ++ return "CLOSE"; ++ case TCPS_CLOSING: ++ return "CLOSING"; ++ case TCPS_CLOSE_WAIT: ++ return "CLOSE_WAIT"; ++ case TCPS_LISTEN: ++ return "LISTEN"; ++ case TCPS_ESTABLISHED: ++ return "ESTABLISHED"; ++ case TCPS_SYN_SENT: ++ return "SYN_SENT"; ++ case TCPS_SYN_RECEIVED: ++ return "SYN_RECV"; ++ case TCPS_FIN_WAIT_1: ++ return "FIN_WAIT_1"; ++ case TCPS_FIN_WAIT_2: ++ return "FIN_WAIT_2"; ++ case TCPS_LAST_ACK: ++ return "LAST_ACK"; ++ case TCPS_TIME_WAIT: ++ return "TIME_WAIT"; ++ default: ++ return "?"; ++ } ++} ++ ++// a kvm_read that returns true if everything is read ++#define KVM_READ(kaddr, paddr, len) \ ++ ((len) < SSIZE_MAX && \ ++ kvm_read(kd, (u_long)(kaddr), (char *)(paddr), (len)) == (ssize_t)(len)) ++ ++// XXX - copied from sys/file.h to make compiler happy ++struct file { ++ void *f_data; /* file descriptor specific data */ ++ struct fileops *f_ops; /* File operations */ ++ struct ucred *f_cred; /* associated credentials. */ ++ struct vnode *f_vnode; /* NULL or applicable vnode */ ++ short f_type; /* descriptor type */ ++ short f_vnread_flags; /* (f) Sleep lock for f_offset */ ++ volatile u_int f_flag; /* see fcntl.h */ ++ volatile u_int f_count; /* reference count */ ++ int f_seqcount; /* Count of sequential accesses. */ ++ off_t f_nextoff; /* next expected read/write offset. */ ++ struct cdev_privdata *f_cdevpriv; /* (d) Private data for the cdev. */ ++ off_t f_offset; ++ void *f_label; /* Place-holder for MAC label. */ ++}; ++ ++ ++/* ++ * Return connections opened by process. ++ * fstat.c source code was used as an example. ++ */ ++static PyObject* ++get_process_connections(PyObject* self, PyObject* args) ++{ ++ long pid; ++ struct kinfo_proc *p; ++ struct file **ofiles = NULL; ++ char buf[_POSIX2_LINE_MAX]; ++ char path[PATH_MAX]; ++ int cnt; ++ int i; ++ kvm_t *kd = NULL; ++ struct file file; ++ struct filedesc filed; ++ struct nlist nl[] = {{ "" },}; ++ struct socket so; ++ struct protosw proto; ++ struct domain dom; ++ struct inpcb inpcb; ++ struct tcpcb tcpcb; ++ struct unpcb unpcb; ++ ++ PyObject *retList = PyList_New(0); ++ PyObject *tuple = NULL; ++ PyObject *laddr = NULL; ++ PyObject *raddr = NULL; ++ PyObject *af_filter = NULL; ++ PyObject *type_filter = NULL; ++ PyObject* _family = NULL; ++ PyObject* _type = NULL; ++ ++ if (! PyArg_ParseTuple(args, "lOO", &pid, &af_filter, &type_filter)) { ++ goto error; ++ } ++ if (!PySequence_Check(af_filter) || !PySequence_Check(type_filter)) { ++ PyErr_SetString(PyExc_TypeError, "arg 2 or 3 is not a sequence"); ++ goto error; ++ } ++ ++ kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, buf); ++ if (kd == NULL) { ++ AccessDenied(); ++ goto error; ++ } ++ ++ if (kvm_nlist(kd, nl) != 0) { ++ PyErr_SetString(PyExc_RuntimeError, "kvm_nlist() failed"); ++ goto error; ++ } ++ ++ p = kvm_getprocs(kd, KERN_PROC_PID, pid, &cnt); ++ if (p == NULL) { ++ NoSuchProcess(); ++ goto error; ++ } ++ if (cnt != 1) { ++ NoSuchProcess(); ++ goto error; ++ } ++ if (p->ki_fd == NULL) { ++ PyErr_SetString(PyExc_RuntimeError, "no usable fd found"); ++ goto error; ++ } ++ if (!KVM_READ(p->ki_fd, &filed, sizeof(filed))) { ++ PyErr_SetString(PyExc_RuntimeError, "kvm_read() failed"); ++ goto error; ++ } ++ ++ ofiles = malloc((filed.fd_lastfile+1) * sizeof(struct file *)); ++ if (ofiles == NULL) { ++ PyErr_SetString(PyExc_RuntimeError, "malloc() failed"); ++ goto error; ++ } ++ ++ if (!KVM_READ(filed.fd_ofiles, ofiles, ++ (filed.fd_lastfile+1) * sizeof(struct file *))) { ++ PyErr_SetString(PyExc_RuntimeError, "kvm_read() failed"); ++ goto error; ++ } ++ ++ for (i = 0; i <= filed.fd_lastfile; i++) { ++ int lport, rport; ++ char lip[200], rip[200]; ++ char *state; ++ int inseq; ++ tuple = NULL; ++ laddr = NULL; ++ raddr = NULL; ++ ++ if (ofiles[i] == NULL) { ++ continue; ++ } ++ if (!KVM_READ(ofiles[i], &file, sizeof (struct file))) { ++ PyErr_SetString(PyExc_RuntimeError, "kvm_read() file failed"); ++ goto error; ++ } ++ if (file.f_type == DTYPE_SOCKET) { ++ // fill in socket ++ if (!KVM_READ(file.f_data, &so, sizeof(struct socket))) { ++ PyErr_SetString(PyExc_RuntimeError, "kvm_read() socket failed"); ++ goto error; ++ } ++ // fill in protosw entry ++ if (!KVM_READ(so.so_proto, &proto, sizeof(struct protosw))) { ++ PyErr_SetString(PyExc_RuntimeError, "kvm_read() proto failed"); ++ goto error; ++ } ++ // fill in domain ++ if (!KVM_READ(proto.pr_domain, &dom, sizeof(struct domain))) { ++ PyErr_SetString(PyExc_RuntimeError, "kvm_read() domain failed"); ++ goto error; ++ } ++ ++ // apply filters ++ _family = PyLong_FromLong((long)dom.dom_family); ++ inseq = PySequence_Contains(af_filter, _family); ++ Py_DECREF(_family); ++ if (inseq == 0) { ++ continue; ++ } ++ _type = PyLong_FromLong((long)proto.pr_type); ++ inseq = PySequence_Contains(type_filter, _type); ++ Py_DECREF(_type); ++ if (inseq == 0) { ++ continue; ++ } ++ ++ // IPv4 / IPv6 socket ++ if ((dom.dom_family == AF_INET) || (dom.dom_family == AF_INET6)) { ++ // fill inpcb ++ if (kvm_read(kd, (u_long)so.so_pcb, (char *)&inpcb, ++ sizeof(struct inpcb)) != sizeof(struct inpcb)) { ++ PyErr_SetString(PyExc_RuntimeError, "kvm_read() addr failed"); ++ goto error; ++ } ++ ++ // fill status ++ if (proto.pr_type == SOCK_STREAM) { ++ if (kvm_read(kd, (u_long)inpcb.inp_ppcb, (char *)&tcpcb, ++ sizeof(struct tcpcb)) != sizeof(struct tcpcb)) { ++ PyErr_SetString(PyExc_RuntimeError, "kvm_read() state failed"); ++ goto error; ++ } ++ state = get_connection_status((int)tcpcb.t_state); ++ } ++ else { ++ state = ""; ++ } ++ ++ // build addr and port ++ if (dom.dom_family == AF_INET) { ++ inet_ntop(AF_INET, &inpcb.inp_laddr.s_addr, lip, sizeof(lip)); ++ inet_ntop(AF_INET, &inpcb.inp_faddr.s_addr, rip, sizeof(rip)); ++ } ++ else { ++ inet_ntop(AF_INET6, &inpcb.in6p_laddr.s6_addr, lip, sizeof(lip)); ++ inet_ntop(AF_INET6, &inpcb.in6p_faddr.s6_addr, rip, sizeof(rip)); ++ } ++ lport = ntohs(inpcb.inp_lport); ++ rport = ntohs(inpcb.inp_fport); ++ ++ // contruct python tuple/list ++ laddr = Py_BuildValue("(si)", lip, lport); ++ if (!laddr) ++ goto error; ++ if (rport != 0) { ++ raddr = Py_BuildValue("(si)", rip, rport); ++ } ++ else { ++ raddr = Py_BuildValue("()"); ++ } ++ if (!raddr) ++ goto error; ++ tuple = Py_BuildValue("(iiiNNs)", i, ++ dom.dom_family, ++ proto.pr_type, ++ laddr, ++ raddr, ++ state); ++ if (!tuple) ++ goto error; ++ if (PyList_Append(retList, tuple)) ++ goto error; ++ Py_DECREF(tuple); ++ } ++ // UNIX socket ++ else if (dom.dom_family == AF_UNIX) { ++ struct sockaddr_un sun; ++ path[0] = '\0'; ++ ++ if (kvm_read(kd, (u_long)so.so_pcb, (char *)&unpcb, ++ sizeof(struct unpcb)) != sizeof(struct unpcb)) { ++ PyErr_SetString(PyExc_RuntimeError, "kvm_read() unpcb failed"); ++ goto error; ++ } ++ if (unpcb.unp_addr) { ++ if (kvm_read(kd, (u_long)unpcb.unp_addr, (char *)&sun, ++ sizeof(sun)) != sizeof(sun)) { ++ PyErr_SetString(PyExc_RuntimeError, ++ "kvm_read() sockaddr_un failed"); ++ goto error; ++ } ++ sprintf(path, "%.*s", ++ (sun.sun_len - (sizeof(sun) - sizeof(sun.sun_path))), ++ sun.sun_path); ++ } ++ ++ tuple = Py_BuildValue("(iiisOs)", i, ++ dom.dom_family, ++ proto.pr_type, ++ path, ++ Py_None, ++ ""); ++ if (!tuple) ++ goto error; ++ if (PyList_Append(retList, tuple)) ++ goto error; ++ Py_DECREF(tuple); ++ Py_INCREF(Py_None); ++ } ++ } ++ } ++ ++ free(ofiles); ++ kvm_close(kd); ++ return retList; ++ ++error: ++ Py_XDECREF(tuple); ++ Py_XDECREF(laddr); ++ Py_XDECREF(raddr); ++ Py_DECREF(retList); ++ ++ if (kd != NULL) { ++ kvm_close(kd); ++ } ++ if (ofiles != NULL) { ++ free(ofiles); ++ } ++ return NULL; + } + + +@@ -785,11 +1177,12 @@ + size_t size; + int i; + PyObject* py_retlist = PyList_New(0); +- PyObject* py_cputime; ++ PyObject* py_cputime = NULL; + + // retrieve maxcpus value + size = sizeof(maxcpus); + if (sysctlbyname("kern.smp.maxcpus", &maxcpus, &size, NULL, 0) < 0) { ++ Py_DECREF(py_retlist); + PyErr_SetFromErrno(0); + return NULL; + } +@@ -801,14 +1194,14 @@ + len = sizeof(ncpu); + if (sysctl(mib, 2, &ncpu, &len, NULL, 0) == -1) { + PyErr_SetFromErrno(0); +- return NULL; ++ goto error; + } + + // per-cpu info + size = sizeof(cpu_time); + if (sysctlbyname("kern.cp_times", &cpu_time, &size, NULL, 0) == -1) { + PyErr_SetFromErrno(0); +- return NULL; ++ goto error; + } + + for (i = 0; i < ncpu; i++) { +@@ -819,11 +1212,19 @@ + (double)cpu_time[i][CP_IDLE] / CLOCKS_PER_SEC, + (double)cpu_time[i][CP_INTR] / CLOCKS_PER_SEC + ); +- PyList_Append(py_retlist, py_cputime); +- Py_XDECREF(py_cputime); ++ 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; + } + + +@@ -841,25 +1242,27 @@ + char perms[10]; + const char *path; + struct kinfo_proc kp; +- struct kinfo_vmentry *freep, *kve; ++ struct kinfo_vmentry *freep = NULL; ++ struct kinfo_vmentry *kve; + PyObject* pytuple = NULL; + PyObject* retlist = PyList_New(0); + + ptrwidth = 2*sizeof(void *); + + if (! PyArg_ParseTuple(args, "l", &pid)) { +- return NULL; ++ goto error; + } + if (get_kinfo_proc(pid, &kp) == -1) { +- return NULL; ++ goto error; + } + + freep = kinfo_getvmmap(pid, &cnt); + if (freep == NULL) { + PyErr_SetString(PyExc_RuntimeError, "kinfo_getvmmap() failed"); +- return NULL; ++ goto error; + } + for (i = 0; i < cnt; i++) { ++ pytuple = NULL; + kve = &freep[i]; + addr[0] = '\0'; + perms[0] = '\0'; +@@ -919,11 +1322,21 @@ + kve->kve_ref_count, // ref count + kve->kve_shadow_count // shadow count + ); +- PyList_Append(retlist, pytuple); +- Py_XDECREF(pytuple); ++ if (!pytuple) ++ goto error; ++ if (PyList_Append(retlist, pytuple)) ++ goto error; ++ Py_DECREF(pytuple); + } + free(freep); + return retlist; ++ ++error: ++ Py_XDECREF(pytuple); ++ Py_DECREF(retlist); ++ if (freep != NULL) ++ free(freep); ++ return NULL; + } + #endif + +@@ -940,9 +1353,9 @@ + long len; + uint64_t flags; + char opts[200]; +- struct statfs *fs; ++ struct statfs *fs = NULL; + PyObject* py_retlist = PyList_New(0); +- PyObject* py_tuple; ++ PyObject* py_tuple = NULL; + + // get the number of mount points + Py_BEGIN_ALLOW_THREADS +@@ -950,7 +1363,7 @@ + Py_END_ALLOW_THREADS + if (num == -1) { + PyErr_SetFromErrno(0); +- return NULL; ++ goto error; + } + + len = sizeof(*fs) * num; +@@ -960,12 +1373,12 @@ + num = getfsstat(fs, len, MNT_NOWAIT); + Py_END_ALLOW_THREADS + if (num == -1) { +- free(fs); + PyErr_SetFromErrno(0); +- return NULL; ++ goto error; + } + + for (i = 0; i < num; i++) { ++ py_tuple = NULL; + opts[0] = 0; + flags = fs[i].f_flags; + +@@ -1009,12 +1422,22 @@ + fs[i].f_mntonname, // mount point + fs[i].f_fstypename, // fs type + opts); // options +- PyList_Append(py_retlist, py_tuple); +- Py_XDECREF(py_tuple); ++ if (!py_tuple) ++ goto error; ++ if (PyList_Append(py_retlist, py_tuple)) ++ goto error; ++ Py_DECREF(py_tuple); + } + + free(fs); + return py_retlist; ++ ++error: ++ Py_XDECREF(py_tuple); ++ Py_DECREF(py_retlist); ++ if (fs != NULL) ++ free(fs); ++ return NULL; + } + + +@@ -1025,7 +1448,7 @@ + get_network_io_counters(PyObject* self, PyObject* args) + { + PyObject* py_retdict = PyDict_New(); +- PyObject* py_ifc_info; ++ PyObject* py_ifc_info = NULL; + + char *buf = NULL, *lim, *next; + struct if_msghdr *ifm; +@@ -1040,26 +1463,22 @@ + mib[5] = 0; + + if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) { +- Py_DECREF(py_retdict); + PyErr_SetFromErrno(0); +- return NULL; ++ goto error; + } + + + buf = malloc(len); + + if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) { +- if (buf) { +- free(buf); +- } +- Py_DECREF(py_retdict); + PyErr_SetFromErrno(0); +- return NULL; ++ goto error; + } + + lim = buf + len; + + for (next = buf; next < lim; ) { ++ py_ifc_info = NULL; + ifm = (struct if_msghdr *)next; + next += ifm->ifm_msglen; + +@@ -1076,8 +1495,11 @@ + if2m->ifm_data.ifi_ibytes, + if2m->ifm_data.ifi_opackets, + if2m->ifm_data.ifi_ipackets); +- PyDict_SetItemString(py_retdict, ifc_name, py_ifc_info); +- Py_XDECREF(py_ifc_info); ++ if (!py_ifc_info) ++ goto error; ++ if (PyDict_SetItemString(py_retdict, ifc_name, py_ifc_info)) ++ goto error; ++ Py_DECREF(py_ifc_info); + } + else { + continue; +@@ -1086,6 +1508,13 @@ + + free(buf); + return py_retdict; ++ ++error: ++ Py_XDECREF(py_ifc_info); ++ Py_DECREF(py_retdict); ++ if (buf != NULL) ++ free(buf); ++ return NULL; + } + + +@@ -1096,27 +1525,26 @@ + get_disk_io_counters(PyObject* self, PyObject* args) + { + PyObject* py_retdict = PyDict_New(); +- PyObject* py_disk_info; ++ PyObject* py_disk_info = NULL; + + int i; + struct statinfo stats; + + if (devstat_checkversion(NULL) < 0) { +- Py_DECREF(py_retdict); +- return PyErr_Format(PyExc_RuntimeError, +- "devstat_checkversion() failed"); ++ PyErr_Format(PyExc_RuntimeError, "devstat_checkversion() failed"); ++ goto error; + } + + stats.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo)); + bzero(stats.dinfo, sizeof(struct devinfo)); + + if (devstat_getdevs(NULL, &stats) == -1) { +- Py_DECREF(py_retdict); +- return PyErr_Format(PyExc_RuntimeError, +- "devstat_getdevs() failed"); ++ PyErr_Format(PyExc_RuntimeError, "devstat_getdevs() failed"); ++ goto error; + } + + for (i = 0; i < stats.dinfo->numdevs; i++) { ++ py_disk_info = NULL; + struct devstat current; + char disk_name[128]; + current = stats.dinfo->devices[i]; +@@ -1124,7 +1552,6 @@ + current.device_name, + current.unit_number); + +- + py_disk_info = Py_BuildValue("(KKKKLL)", + current.operations[DEVSTAT_READ], // no reads + current.operations[DEVSTAT_WRITE], // no writes +@@ -1134,17 +1561,26 @@ + ¤t.duration[DEVSTAT_READ], NULL), // r time + (long long)devstat_compute_etime( + ¤t.duration[DEVSTAT_WRITE], NULL) // w time +- ); +- PyDict_SetItemString(py_retdict, disk_name, py_disk_info); +- Py_XDECREF(py_disk_info); ++ ); ++ if (!py_disk_info) ++ goto error; ++ if (PyDict_SetItemString(py_retdict, disk_name, py_disk_info)) ++ goto error; ++ Py_DECREF(py_disk_info); + } + + if (stats.dinfo->mem_ptr) { + free(stats.dinfo->mem_ptr); + } + free(stats.dinfo); +- + return py_retdict; ++ ++error: ++ Py_XDECREF(py_disk_info); ++ Py_DECREF(py_retdict); ++ if (stats.dinfo != NULL) ++ free(stats.dinfo); ++ return NULL; + } + + +@@ -1156,13 +1592,15 @@ + { + PyObject *ret_list = PyList_New(0); + PyObject *tuple = NULL; ++ ++#if __FreeBSD_version < 900000 + struct utmp ut; + FILE *fp; + +- + fp = fopen(_PATH_UTMP, "r"); + if (fp == NULL) { +- return PyErr_SetFromErrno(0); ++ PyErr_SetFromErrno(0); ++ goto error; + } + + while (fread(&ut, sizeof(ut), 1, fp) == 1) { +@@ -1172,14 +1610,51 @@ + ut.ut_name, // username + ut.ut_line, // tty + ut.ut_host, // hostname +- (float)ut.ut_time // tstamp ++ (float)ut.ut_time // start time + ); +- PyList_Append(ret_list, tuple); ++ if (!tuple) { ++ fclose(fp); ++ goto error; ++ } ++ if (PyList_Append(ret_list, tuple)) { ++ fclose(fp); ++ goto error; ++ } + Py_DECREF(tuple); + } + + fclose(fp); ++#else ++ struct utmpx *utx; ++ ++ while ((utx = getutxent()) != NULL) { ++ if (utx->ut_type != USER_PROCESS) ++ continue; ++ tuple = Py_BuildValue("(sssf)", ++ utx->ut_user, // username ++ utx->ut_line, // tty ++ utx->ut_host, // hostname ++ (float)utx->ut_tv.tv_sec // start time ++ ); ++ if (!tuple) { ++ endutxent(); ++ goto error; ++ } ++ if (PyList_Append(ret_list, tuple)) { ++ endutxent(); ++ goto error; ++ } ++ Py_DECREF(tuple); ++ } ++ ++ endutxent(); ++#endif + return ret_list; ++ ++error: ++ Py_XDECREF(tuple); ++ Py_DECREF(ret_list); ++ return NULL; + } + + +@@ -1193,6 +1668,8 @@ + + {"get_process_name", get_process_name, METH_VARARGS, + "Return process name"}, ++ {"get_process_connections", get_process_connections, METH_VARARGS, ++ "Return connections opened by process"}, + {"get_process_exe", get_process_exe, METH_VARARGS, + "Return process pathname executable"}, + {"get_process_cmdline", get_process_cmdline, METH_VARARGS, +@@ -1203,15 +1680,17 @@ + "Return process real effective and saved user ids as a Python tuple"}, + {"get_process_gids", get_process_gids, METH_VARARGS, + "Return process real effective and saved group ids as a Python tuple"}, +- {"get_cpu_times", get_cpu_times, METH_VARARGS, ++ {"get_process_cpu_times", get_process_cpu_times, METH_VARARGS, + "Return tuple of user/kern time for the given PID"}, + {"get_process_create_time", get_process_create_time, METH_VARARGS, + "Return a float indicating the process create time expressed in " + "seconds since the epoch"}, +- {"get_memory_info", get_memory_info, METH_VARARGS, +- "Return a tuple of RSS/VMS memory information"}, ++ {"get_process_memory_info", get_process_memory_info, METH_VARARGS, ++ "Return extended memory info for a process as a Python tuple."}, + {"get_process_num_threads", get_process_num_threads, METH_VARARGS, + "Return number of threads used by process"}, ++ {"get_process_num_ctx_switches", get_process_num_ctx_switches, METH_VARARGS, ++ "Return the number of context switches performed by process"}, + {"get_process_threads", get_process_threads, METH_VARARGS, + "Return process threads"}, + {"get_process_status", get_process_status, METH_VARARGS, Index: files/patch-psutil__psutil_bsd.c =================================================================== --- files/patch-psutil__psutil_bsd.c (révision 301667) +++ files/patch-psutil__psutil_bsd.c (copie de travail) Modification de propriétés sur files/patch-psutil__psutil_bsd.c ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: fbsd:nokeywords ## -0,0 +1 ## +yes \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: Makefile =================================================================== --- Makefile (révision 301667) +++ Makefile (copie de travail) @@ -6,7 +6,7 @@ # PORTNAME= psutil -PORTVERSION= 0.4.1 +PORTVERSION= 0.5.1 CATEGORIES= sysutils python MASTER_SITES= GOOGLE_CODE PKGNAMEPREFIX= ${PYTHON_PKGNAMEPREFIX} >Release-Note: >Audit-Trail: >Unformatted: