diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2020-11-15 00:27:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-15 00:27:05 +0100 |
commit | 8fc5ed1b20c9c9fab75164aae1984698a46974dc (patch) | |
tree | d588d132137ce6b47c34ccc8c59117d2e75cb0b4 /psutil/_psutil_linux.c | |
parent | fd69f22ee5ca38ceff32ae3fac15420c5d8fce29 (diff) | |
download | psutil-8fc5ed1b20c9c9fab75164aae1984698a46974dc.tar.gz |
Rewrite Linux prlimit() with ctypes (Linux wheels) (#1879)
Diffstat (limited to 'psutil/_psutil_linux.c')
-rw-r--r-- | psutil/_psutil_linux.c | 76 |
1 files changed, 1 insertions, 75 deletions
diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c index 4def9692..5836cd6b 100644 --- a/psutil/_psutil_linux.c +++ b/psutil/_psutil_linux.c @@ -23,6 +23,7 @@ #include <sys/socket.h> #include <linux/sockios.h> #include <linux/if.h> +#include <sys/resource.h> // see: https://github.com/giampaolo/psutil/issues/659 #ifdef PSUTIL_ETHTOOL_MISSING_TYPES @@ -42,17 +43,6 @@ static const int NCPUS_START = sizeof(unsigned long) * CHAR_BIT; // Linux >= 2.6.13 #define PSUTIL_HAVE_IOPRIO defined(__NR_ioprio_get) && defined(__NR_ioprio_set) -// Linux >= 2.6.36 (supposedly) and glibc >= 2.13 -#define PSUTIL_HAVE_PRLIMIT \ - defined(__NR_prlimit64) && \ - (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 13) - -#if PSUTIL_HAVE_PRLIMIT - #define _FILE_OFFSET_BITS 64 - #include <time.h> - #include <sys/resource.h> -#endif - // Should exist starting from CentOS 6 (year 2011). #ifdef CPU_ALLOC #define PSUTIL_HAVE_CPU_AFFINITY @@ -133,66 +123,6 @@ psutil_proc_ioprio_set(PyObject *self, PyObject *args) { #endif -#if PSUTIL_HAVE_PRLIMIT -/* - * A wrapper around prlimit(2); sets process resource limits. - * This can be used for both get and set, in which case extra - * 'soft' and 'hard' args must be provided. - */ -static PyObject * -psutil_linux_prlimit(PyObject *self, PyObject *args) { - pid_t pid; - int ret, resource; - struct rlimit old, new; - struct rlimit *newp = NULL; - PyObject *py_soft = NULL; - PyObject *py_hard = NULL; - - if (! PyArg_ParseTuple(args, _Py_PARSE_PID "i|OO", &pid, &resource, - &py_soft, &py_hard)) { - return NULL; - } - - // get - if (py_soft == NULL && py_hard == NULL) { - ret = prlimit(pid, resource, NULL, &old); - if (ret == -1) - return PyErr_SetFromErrno(PyExc_OSError); - if (sizeof(old.rlim_cur) > sizeof(long)) { - return Py_BuildValue("LL", - (PY_LONG_LONG)old.rlim_cur, - (PY_LONG_LONG)old.rlim_max); - } - return Py_BuildValue("ll", (long)old.rlim_cur, (long)old.rlim_max); - } - - // set - else { -#if defined(HAVE_LONG_LONG) - new.rlim_cur = PyLong_AsLongLong(py_soft); - if (new.rlim_cur == (rlim_t) - 1 && PyErr_Occurred()) - return NULL; - new.rlim_max = PyLong_AsLongLong(py_hard); - if (new.rlim_max == (rlim_t) - 1 && PyErr_Occurred()) - return NULL; -#else - new.rlim_cur = PyLong_AsLong(py_soft); - if (new.rlim_cur == (rlim_t) - 1 && PyErr_Occurred()) - return NULL; - new.rlim_max = PyLong_AsLong(py_hard); - if (new.rlim_max == (rlim_t) - 1 && PyErr_Occurred()) - return NULL; -#endif - newp = &new; - ret = prlimit(pid, resource, newp, &old); - if (ret == -1) - return PyErr_SetFromErrno(PyExc_OSError); - Py_RETURN_NONE; - } -} -#endif - - /* * Return disk mounted partitions as a list of tuples including device, * mount point and filesystem type @@ -572,10 +502,6 @@ static PyMethodDef mod_methods[] = { {"linux_sysinfo", psutil_linux_sysinfo, METH_VARARGS, "A wrapper around sysinfo(), return system memory usage statistics"}, -#if PSUTIL_HAVE_PRLIMIT - {"linux_prlimit", psutil_linux_prlimit, METH_VARARGS, - "Get or set process resource limits."}, -#endif // --- others {"set_testing", psutil_set_testing, METH_NOARGS, "Set psutil in testing mode"}, |