mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-21 09:33:57 +03:00
psi-util: fix error handling
We checked ERRNO_IS_NOT_SUPPORTED on a possible positive non-error code, which isn't right. Fix that. Also add caching, since we are about to call this more often. (cherry picked from commit90ec8ebe33
) (cherry picked from commit5ee19fdfa0
) (cherry picked from commit8e6234064d
) (cherry picked from commitcb4f512f47
)
This commit is contained in:
parent
5d0fb9483a
commit
fadf3c4099
@ -106,20 +106,25 @@ int read_resource_pressure(const char *path, PressureType type, ResourcePressure
|
||||
}
|
||||
|
||||
int is_pressure_supported(void) {
|
||||
static thread_local int cached = -1;
|
||||
const char *p;
|
||||
int r;
|
||||
|
||||
/* 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 */
|
||||
|
||||
if (cached >= 0)
|
||||
return cached;
|
||||
|
||||
/* 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)
|
||||
if (r < 0) {
|
||||
if (r == -ENOENT || ERRNO_IS_NOT_SUPPORTED(r))
|
||||
return (cached = false);
|
||||
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
return (cached = true);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user