All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] Add SAFE_ACCESS macro
@ 2022-03-14 17:28 Dai Shili
  2022-03-14 17:28 ` [LTP] [PATCH 2/2] Make use of SAFE_ACCESS Dai Shili
  0 siblings, 1 reply; 27+ messages in thread
From: Dai Shili @ 2022-03-14 17:28 UTC (permalink / raw)
  To: ltp

Signed-off-by: Dai Shili <daisl.fnst@fujitsu.com>
---
 include/old/safe_macros.h |  3 +++
 include/safe_macros_fn.h  |  3 +++
 include/tst_safe_macros.h |  3 +++
 lib/safe_macros.c         | 20 ++++++++++++++++++++
 4 files changed, 29 insertions(+)

diff --git a/include/old/safe_macros.h b/include/old/safe_macros.h
index fb1d7a1..1d5de49 100644
--- a/include/old/safe_macros.h
+++ b/include/old/safe_macros.h
@@ -20,6 +20,9 @@
 #include "old_safe_stdio.h"
 #include "old_safe_net.h"
 
+#define SAFE_ACCESS(cleanup_fn, pathname, mode)	\
+	safe_access(__FILE__, __LINE__, cleanup_fn, (pathname), (mode))
+
 #define SAFE_BASENAME(cleanup_fn, path)	\
 	safe_basename(__FILE__, __LINE__, (cleanup_fn), (path))
 
diff --git a/include/safe_macros_fn.h b/include/safe_macros_fn.h
index 3df9528..2c8eb50 100644
--- a/include/safe_macros_fn.h
+++ b/include/safe_macros_fn.h
@@ -24,6 +24,9 @@
 #include <unistd.h>
 #include <dirent.h>
 
+int safe_access(const char *file, const int lineno,
+		void (*cleanup_fn)(void), const char *pathname, int mode);
+
 char* safe_basename(const char *file, const int lineno,
                     void (*cleanup_fn)(void), char *path);
 
diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 9a543e4..d8e56f5 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -24,6 +24,9 @@
 #include "safe_macros_fn.h"
 #include "tst_cmd.h"
 
+#define SAFE_ACCESS(pathname, mode) \
+	safe_access(__FILE__, __LINE__, NULL, (pathname), (mode))
+
 #define SAFE_BASENAME(path) \
 	safe_basename(__FILE__, __LINE__, NULL, (path))
 
diff --git a/lib/safe_macros.c b/lib/safe_macros.c
index a5b6bc5..006e583 100644
--- a/lib/safe_macros.c
+++ b/lib/safe_macros.c
@@ -24,6 +24,26 @@
 #include "test.h"
 #include "safe_macros.h"
 
+int
+safe_access(const char *file, const int lineno, void (*cleanup_fn) (void),
+	   const char *pathname, int mode)
+{
+	int rval;
+
+	rval = access(pathname, mode);
+
+	if (rval == -1) {
+		tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
+			"access(%s,%d) failed", pathname, mode);
+	} else if (rval) {
+		tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
+			"Invalid access(%s,%d) return value %d", pathname,
+			mode, rval);
+	}
+
+	return rval;
+}
+
 char *safe_basename(const char *file, const int lineno,
 		    void (*cleanup_fn) (void), char *path)
 {
-- 
1.8.3.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2022-03-25  8:47 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-14 17:28 [LTP] [PATCH 1/2] Add SAFE_ACCESS macro Dai Shili
2022-03-14 17:28 ` [LTP] [PATCH 2/2] Make use of SAFE_ACCESS Dai Shili
2022-03-14  6:43   ` xuyang2018.jy
2022-03-17 21:00     ` [LTP] [PATCH v2 1/3] Add SAFE_ACCESS macro Dai Shili
2022-03-17 21:00       ` [LTP] [PATCH v2 2/3] Make use of SAFE_ACCESS Dai Shili
2022-03-18  4:02         ` xuyang2018.jy
2022-03-17 21:00       ` [LTP] [PATCH v2 3/3] syscalls/umount2: Convert to new API and use SAFE_ACCESS Dai Shili
2022-03-18  4:03         ` xuyang2018.jy
2022-03-18  5:11           ` xuyang2018.jy
2022-03-18 18:55             ` [LTP] [PATCH v3 1/3] Add SAFE_ACCESS macro Dai Shili
2022-03-18 18:55               ` [LTP] [PATCH v3 2/3] Make use of SAFE_ACCESS Dai Shili
2022-03-23 19:30                 ` Petr Vorel
2022-03-23 19:33                 ` Petr Vorel
2022-03-18 18:55               ` [LTP] [PATCH v3 3/3] syscalls/umount2: Convert to new API and use SAFE_ACCESS Dai Shili
2022-03-23 19:36                 ` Petr Vorel
2022-03-24  2:23                   ` daisl.fnst
2022-03-24 15:35                   ` [LTP] [PATCH v4] " Dai Shili
2022-03-24  9:11                     ` Petr Vorel
2022-03-25  3:00                       ` daisl.fnst
2022-03-25 17:29                       ` [LTP] [PATCH v5] " Dai Shili
2022-03-25  8:46                         ` Petr Vorel
2022-03-24  1:37                 ` [LTP] [PATCH v3 3/3] " xuyang2018.jy
2022-03-23 19:24               ` [LTP] [PATCH v3 1/3] Add SAFE_ACCESS macro Petr Vorel
2022-03-24  2:22                 ` daisl.fnst
2022-03-23 19:27               ` Petr Vorel
2022-03-23 19:33               ` Petr Vorel
2022-03-18  3:56       ` [LTP] [PATCH v2 " xuyang2018.jy

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.