All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin Doucha <mdoucha@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 1/4] Add SAFE_SYSINFO() macro
Date: Tue, 25 Aug 2020 18:07:32 +0200	[thread overview]
Message-ID: <20200825160735.24602-2-mdoucha@suse.cz> (raw)
In-Reply-To: <20200825160735.24602-1-mdoucha@suse.cz>

Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---

Changes since v1: New patch

 include/tst_safe_macros.h |  5 +++++
 lib/safe_macros.c         | 20 ++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 000381c4f..053c3bcf9 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -12,6 +12,7 @@
 #include <sys/resource.h>
 #include <sys/stat.h>
 #include <sys/vfs.h>
+#include <sys/sysinfo.h>
 #include <fcntl.h>
 #include <libgen.h>
 #include <signal.h>
@@ -598,4 +599,8 @@ long tst_safe_ptrace(const char *file, const int lineno, int req, pid_t pid,
 #define SAFE_PTRACE(req, pid, addr, data) \
 	tst_safe_ptrace(__FILE__, __LINE__, req, pid, addr, data)
 
+int safe_sysinfo(const char *file, const int lineno, struct sysinfo *info);
+#define SAFE_SYSINFO(info) \
+	safe_sysinfo(__FILE__, __LINE__, (info))
+
 #endif /* SAFE_MACROS_H__ */
diff --git a/lib/safe_macros.c b/lib/safe_macros.c
index dde9b7b5e..5ef9ee1c5 100644
--- a/lib/safe_macros.c
+++ b/lib/safe_macros.c
@@ -11,6 +11,7 @@
 #include <sys/wait.h>
 #include <sys/mount.h>
 #include <sys/xattr.h>
+#include <sys/sysinfo.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <libgen.h>
@@ -1088,3 +1089,22 @@ int safe_mincore(const char *file, const int lineno, void *start,
 
 	return rval;
 }
+
+int safe_sysinfo(const char *file, const int lineno, struct sysinfo *info)
+{
+	int ret;
+
+	errno = 0;
+	ret = sysinfo(info);
+
+	if (ret == -1) {
+		tst_brkm_(file, lineno, TBROK | TERRNO, NULL,
+			"sysinfo() failed");
+	} else if (ret) {
+		tst_brkm_(file, lineno, TBROK | TERRNO, NULL,
+			"Invalid sysinfo() return value %d", ret);
+
+	}
+
+	return ret;
+}
-- 
2.28.0


  reply	other threads:[~2020-08-25 16:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-25 16:07 [LTP] [PATCH v2 0/4] Improve reliability of ioctl_sg01 Martin Doucha
2020-08-25 16:07 ` Martin Doucha [this message]
2020-09-02 11:39   ` [LTP] [PATCH v2 1/4] Add SAFE_SYSINFO() macro Petr Vorel
2020-08-25 16:07 ` [LTP] [PATCH v2 2/4] Add tst_pollute_memory() helper function Martin Doucha
2020-09-02 17:05   ` Petr Vorel
2020-08-25 16:07 ` [LTP] [PATCH v2 3/4] ioctl_sg01: Pollute free memory in setup Martin Doucha
2020-09-02 17:13   ` Petr Vorel
2020-08-25 16:07 ` [LTP] [PATCH v2 4/4] ioctl_sg01: Loop data leak check 100 times Martin Doucha
2020-09-02 17:17   ` Petr Vorel
2020-09-03 13:19     ` Martin Doucha
2020-09-03 14:03       ` Petr Vorel
2020-09-03 14:22 ` [LTP] [PATCH v2 0/4] Improve reliability of ioctl_sg01 Petr Vorel

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=20200825160735.24602-2-mdoucha@suse.cz \
    --to=mdoucha@suse.cz \
    --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.