public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Joerg Vehlow <lkml@jv-coder.de>
To: ltp@lists.linux.it, chrubis@suse.cz, krzysztof.kozlowski@canonical.com
Cc: Joerg Vehlow <joerg.vehlow@aox-tech.de>
Subject: [LTP] [PATCH] tst_pid: Fix read_session_pids_limit if pids.max is max
Date: Mon, 20 Sep 2021 13:58:14 +0200	[thread overview]
Message-ID: <20210920115814.296041-1-lkml@jv-coder.de> (raw)

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

             reply	other threads:[~2021-09-20 11:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-20 11:58 Joerg Vehlow [this message]
2021-09-20 12:30 ` [LTP] [PATCH] tst_pid: Fix read_session_pids_limit if pids.max is max Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210920115814.296041-1-lkml@jv-coder.de \
    --to=lkml@jv-coder.de \
    --cc=chrubis@suse.cz \
    --cc=joerg.vehlow@aox-tech.de \
    --cc=krzysztof.kozlowski@canonical.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox