diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2017-05-28 21:45:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-28 21:45:36 +0200 |
commit | 94fca1d2ea8f35f999286e74211cc5a4b4255bf1 (patch) | |
tree | cd217d1235929584df4a3d9e3e7903afa1e38509 /psutil/_psutil_sunos.c | |
parent | 68e04def9b1f04462fa8f2eefcc5287b1b943cfe (diff) | |
download | psutil-94fca1d2ea8f35f999286e74211cc5a4b4255bf1.tar.gz |
Fix 1091 nitpicks (#1097)
* rename C module
* rename C file
* fix compilation error
* small refactoring
* small refactoring
* raise AccessDenied if info.pr_envp is empty, see https://github.com/giampaolo/psutil/pull/1091#issuecomment-304530771
* fix envs with no equal sign
* style
* update doc
* style
Diffstat (limited to 'psutil/_psutil_sunos.c')
-rw-r--r-- | psutil/_psutil_sunos.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/psutil/_psutil_sunos.c b/psutil/_psutil_sunos.c index 0af8bc47..12caaec7 100644 --- a/psutil/_psutil_sunos.c +++ b/psutil/_psutil_sunos.c @@ -50,7 +50,7 @@ #include "_psutil_common.h" #include "_psutil_posix.h" -#include "arch/solaris/process_as_utils.h" +#include "arch/solaris/environ.h" #define PSUTIL_TV2DOUBLE(t) (((t).tv_nsec * 0.000000001) + (t).tv_sec) @@ -156,8 +156,9 @@ error: return NULL; } + /* - * Return process environ block + * Return process environ block. */ static PyObject * psutil_proc_environ(PyObject *self, PyObject *args) { @@ -169,35 +170,36 @@ psutil_proc_environ(PyObject *self, PyObject *args) { ssize_t env_count = -1; char *dm; int i = 0; - PyObject *py_retdict = NULL; PyObject *py_envname = NULL; PyObject *py_envval = NULL; + PyObject *py_retdict = PyDict_New(); + + if (! py_retdict) + return PyErr_NoMemory(); if (! PyArg_ParseTuple(args, "is", &pid, &procfs_path)) - goto error; + return NULL; sprintf(path, "%s/%i/psinfo", procfs_path, pid); if (! psutil_file_to_struct(path, (void *)&info, sizeof(info))) goto error; - env = psutil_read_raw_env(info, procfs_path, &env_count); - if (! env && env_count != 0) + if (! info.pr_envp) { + AccessDenied(); goto error; + } - py_retdict = PyDict_New(); - if (! py_retdict) { - PyErr_NoMemory(); + env = psutil_read_raw_env(info, procfs_path, &env_count); + if (! env && env_count != 0) goto error; - } for (i=0; i<env_count; i++) { if (! env[i]) break; - /* Environment corrupted */ dm = strchr(env[i], '='); if (! dm) - break; + continue; *dm = '\0'; @@ -229,6 +231,7 @@ psutil_proc_environ(PyObject *self, PyObject *args) { return NULL; } + /* * Return process user and system CPU times as a Python tuple. */ |