Merge pull request #21217 from keszybz/debug-test-process-util
procfs-util: fix confusion wrt. quantity limit and maximum value
This commit is contained in:
@@ -851,8 +851,14 @@ static void test_get_process_ppid(void) {
|
||||
assert_se(get_process_ppid(1, NULL) == -EADDRNOTAVAIL);
|
||||
|
||||
/* the process with the PID above the global limit definitely doesn't exist. Verify that */
|
||||
assert_se(procfs_tasks_get_limit(&limit) >= 0);
|
||||
assert_se(limit >= INT_MAX || get_process_ppid(limit+1, NULL) == -ESRCH);
|
||||
assert_se(procfs_get_pid_max(&limit) >= 0);
|
||||
log_debug("kernel.pid_max = %"PRIu64, limit);
|
||||
|
||||
if (limit < INT_MAX) {
|
||||
r = get_process_ppid(limit + 1, NULL);
|
||||
log_debug_errno(r, "get_process_limit(%"PRIu64") → %d/%m", limit + 1, r);
|
||||
assert(r == -ESRCH);
|
||||
}
|
||||
|
||||
for (pid_t pid = 0;;) {
|
||||
_cleanup_free_ char *c1 = NULL, *c2 = NULL;
|
||||
|
||||
+25
-11
@@ -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;
|
||||
r = procfs_tasks_set_limit(v-1);
|
||||
assert_se(IN_SET(r, 0, -EPERM, -EACCES, -EROFS));
|
||||
log_info("Reducing limit by one to %"PRIu64"…", v-1);
|
||||
|
||||
assert_se(procfs_tasks_get_limit(&w) >= 0);
|
||||
assert_se((r == 0 && w == v - 1) || (r < 0 && w == v));
|
||||
r = procfs_tasks_set_limit(v-1);
|
||||
log_info_errno(r, "procfs_tasks_set_limit: %m");
|
||||
assert_se(r >= 0 || ERRNO_IS_PRIVILEGE(r) || r == -EROFS);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user