From: Dan Streetman Date: Wed, 19 May 2021 18:22:28 +0000 (-0400) Subject: psi: update is_pressure_supported to read file X-Git-Tag: v249-rc1~183^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0de2fd18705caa49fc1179e241cd2fbb22bd42e3;p=thirdparty%2Fsystemd.git psi: update is_pressure_supported to read file The kernel still provides the /proc and cgroup pressure files even if its psi support is disabled, so we need to actually read the files to verify they don't return -EOPNOTSUPP --- diff --git a/src/shared/psi-util.c b/src/shared/psi-util.c index 7a184d53f7b..97a43537922 100644 --- a/src/shared/psi-util.c +++ b/src/shared/psi-util.c @@ -4,6 +4,7 @@ #include #include "alloc-util.h" +#include "errno-util.h" #include "extract-word.h" #include "fd-util.h" #include "fileio.h" @@ -107,12 +108,18 @@ int read_resource_pressure(const char *path, PressureType type, ResourcePressure int is_pressure_supported(void) { const char *p; - FOREACH_STRING(p, "/proc/pressure/cpu", "/proc/pressure/io", "/proc/pressure/memory") - if (access(p, F_OK) < 0) { - if (errno == ENOENT) - return 0; - return -errno; - } + /* The pressure files, both under /proc and in cgroups, will exist + * even if the kernel has PSI support disabled; we have to read + * the file to make sure it doesn't return -EOPNOTSUPP */ + FOREACH_STRING(p, "/proc/pressure/cpu", "/proc/pressure/io", "/proc/pressure/memory") { + int r; + + r = read_virtual_file(p, 0, NULL, NULL); + if (r == -ENOENT || ERRNO_IS_NOT_SUPPORTED(r)) + return 0; + if (r < 0) + return r; + } return 1; }