summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-05-15 17:34:14 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2020-05-15 17:34:14 +0200
commit2c113c6746d3558e47e575b4169ac15b636ddf57 (patch)
treed79d9a138f1c28c323fa5a320787ac35d8007e03
parentb543b3fddbcd9a1c931783e3f2230871a3e7ac9e (diff)
downloadpsutil-2c113c6746d3558e47e575b4169ac15b636ddf57.tar.gz
better #ifdef detection for prlimit() availbility
Rely on "__NR_prlimit64" availability and check GLIBC version only. Take kernel version out of the picture. This way it works on both CentOS 6 and 7. Also, have test_contracts.py tests assume prlimit() is always available, so that we will be notified (by failure). Ref: #1758
-rw-r--r--psutil/_psutil_linux.c7
-rwxr-xr-xpsutil/tests/test_contracts.py41
2 files changed, 22 insertions, 26 deletions
diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c
index 915ab9b4..5f00454b 100644
--- a/psutil/_psutil_linux.c
+++ b/psutil/_psutil_linux.c
@@ -42,11 +42,10 @@ 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 >= 13
+// Linux >= 2.6.36 (supposedly) and glibc >= 2.13
#define PSUTIL_HAVE_PRLIMIT \
- (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)) && \
- (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 13) && \
- defined(__NR_prlimit64)
+ defined(__NR_prlimit64) && \
+ (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 13)
#if PSUTIL_HAVE_PRLIMIT
#define _FILE_OFFSET_BITS 64
diff --git a/psutil/tests/test_contracts.py b/psutil/tests/test_contracts.py
index edeb1d9a..e9c68a91 100755
--- a/psutil/tests/test_contracts.py
+++ b/psutil/tests/test_contracts.py
@@ -34,7 +34,6 @@ from psutil._compat import long
from psutil._compat import range
from psutil.tests import create_sockets
from psutil.tests import enum
-from psutil.tests import get_kernel_version
from psutil.tests import HAS_CPU_FREQ
from psutil.tests import HAS_NET_IO_COUNTERS
from psutil.tests import HAS_SENSORS_FANS
@@ -87,27 +86,25 @@ class TestAvailConstantsAPIs(PsutilTestCase):
def test_linux_rlimit(self):
ae = self.assertEqual
- hasit = LINUX and get_kernel_version() >= (2, 6, 36)
- ae(hasattr(psutil.Process, "rlimit"), hasit)
- ae(hasattr(psutil, "RLIM_INFINITY"), hasit)
- ae(hasattr(psutil, "RLIMIT_AS"), hasit)
- ae(hasattr(psutil, "RLIMIT_CORE"), hasit)
- ae(hasattr(psutil, "RLIMIT_CPU"), hasit)
- ae(hasattr(psutil, "RLIMIT_DATA"), hasit)
- ae(hasattr(psutil, "RLIMIT_FSIZE"), hasit)
- ae(hasattr(psutil, "RLIMIT_LOCKS"), hasit)
- ae(hasattr(psutil, "RLIMIT_MEMLOCK"), hasit)
- ae(hasattr(psutil, "RLIMIT_NOFILE"), hasit)
- ae(hasattr(psutil, "RLIMIT_NPROC"), hasit)
- ae(hasattr(psutil, "RLIMIT_RSS"), hasit)
- ae(hasattr(psutil, "RLIMIT_STACK"), hasit)
-
- hasit = LINUX and get_kernel_version() >= (3, 0)
- ae(hasattr(psutil, "RLIMIT_MSGQUEUE"), hasit)
- ae(hasattr(psutil, "RLIMIT_NICE"), hasit)
- ae(hasattr(psutil, "RLIMIT_RTPRIO"), hasit)
- ae(hasattr(psutil, "RLIMIT_RTTIME"), hasit)
- ae(hasattr(psutil, "RLIMIT_SIGPENDING"), hasit)
+ ae(hasattr(psutil.Process, "rlimit"), LINUX) # requires Linux 2.6.36
+ ae(hasattr(psutil, "RLIM_INFINITY"), LINUX)
+ ae(hasattr(psutil, "RLIMIT_AS"), LINUX)
+ ae(hasattr(psutil, "RLIMIT_CORE"), LINUX)
+ ae(hasattr(psutil, "RLIMIT_CPU"), LINUX)
+ ae(hasattr(psutil, "RLIMIT_DATA"), LINUX)
+ ae(hasattr(psutil, "RLIMIT_FSIZE"), LINUX)
+ ae(hasattr(psutil, "RLIMIT_LOCKS"), LINUX)
+ ae(hasattr(psutil, "RLIMIT_MEMLOCK"), LINUX)
+ ae(hasattr(psutil, "RLIMIT_NOFILE"), LINUX)
+ ae(hasattr(psutil, "RLIMIT_NPROC"), LINUX)
+ ae(hasattr(psutil, "RLIMIT_RSS"), LINUX)
+ ae(hasattr(psutil, "RLIMIT_STACK"), LINUX)
+
+ ae(hasattr(psutil, "RLIMIT_MSGQUEUE"), LINUX) # requires Linux 2.6.8
+ ae(hasattr(psutil, "RLIMIT_NICE"), LINUX) # requires Linux 2.6.12
+ ae(hasattr(psutil, "RLIMIT_RTPRIO"), LINUX) # requires Linux 2.6.12
+ ae(hasattr(psutil, "RLIMIT_RTTIME"), LINUX) # requires Linux 2.6.25
+ ae(hasattr(psutil, "RLIMIT_SIGPENDING"), LINUX) # requires Linux 2.6.8
class TestAvailSystemAPIs(PsutilTestCase):