* [LTP] [PATCH] tst_pid: Fix read_session_pids_limit if pids.max is max
@ 2021-09-20 11:58 Joerg Vehlow
2021-09-20 12:30 ` Cyril Hrubis
0 siblings, 1 reply; 2+ messages in thread
From: Joerg Vehlow @ 2021-09-20 11:58 UTC (permalink / raw)
To: ltp, chrubis, krzysztof.kozlowski; +Cc: Joerg Vehlow
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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [LTP] [PATCH] tst_pid: Fix read_session_pids_limit if pids.max is max
2021-09-20 11:58 [LTP] [PATCH] tst_pid: Fix read_session_pids_limit if pids.max is max Joerg Vehlow
@ 2021-09-20 12:30 ` Cyril Hrubis
0 siblings, 0 replies; 2+ messages in thread
From: Cyril Hrubis @ 2021-09-20 12:30 UTC (permalink / raw)
To: Joerg Vehlow; +Cc: Joerg Vehlow, ltp
Hi!
Pushed with two minor fixes, thanks.
- got rid of trailing whitespace
- changed strcmp() == 0 to more common !strcmp()
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-09-20 12:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-20 11:58 [LTP] [PATCH] tst_pid: Fix read_session_pids_limit if pids.max is max Joerg Vehlow
2021-09-20 12:30 ` Cyril Hrubis
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.