diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-11-02 18:18:21 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-11-03 09:36:08 +0100 |
commit | c3dead53d50e334f2d072a2248256983d6dc9f8c (patch) | |
tree | 2926cf5000538c86ae1f221328eeac49523919e5 /src/test/test-procfs-util.c | |
parent | Merge pull request #21209 from yuwata/veth-peer-mtu (diff) | |
download | systemd-c3dead53d50e334f2d072a2248256983d6dc9f8c.tar.xz systemd-c3dead53d50e334f2d072a2248256983d6dc9f8c.zip |
procfs-util: fix confusion wrt. quantity limit and maximum value
From packit/rawhide-arm64 logs:
Assertion 'limit >= INT_MAX || get_process_ppid(limit+1, NULL) == -ESRCH' failed at src/test/test-process-util.c:855, function test_get_process_ppid(). Aborting.
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
The kernel has a few different limits. In particular kernel.threads-max can be
set to some lower value, and kernel.pid_max can be set to a higher value. This
is nice because it reduces PID reuse, even if the number of threads that is
allowed is limited. But the tests assumed that we cannot have a thread with
PID above MIN(kernel.threads-max, kernel.pid_max-1), which is not valid.
So let's rework the whole thing: let's expose the helpers to read
kernel.threads-max and kernel.pid_max, and print what they return in tests.
procfs_tasks_get_limit() was something that is only used in tests, and wasn't
very well defined, so let's drop it.
Fixes #21193.
Diffstat (limited to '')
-rw-r--r-- | src/test/test-procfs-util.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/src/test/test-procfs-util.c b/src/test/test-procfs-util.c index a961436b40..fb9894d280 100644 --- a/src/test/test-procfs-util.c +++ b/src/test/test-procfs-util.c @@ -6,11 +6,12 @@ #include "format-util.h" #include "log.h" #include "procfs-util.h" +#include "process-util.h" #include "tests.h" int main(int argc, char *argv[]) { nsec_t nsec; - uint64_t v; + uint64_t v, w; int r; log_parse_environment(); @@ -25,26 +26,39 @@ int main(int argc, char *argv[]) { assert_se(procfs_tasks_get_current(&v) >= 0); log_info("Current number of tasks: %" PRIu64, v); - r = procfs_tasks_get_limit(&v); - if (r == -ENOENT || ERRNO_IS_PRIVILEGE(r)) - return log_tests_skipped("can't read /proc/sys/kernel/pid_max"); + v = TASKS_MAX; + r = procfs_get_pid_max(&v); + assert(r >= 0 || r == -ENOENT || ERRNO_IS_PRIVILEGE(r)); + log_info("kernel.pid_max: %"PRIu64, v); + + w = TASKS_MAX; + r = procfs_get_threads_max(&w); + assert(r >= 0 || r == -ENOENT || ERRNO_IS_PRIVILEGE(r)); + log_info("kernel.threads-max: %"PRIu64, w); + + v = MIN(v - (v > 0), w); assert_se(r >= 0); log_info("Limit of tasks: %" PRIu64, v); assert_se(v > 0); - assert_se(procfs_tasks_set_limit(v) >= 0); + r = procfs_tasks_set_limit(v); + if (r == -ENOENT || ERRNO_IS_PRIVILEGE(r)) + return log_tests_skipped("can't set task limits"); + assert(r >= 0); if (v > 100) { - uint64_t w; + log_info("Reducing limit by one to %"PRIu64"…", v-1); + r = procfs_tasks_set_limit(v-1); - assert_se(IN_SET(r, 0, -EPERM, -EACCES, -EROFS)); + log_info_errno(r, "procfs_tasks_set_limit: %m"); + assert_se(r >= 0 || ERRNO_IS_PRIVILEGE(r)); - assert_se(procfs_tasks_get_limit(&w) >= 0); - assert_se((r == 0 && w == v - 1) || (r < 0 && w == v)); + assert_se(procfs_get_threads_max(&w) >= 0); + assert_se(r >= 0 ? w == v - 1 : w == v); assert_se(procfs_tasks_set_limit(v) >= 0); - assert_se(procfs_tasks_get_limit(&w) >= 0); + assert_se(procfs_get_threads_max(&w) >= 0); assert_se(v == w); } |