All of lore.kernel.org
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v5 1/3] lib/tst_pid: simplify error handling by callers of tst_get_free_pids()
Date: Fri, 20 Aug 2021 12:00:26 +0200	[thread overview]
Message-ID: <20210820100028.97487-2-krzysztof.kozlowski@canonical.com> (raw)
In-Reply-To: <20210820100028.97487-1-krzysztof.kozlowski@canonical.com>

Handle errors of getting free pids directly in the library instead of
tst_get_free_pids() caller.

Suggested-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
---
 lib/tst_pid.c                                         | 9 ++++++---
 testcases/kernel/syscalls/ipc/msgstress/msgstress04.c | 6 ------
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/lib/tst_pid.c b/lib/tst_pid.c
index c408172675a7..23753988ca57 100644
--- a/lib/tst_pid.c
+++ b/lib/tst_pid.c
@@ -107,15 +107,14 @@ int tst_get_free_pids_(void (*cleanup_fn) (void))
 
 	f = popen("ps -eT | wc -l", "r");
 	if (!f) {
-		tst_resm(TBROK, "Could not run 'ps' to calculate used " "pids");
+		tst_brkm(TBROK, cleanup_fn, "Could not run 'ps' to calculate used pids");
 		return -1;
 	}
 	rc = fscanf(f, "%i", &used_pids);
 	pclose(f);
 
 	if (rc != 1 || used_pids < 0) {
-		tst_resm(TBROK, "Could not read output of 'ps' to "
-			 "calculate used pids");
+		tst_brkm(TBROK, cleanup_fn, "Could not read output of 'ps' to calculate used pids");
 		return -1;
 	}
 
@@ -128,5 +127,9 @@ int tst_get_free_pids_(void (*cleanup_fn) (void))
 	/* max_pids contains the maximum PID + 1,
 	 * used_pids contains used PIDs + 1,
 	 * so this additional '1' is eliminated by the substraction */
+	if (used_pids >= max_pids) {
+		tst_brkm(TBROK, cleanup_fn, "No free pids");
+		return 0;
+	}
 	return max_pids - used_pids;
 }
diff --git a/testcases/kernel/syscalls/ipc/msgstress/msgstress04.c b/testcases/kernel/syscalls/ipc/msgstress/msgstress04.c
index f1c124990cb1..b9ebf9035c6d 100644
--- a/testcases/kernel/syscalls/ipc/msgstress/msgstress04.c
+++ b/testcases/kernel/syscalls/ipc/msgstress/msgstress04.c
@@ -413,12 +413,6 @@ void setup(void)
 	tst_resm(TINFO, "Found %d available message queues", MSGMNI);
 
 	free_pids = tst_get_free_pids(cleanup);
-	if (free_pids < 0) {
-		tst_brkm(TBROK, cleanup, "Can't obtain free_pid count");
-	} else if (!free_pids) {
-		tst_brkm(TBROK, cleanup, "No free pids");
-	}
-
 	/* We don't use more than a half of available pids.
 	 * For each child we fork up to 2*maxnkids grandchildren. */
 	maxnprocs = (free_pids / 2) / (1 + 2 * maxnkids);
-- 
2.30.2


  reply	other threads:[~2021-08-20 10:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-20 10:00 [LTP] [PATCH v5 0/3] syscalls/msgstress: fixes for small systems Krzysztof Kozlowski
2021-08-20 10:00 ` Krzysztof Kozlowski [this message]
2021-08-20 10:00 ` [LTP] [PATCH v5 2/3] syscalls/msgstress03: fix fork failure on small memory systems Krzysztof Kozlowski
2021-08-20 10:00 ` [LTP] [PATCH v5 3/3] syscalls/msgstress: tune limit of processes for small machines Krzysztof Kozlowski
2021-08-20 13:34   ` Cyril Hrubis
2021-08-26  9:50     ` Krzysztof Kozlowski
2021-08-20 13:34 ` [LTP] [PATCH v5 0/3] syscalls/msgstress: fixes for small systems 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=20210820100028.97487-2-krzysztof.kozlowski@canonical.com \
    --to=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 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.