summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2015-08-07 13:49:33 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2015-08-07 13:49:33 +0200
commit3226e941cebd784f75af9bbc0d5ad13f635a1695 (patch)
tree1c4980105dfcb6f7abbc2137b96c2faaeaac10c2
parent5df3b81eb8383b2f533de37311e386aede444305 (diff)
downloadpsutil-3226e941cebd784f75af9bbc0d5ad13f635a1695.tar.gz
fix #513: [Linux] fixed integer overflow for RLIM_INFINITY.
-rw-r--r--HISTORY.rst1
-rw-r--r--psutil/_psutil_linux.c15
-rw-r--r--test/test_psutil.py16
3 files changed, 31 insertions, 1 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index 706945a0..60574ce0 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -10,6 +10,7 @@ Bug tracker at https://github.com/giampaolo/psutil/issues
**Bug fixes**
+- #513: [Linux] fixed integer overflow for RLIM_INFINITY.
- #641: [Windows] fixed many compilation warnings. (patch by Jeff Tang)
- #659: [Linux] compilation error on Suse 10.
- #664: [Linux] compilation error on Alpine Linux. (patch by Bart van Kleef)
diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c
index 5c365939..697c81b0 100644
--- a/psutil/_psutil_linux.c
+++ b/psutil/_psutil_linux.c
@@ -638,7 +638,6 @@ void init_psutil_linux(void)
PyModule_AddIntConstant(module, "version", PSUTIL_VERSION);
#if PSUTIL_HAVE_PRLIMIT
- PyModule_AddIntConstant(module, "RLIM_INFINITY", RLIM_INFINITY);
PyModule_AddIntConstant(module, "RLIMIT_AS", RLIMIT_AS);
PyModule_AddIntConstant(module, "RLIMIT_CORE", RLIMIT_CORE);
PyModule_AddIntConstant(module, "RLIMIT_CPU", RLIMIT_CPU);
@@ -650,6 +649,20 @@ void init_psutil_linux(void)
PyModule_AddIntConstant(module, "RLIMIT_NPROC", RLIMIT_NPROC);
PyModule_AddIntConstant(module, "RLIMIT_RSS", RLIMIT_RSS);
PyModule_AddIntConstant(module, "RLIMIT_STACK", RLIMIT_STACK);
+
+ PyObject *v;
+#if defined(HAVE_LONG_LONG)
+ if (sizeof(RLIM_INFINITY) > sizeof(long)) {
+ v = PyLong_FromLongLong((PY_LONG_LONG) RLIM_INFINITY);
+ } else
+#endif
+ {
+ v = PyLong_FromLong((long) RLIM_INFINITY);
+ }
+ if (v) {
+ PyModule_AddObject(module, "RLIM_INFINITY", v);
+ }
+
#ifdef RLIMIT_MSGQUEUE
PyModule_AddIntConstant(module, "RLIMIT_MSGQUEUE", RLIMIT_MSGQUEUE);
#endif
diff --git a/test/test_psutil.py b/test/test_psutil.py
index 4daeaf36..954481c0 100644
--- a/test/test_psutil.py
+++ b/test/test_psutil.py
@@ -1517,6 +1517,22 @@ class TestProcess(unittest.TestCase):
p.rlimit(psutil.RLIMIT_FSIZE, (soft, hard))
self.assertEqual(p.rlimit(psutil.RLIMIT_FSIZE), (soft, hard))
+ @unittest.skipUnless(LINUX and RLIMIT_SUPPORT,
+ "only available on Linux >= 2.6.36")
+ def test_rlimit_infinity(self):
+ # First set a limit, then re-set it by specifying INFINITY
+ # and assume we overridden the previous limit.
+ p = psutil.Process()
+ soft, hard = p.rlimit(psutil.RLIMIT_FSIZE)
+ try:
+ p.rlimit(psutil.RLIMIT_FSIZE, (1024, hard))
+ p.rlimit(psutil.RLIMIT_FSIZE, (psutil.RLIM_INFINITY, hard))
+ with open(TESTFN, "wb") as f:
+ f.write(b"X" * 2048)
+ finally:
+ p.rlimit(psutil.RLIMIT_FSIZE, (soft, hard))
+ self.assertEqual(p.rlimit(psutil.RLIMIT_FSIZE), (soft, hard))
+
def test_num_threads(self):
# on certain platforms such as Linux we might test for exact
# thread number, since we always have with 1 thread per process,