[LTP] [PATCH] tst_pid: Fix read_session_pids_limit if pids.max is max

Joerg Vehlow lkml@jv-coder.de
Mon Sep 20 13:58:14 CEST 2021


From: Joerg Vehlow <joerg.vehlow@aox-tech.de>

The pids cgroup controller knob pids.max is allowed to be set to max.
This lead to a failure, when SAFE_FILE_SCANF with "%d" was used.

If pids.max=max, we can assume unlimited pids
=> read /proc/sys/kernel/pid_max

Signed-off-by: Joerg Vehlow <joerg.vehlow@aox-tech.de>
---

@Cyril: This should propably be merged before the release,
because it breaks some tests (e.g. msgstress03 and msgstress04)

 lib/tst_pid.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/lib/tst_pid.c b/lib/tst_pid.c
index 897a1b96a..55a316429 100644
--- a/lib/tst_pid.c
+++ b/lib/tst_pid.c
@@ -28,6 +28,7 @@
 #include "test.h"
 #include "tst_pid.h"
 #include "old_safe_file_ops.h"
+#include "tst_safe_macros.h"
 
 #define PID_MAX_PATH "/proc/sys/kernel/pid_max"
 #define CGROUPS_V1_SLICE_FMT "/sys/fs/cgroup/pids/user.slice/user-%d.slice/pids.max"
@@ -69,6 +70,7 @@ static int read_session_pids_limit(const char *path_fmt, int uid,
 				   void (*cleanup_fn) (void))
 {
 	int max_pids, ret;
+	char max_pid_value[100];
 	char path[PATH_MAX];
 
 	ret = snprintf(path, sizeof(path), path_fmt, uid);
@@ -80,8 +82,14 @@ static int read_session_pids_limit(const char *path_fmt, int uid,
 		return -1;
 	}
 
-	SAFE_FILE_SCANF(cleanup_fn, path, "%d", &max_pids);
-	tst_resm(TINFO, "Found limit of processes %d (from %s)", max_pids, path);
+	SAFE_FILE_SCANF(cleanup_fn, path, "%s", max_pid_value);
+	if (strcmp(max_pid_value, "max") == 0) {
+		SAFE_FILE_SCANF(cleanup_fn, PID_MAX_PATH, "%d", &max_pids);
+		tst_resm(TINFO, "Found limit of processes %d (from %s=max)", max_pids, path);
+	} else {
+		max_pids = SAFE_STRTOL(max_pid_value, 0, INT_MAX);
+		tst_resm(TINFO, "Found limit of processes %d (from %s)", max_pids, path);
+	}	
 
 	return max_pids;
 }
-- 
2.25.1



More information about the ltp mailing list