tst_pid: Fix read_session_pids_limit if pids.max is max
PATCH 1/1 tst_pid: Fix read_session_pids_limit if pids.max is max
From: Joerg Vehlow <[email protected]>
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 <[email protected]>
---
@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(-)
lib/tst_pid.c +10 -2
@@ -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; }
Signature · 5 lines
2.25.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Pushed with two minor fixes, thanks.
- got rid of trailing whitespace
- changed strcmp() == 0 to more common !strcmp()
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp