summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-01-20 14:10:42 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2016-01-20 14:10:42 +0100
commitbce1d8bf4aec80802092699bc226c6b04aa6ebcb (patch)
treea7ca6f373a0a482788352ff884ac5224a3559fcc
parentad345515370fbbef051a41eefefabd3299d81903 (diff)
parentd16acf94010a1ecc0757b03da87f229376317b13 (diff)
downloadpsutil-bce1d8bf4aec80802092699bc226c6b04aa6ebcb.tar.gz
Merge branch 'master' of github.com:giampaolo/psutil
-rw-r--r--psutil/_pssunos.py32
-rw-r--r--psutil/_psutil_sunos.c59
2 files changed, 52 insertions, 39 deletions
diff --git a/psutil/_pssunos.py b/psutil/_pssunos.py
index d00e5c97..4f3d6e15 100644
--- a/psutil/_pssunos.py
+++ b/psutil/_pssunos.py
@@ -290,7 +290,7 @@ class Process(object):
@wrap_exceptions
def name(self):
# note: max len == 15
- return cext.proc_name_and_args(self.pid)[0]
+ return cext.proc_name_and_args(self.pid, get_procfs_path())[0]
@wrap_exceptions
def exe(self):
@@ -307,15 +307,16 @@ class Process(object):
@wrap_exceptions
def cmdline(self):
- return cext.proc_name_and_args(self.pid)[1].split(' ')
+ return cext.proc_name_and_args(
+ self.pid, get_procfs_path())[1].split(' ')
@wrap_exceptions
def create_time(self):
- return cext.proc_basic_info(self.pid)[3]
+ return cext.proc_basic_info(self.pid, get_procfs_path())[3]
@wrap_exceptions
def num_threads(self):
- return cext.proc_basic_info(self.pid)[5]
+ return cext.proc_basic_info(self.pid, get_procfs_path())[5]
@wrap_exceptions
def nice_get(self):
@@ -348,21 +349,23 @@ class Process(object):
@wrap_exceptions
def ppid(self):
- return cext.proc_basic_info(self.pid)[0]
+ return cext.proc_basic_info(self.pid, get_procfs_path())[0]
@wrap_exceptions
def uids(self):
- real, effective, saved, _, _, _ = cext.proc_cred(self.pid)
+ real, effective, saved, _, _, _ = \
+ cext.proc_cred(self.pid, get_procfs_path())
return _common.puids(real, effective, saved)
@wrap_exceptions
def gids(self):
- _, _, _, real, effective, saved = cext.proc_cred(self.pid)
+ _, _, _, real, effective, saved = \
+ cext.proc_cred(self.pid, get_procfs_path())
return _common.puids(real, effective, saved)
@wrap_exceptions
def cpu_times(self):
- user, system = cext.proc_cpu_times(self.pid)
+ user, system = cext.proc_cpu_times(self.pid, get_procfs_path())
return _common.pcputimes(user, system)
@wrap_exceptions
@@ -370,7 +373,7 @@ class Process(object):
procfs_path = get_procfs_path()
hit_enoent = False
tty = wrap_exceptions(
- cext.proc_basic_info(self.pid)[0])
+ cext.proc_basic_info(self.pid, get_procfs_path())[0])
if tty != cext.PRNODEV:
for x in (0, 1, 2, 255):
try:
@@ -402,7 +405,7 @@ class Process(object):
@wrap_exceptions
def memory_info(self):
- ret = cext.proc_basic_info(self.pid)
+ ret = cext.proc_basic_info(self.pid, get_procfs_path())
rss, vms = ret[1] * 1024, ret[2] * 1024
return _common.pmem(rss, vms)
@@ -411,7 +414,7 @@ class Process(object):
@wrap_exceptions
def status(self):
- code = cext.proc_basic_info(self.pid)[6]
+ code = cext.proc_basic_info(self.pid, get_procfs_path())[6]
# XXX is '?' legit? (we're not supposed to return it anyway)
return PROC_STATUSES.get(code, '?')
@@ -425,7 +428,7 @@ class Process(object):
tid = int(tid)
try:
utime, stime = cext.query_process_thread(
- self.pid, tid)
+ self.pid, tid, procfs_path)
except EnvironmentError as err:
# ENOENT == thread gone in meantime
if err.errno == errno.ENOENT:
@@ -526,7 +529,7 @@ class Process(object):
procfs_path = get_procfs_path()
retlist = []
- rawlist = cext.proc_memory_maps(self.pid)
+ rawlist = cext.proc_memory_maps(self.pid, procfs_path)
hit_enoent = False
for item in rawlist:
addr, addrsize, perm, name, rss, anon, locked = item
@@ -559,7 +562,8 @@ class Process(object):
@wrap_exceptions
def num_ctx_switches(self):
- return _common.pctxsw(*cext.proc_num_ctx_switches(self.pid))
+ return _common.pctxsw(
+ *cext.proc_num_ctx_switches(self.pid, get_procfs_path()))
@wrap_exceptions
def wait(self, timeout=None):
diff --git a/psutil/_psutil_sunos.c b/psutil/_psutil_sunos.c
index 3be1f545..31933055 100644
--- a/psutil/_psutil_sunos.c
+++ b/psutil/_psutil_sunos.c
@@ -88,12 +88,14 @@ psutil_file_to_struct(char *path, void *fstruct, size_t size) {
static PyObject *
psutil_proc_basic_info(PyObject *self, PyObject *args) {
int pid;
- char path[100];
+ char path[1000];
psinfo_t info;
+ const char *procfs_path;
- if (! PyArg_ParseTuple(args, "i", &pid))
+ if (! PyArg_ParseTuple(args, "is", &pid, &procfs_path))
return NULL;
- sprintf(path, "/proc/%i/psinfo", pid);
+
+ sprintf(path, "%s/%i/psinfo", procfs_path, pid);
if (! psutil_file_to_struct(path, (void *)&info, sizeof(info)))
return NULL;
return Py_BuildValue("ikkdiiik",
@@ -115,12 +117,13 @@ psutil_proc_basic_info(PyObject *self, PyObject *args) {
static PyObject *
psutil_proc_name_and_args(PyObject *self, PyObject *args) {
int pid;
- char path[100];
+ char path[1000];
psinfo_t info;
+ const char *procfs_path;
- if (! PyArg_ParseTuple(args, "i", &pid))
+ if (! PyArg_ParseTuple(args, "is", &pid, &procfs_path))
return NULL;
- sprintf(path, "/proc/%i/psinfo", pid);
+ sprintf(path, "%s/%i/psinfo", procfs_path, pid);
if (! psutil_file_to_struct(path, (void *)&info, sizeof(info)))
return NULL;
return Py_BuildValue("ss", info.pr_fname, info.pr_psargs);
@@ -133,12 +136,13 @@ psutil_proc_name_and_args(PyObject *self, PyObject *args) {
static PyObject *
psutil_proc_cpu_times(PyObject *self, PyObject *args) {
int pid;
- char path[100];
+ char path[1000];
pstatus_t info;
+ const char *procfs_path;
- if (! PyArg_ParseTuple(args, "i", &pid))
+ if (! PyArg_ParseTuple(args, "is", &pid, &procfs_path))
return NULL;
- sprintf(path, "/proc/%i/status", pid);
+ sprintf(path, "%s/%i/status", procfs_path, pid);
if (! psutil_file_to_struct(path, (void *)&info, sizeof(info)))
return NULL;
// results are more precise than os.times()
@@ -154,12 +158,13 @@ psutil_proc_cpu_times(PyObject *self, PyObject *args) {
static PyObject *
psutil_proc_cred(PyObject *self, PyObject *args) {
int pid;
- char path[100];
+ char path[1000];
prcred_t info;
+ const char *procfs_path;
- if (! PyArg_ParseTuple(args, "i", &pid))
+ if (! PyArg_ParseTuple(args, "is", &pid, &procfs_path))
return NULL;
- sprintf(path, "/proc/%i/cred", pid);
+ sprintf(path, "%s/%i/cred", procfs_path, pid);
if (! psutil_file_to_struct(path, (void *)&info, sizeof(info)))
return NULL;
return Py_BuildValue("iiiiii",
@@ -174,12 +179,13 @@ psutil_proc_cred(PyObject *self, PyObject *args) {
static PyObject *
psutil_proc_num_ctx_switches(PyObject *self, PyObject *args) {
int pid;
- char path[100];
+ char path[1000];
prusage_t info;
+ const char *procfs_path;
- if (! PyArg_ParseTuple(args, "i", &pid))
+ if (! PyArg_ParseTuple(args, "is", &pid, &procfs_path))
return NULL;
- sprintf(path, "/proc/%i/usage", pid);
+ sprintf(path, "%s/%i/usage", procfs_path, pid);
if (! psutil_file_to_struct(path, (void *)&info, sizeof(info)))
return NULL;
return Py_BuildValue("kk", info.pr_vctx, info.pr_ictx);
@@ -200,12 +206,13 @@ psutil_proc_num_ctx_switches(PyObject *self, PyObject *args) {
static PyObject*
proc_io_counters(PyObject* self, PyObject* args) {
int pid;
- char path[100];
+ char path[1000];
prusage_t info;
+ const char *procfs_path;
- if (! PyArg_ParseTuple(args, "i", &pid))
+ if (! PyArg_ParseTuple(args, "is", &pid, &procfs_path))
return NULL;
- sprintf(path, "/proc/%i/usage", pid);
+ sprintf(path, "%s/%i/usage", procfs_path, pid);
if (! psutil_file_to_struct(path, (void *)&info, sizeof(info)))
return NULL;
@@ -229,12 +236,13 @@ proc_io_counters(PyObject* self, PyObject* args) {
static PyObject *
psutil_proc_query_thread(PyObject *self, PyObject *args) {
int pid, tid;
- char path[100];
+ char path[1000];
lwpstatus_t info;
+ const char *procfs_path;
- if (! PyArg_ParseTuple(args, "ii", &pid, &tid))
+ if (! PyArg_ParseTuple(args, "iis", &pid, &tid, &procfs_path))
return NULL;
- sprintf(path, "/proc/%i/lwp/%i/lwpstatus", pid, tid);
+ sprintf(path, "%s/%i/lwp/%i/lwpstatus", procfs_path, pid, tid);
if (! psutil_file_to_struct(path, (void *)&info, sizeof(info)))
return NULL;
return Py_BuildValue("dd",
@@ -545,7 +553,7 @@ static PyObject *
psutil_proc_memory_maps(PyObject *self, PyObject *args) {
int pid;
int fd = -1;
- char path[100];
+ char path[1000];
char perms[10];
char *name;
struct stat st;
@@ -557,20 +565,21 @@ psutil_proc_memory_maps(PyObject *self, PyObject *args) {
int nmap;
uintptr_t pr_addr_sz;
uintptr_t stk_base_sz, brk_base_sz;
+ const char *procfs_path;
PyObject *py_tuple = NULL;
PyObject *py_retlist = PyList_New(0);
if (py_retlist == NULL)
return NULL;
- if (! PyArg_ParseTuple(args, "i", &pid))
+ if (! PyArg_ParseTuple(args, "is", &pid, &procfs_path))
goto error;
- sprintf(path, "/proc/%i/status", pid);
+ sprintf(path, "%s/%i/status", procfs_path, pid);
if (! psutil_file_to_struct(path, (void *)&status, sizeof(status)))
goto error;
- sprintf(path, "/proc/%i/xmap", pid);
+ sprintf(path, "%s/%i/xmap", procfs_path, pid);
if (stat(path, &st) == -1) {
PyErr_SetFromErrno(PyExc_OSError);
goto error;