All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yang Xu <xuyang2018.jy@fujitsu.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v1 1/3] libs/libnewipc: Alter get_used_queues api
Date: Thu, 5 Aug 2021 11:48:41 +0800	[thread overview]
Message-ID: <1628135323-3722-1-git-send-email-xuyang2018.jy@fujitsu.com> (raw)

Rename get_used_queues as get_used_sysvipc and add a proc file argument, so we can use
GET_USED_QUEQUES() and GET_USED_SEGMENTS() to get the corresponding used sysvipc resource
total. Since no new api cases used get_used_queues(), we don't need to change anything.

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 include/libnewipc.h           |  6 ++++--
 libs/libltpnewipc/libnewipc.c | 16 ++++++++--------
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/include/libnewipc.h b/include/libnewipc.h
index 075364f85..52e054c51 100644
--- a/include/libnewipc.h
+++ b/include/libnewipc.h
@@ -49,9 +49,11 @@ key_t getipckey(const char *file, const int lineno);
 #define GETIPCKEY() \
 	getipckey(__FILE__, __LINE__)
 
-int get_used_queues(const char *file, const int lineno);
+int get_used_sysvipc(const char *file, const int lineno, const char *sysvipc_file);
 #define GET_USED_QUEUES() \
-	get_used_queues(__FILE__, __LINE__)
+	get_used_sysvipc(__FILE__, __LINE__, "/proc/sysvipc/msg")
+#define GET_USED_SEGMENTS() \
+	get_used_sysvipc(__FILE__, __LINE__, "/proc/sysvipc/shm")
 
 void *probe_free_addr(const char *file, const int lineno);
 #define PROBE_FREE_ADDR() \
diff --git a/libs/libltpnewipc/libnewipc.c b/libs/libltpnewipc/libnewipc.c
index d0974bbe0..583291ee0 100644
--- a/libs/libltpnewipc/libnewipc.c
+++ b/libs/libltpnewipc/libnewipc.c
@@ -48,25 +48,25 @@ key_t getipckey(const char *file, const int lineno)
 	return key;
 }
 
-int get_used_queues(const char *file, const int lineno)
+int get_used_sysvipc(const char *file, const int lineno, const char *sysvipc_file)
 {
 	FILE *fp;
-	int used_queues = -1;
+	int used = -1;
 	char buf[BUFSIZE];
 
-	fp = safe_fopen(file, lineno, NULL, "/proc/sysvipc/msg", "r");
+	fp = safe_fopen(file, lineno, NULL, sysvipc_file, "r");
 
 	while (fgets(buf, BUFSIZE, fp) != NULL)
-		used_queues++;
+		used++;
 
 	fclose(fp);
 
-	if (used_queues < 0) {
-		tst_brk(TBROK, "can't read /proc/sysvipc/msg to get "
-			"used message queues@%s:%d", file, lineno);
+	if (used < 0) {
+		tst_brk(TBROK, "can't read %s to get used sysvipc resource total "
+			"at %s:%d", sysvipc_file, file, lineno);
 	}
 
-	return used_queues;
+	return used;
 }
 
 void *probe_free_addr(const char *file, const int lineno)
-- 
2.23.0


             reply	other threads:[~2021-08-05  3:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-05  3:48 Yang Xu [this message]
2021-08-05  3:48 ` [LTP] [PATCH v1 2/3] syscalls/shmget03: Create shared memory segment dynamically instead of hardcode Yang Xu
2021-08-05  3:48 ` [LTP] [PATCH v1 3/3] syscalls/msgget03: Create message queues " Yang Xu
2021-08-05 13:03 ` [LTP] [PATCH v1 1/3] libs/libnewipc: Alter get_used_queues api Li Wang
2021-08-06  1:50   ` xuyang2018.jy

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=1628135323-3722-1-git-send-email-xuyang2018.jy@fujitsu.com \
    --to=xuyang2018.jy@fujitsu.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.