diff options
| author | Giampaolo Rodola' <g.rodola@gmail.com> | 2013-10-07 22:55:03 +0200 |
|---|---|---|
| committer | Giampaolo Rodola' <g.rodola@gmail.com> | 2013-10-07 22:55:03 +0200 |
| commit | 6725532e55b4207f02f98543e3625be5a8eae532 (patch) | |
| tree | b3e1450c18b7e4285deb6540f7fa3ab3bf15cfcc /psutil/_psutil_linux.c | |
| parent | fddbd031d341b9f1c17a60ef120efb54543b9925 (diff) | |
| download | psutil-6725532e55b4207f02f98543e3625be5a8eae532.tar.gz | |
fix prlimit() related warnings; also, use cPython's resource.c as an example as to how interpret set data
Diffstat (limited to 'psutil/_psutil_linux.c')
| -rw-r--r-- | psutil/_psutil_linux.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c index 00ac40a9..1f5e8f07 100644 --- a/psutil/_psutil_linux.c +++ b/psutil/_psutil_linux.c @@ -117,18 +117,11 @@ linux_prlimit(PyObject* self, PyObject* args) long pid; int ret, resource; struct rlimit old, new; - struct rlimit *newp; + struct rlimit *newp = NULL; PyObject *soft = NULL; PyObject *hard = NULL; - if (! PyArg_ParseTuple(args, -#if defined(HAVE_LONG_LONG) - "li|LL", -#else - "li|ll", -#endif - &pid, &resource, &soft, &hard)) - { + if (! PyArg_ParseTuple(args, "li|OO", &pid, &resource, &soft, &hard)) { return NULL; } @@ -146,11 +139,24 @@ linux_prlimit(PyObject* self, PyObject* args) return Py_BuildValue("ll", (long)old.rlim_cur, (long)old.rlim_max); } + // set else { - newp = NULL; - new.rlim_cur = soft; - new.rlim_max = hard; +#if defined(HAVE_LARGEFILE_SUPPORT) + new.rlim_cur = PyLong_AsLongLong(soft); + if (new.rlim_cur == (rlim_t)-1 && PyErr_Occurred()) + return NULL; + new.rlim_max = PyLong_AsLongLong(hard); + if (new.rlim_max == (rlim_t)-1 && PyErr_Occurred()) + return NULL; +#else + new.rlim_cur = PyLong_AsLong(soft); + if (new.rlim_cur == (rlim_t)-1 && PyErr_Occurred()) + return NULL; + new.rlim_max = PyLong_AsLong(hard); + if (new.rlim_max == (rlim_t)-1 && PyErr_Occurred()) + return NULL; +#endif newp = &new; ret = prlimit(pid, resource, newp, &old); if (ret == -1) |
