public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] tst_safe_macros: Move implementations into C file, rename
@ 2024-03-18 16:25 Petr Vorel
  2024-03-18 16:25 ` [LTP] [PATCH 2/2] include: Move inline functions to special header Petr Vorel
  2024-03-26 13:24 ` [LTP] [PATCH 1/2] tst_safe_macros: Move implementations into C file, rename Cyril Hrubis
  0 siblings, 2 replies; 6+ messages in thread
From: Petr Vorel @ 2024-03-18 16:25 UTC (permalink / raw)
  To: ltp

9120d8a22 ("safe_macros: turn functions with off_t parameter into static inline")
noted:

    Some functions used to implement safe macros have parameters
    of type off_t or structures containing off_t fields.

But that's not the case of safe_mprotect() and helper safe_prot_to_str().
Therefore move their implementations into C file (following the approach
we don't want static inline implementations in the API headers).

Also rename safe_prot_to_str() to tst_prot_to_str() (safe_ functions
take const char *file, const int lineno and call tst_brk_() on error).

Fixes: b366afb64 ("Add SAFE_MPROTECT() macro")
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 include/tst_safe_macros.h | 74 +++++++--------------------------------
 lib/tst_safe_macros.c     | 55 +++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 61 deletions(-)

diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 7178a842d..1c2decadd 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -1,5 +1,5 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later
- * Copyright (c) 2010-2018 Linux Test Project
+ * Copyright (c) 2010-2024 Linux Test Project
  * Copyright (c) 2011-2015 Cyril Hrubis <chrubis@suse.cz>
  */
 
@@ -264,49 +264,15 @@ int safe_getgroups(const char *file, const int lineno, int size, gid_t list[]);
 	            "fcntl(%i,%s,...) failed", fd, #cmd), 0 \
 	 : tst_ret_;})
 
-/*
- * following functions are inline because the behaviour may depend on
- * -D_FILE_OFFSET_BITS=64 compile flag
- */
-
-#define PROT_FLAG_STR(f) #f " | "
-
-static void safe_prot_to_str(const int prot, char *buf)
-{
-	char *ptr = buf;
-
-	if (prot == PROT_NONE) {
-		strcpy(buf, "PROT_NONE");
-		return;
-	}
-
-	if (prot & PROT_READ) {
-		strcpy(ptr, PROT_FLAG_STR(PROT_READ));
-		ptr += sizeof(PROT_FLAG_STR(PROT_READ)) - 1;
-	}
-
-	if (prot & PROT_WRITE) {
-		strcpy(ptr, PROT_FLAG_STR(PROT_WRITE));
-		ptr += sizeof(PROT_FLAG_STR(PROT_WRITE)) - 1;
-	}
-
-	if (prot & PROT_EXEC) {
-		strcpy(ptr, PROT_FLAG_STR(PROT_EXEC));
-		ptr += sizeof(PROT_FLAG_STR(PROT_EXEC)) - 1;
-	}
-
-	if (buf != ptr)
-		ptr[-3] = 0;
-}
+void tst_prot_to_str(const int prot, char *buf);
 
 static inline void *safe_mmap(const char *file, const int lineno,
-                              void *addr, size_t length,
-                              int prot, int flags, int fd, off_t offset)
+	void *addr, size_t length, int prot, int flags, int fd, off_t offset)
 {
 	void *rval;
 	char prot_buf[512];
 
-	safe_prot_to_str(prot, prot_buf);
+	tst_prot_to_str(prot, prot_buf);
 
 	tst_res_(file, lineno, TDEBUG,
 		"mmap(%p, %ld, %s(%x), %d, %d, %ld)",
@@ -321,37 +287,23 @@ static inline void *safe_mmap(const char *file, const int lineno,
 
 	return rval;
 }
+
+
 #define SAFE_MMAP(addr, length, prot, flags, fd, offset) \
 	safe_mmap(__FILE__, __LINE__, (addr), (length), (prot), \
 	(flags), (fd), (offset))
 
-static inline int safe_mprotect(const char *file, const int lineno,
-	char *addr, size_t len, int prot)
-{
-	int rval;
-	char prot_buf[512];
-
-	safe_prot_to_str(prot, prot_buf);
-
-	tst_res_(file, lineno, TDEBUG,
-		"mprotect(%p, %ld, %s(%x))", addr, len, prot_buf, prot);
+int safe_mprotect(const char *file, const int lineno,
+	char *addr, size_t len, int prot);
 
-	rval = mprotect(addr, len, prot);
-
-	if (rval == -1) {
-		tst_brk_(file, lineno, TBROK | TERRNO,
-			"mprotect(%p, %ld, %s(%x))", addr, len, prot_buf, prot);
-	} else if (rval) {
-		tst_brk_(file, lineno, TBROK | TERRNO,
-			"mprotect(%p, %ld, %s(%x)) return value %d",
-			addr, len, prot_buf, prot, rval);
-	}
-
-	return rval;
-}
 #define SAFE_MPROTECT(addr, len, prot) \
 	safe_mprotect(__FILE__, __LINE__, (addr), (len), (prot))
 
+/*
+ * Following functions are inline because the behaviour may depend on
+ * -D_FILE_OFFSET_BITS=64 compile flag.
+ */
+
 static inline int safe_ftruncate(const char *file, const int lineno,
                                  int fd, off_t length)
 {
diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
index 498e45a74..907675afe 100644
--- a/lib/tst_safe_macros.c
+++ b/lib/tst_safe_macros.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) 2017-2024 Linux Test Project
  */
 
 #define _GNU_SOURCE
@@ -622,3 +623,57 @@ void safe_print_file(const char *file, const int lineno, char *path)
 
 	safe_fclose(file, lineno, NULL, pfile);
 }
+
+#define PROT_FLAG_STR(f) #f " | "
+void tst_prot_to_str(const int prot, char *buf)
+{
+	char *ptr = buf;
+
+	if (prot == PROT_NONE) {
+		strcpy(buf, "PROT_NONE");
+		return;
+	}
+
+	if (prot & PROT_READ) {
+		strcpy(ptr, PROT_FLAG_STR(PROT_READ));
+		ptr += sizeof(PROT_FLAG_STR(PROT_READ)) - 1;
+	}
+
+	if (prot & PROT_WRITE) {
+		strcpy(ptr, PROT_FLAG_STR(PROT_WRITE));
+		ptr += sizeof(PROT_FLAG_STR(PROT_WRITE)) - 1;
+	}
+
+	if (prot & PROT_EXEC) {
+		strcpy(ptr, PROT_FLAG_STR(PROT_EXEC));
+		ptr += sizeof(PROT_FLAG_STR(PROT_EXEC)) - 1;
+	}
+
+	if (buf != ptr)
+		ptr[-3] = 0;
+}
+
+int safe_mprotect(const char *file, const int lineno,
+	char *addr, size_t len, int prot)
+{
+	int rval;
+	char prot_buf[512];
+
+	tst_prot_to_str(prot, prot_buf);
+
+	tst_res_(file, lineno, TDEBUG,
+		"mprotect(%p, %ld, %s(%x))", addr, len, prot_buf, prot);
+
+	rval = mprotect(addr, len, prot);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"mprotect(%p, %ld, %s(%x))", addr, len, prot_buf, prot);
+	} else if (rval) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"mprotect(%p, %ld, %s(%x)) return value %d",
+			addr, len, prot_buf, prot, rval);
+	}
+
+	return rval;
+}
-- 
2.43.0


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

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

* [LTP] [PATCH 2/2] include: Move inline functions to special header
  2024-03-18 16:25 [LTP] [PATCH 1/2] tst_safe_macros: Move implementations into C file, rename Petr Vorel
@ 2024-03-18 16:25 ` Petr Vorel
  2024-03-19  6:32   ` Jan Stancek
  2024-03-26 13:33   ` Cyril Hrubis
  2024-03-26 13:24 ` [LTP] [PATCH 1/2] tst_safe_macros: Move implementations into C file, rename Cyril Hrubis
  1 sibling, 2 replies; 6+ messages in thread
From: Petr Vorel @ 2024-03-18 16:25 UTC (permalink / raw)
  To: ltp

9120d8a22 ("safe_macros: turn functions with off_t parameter into static
inline") changed some functions to inline because they depend on
-D_FILE_OFFSET_BITS=64. Separate them into it's own header, because
normal functions should be in C files.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 include/tst_safe_macros.h        | 213 +---------------------------
 include/tst_safe_macros_inline.h | 229 +++++++++++++++++++++++++++++++
 2 files changed, 231 insertions(+), 211 deletions(-)
 create mode 100644 include/tst_safe_macros_inline.h

diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 1c2decadd..cfd1d89ad 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -25,6 +25,7 @@
 #include "safe_stdio_fn.h"
 #include "safe_macros_fn.h"
 #include "tst_cmd.h"
+#include "tst_safe_macros_inline.h"
 
 int safe_access(const char *filename, const int lineno, const char *pathname,
 		   int mode);
@@ -299,216 +300,6 @@ int safe_mprotect(const char *file, const int lineno,
 #define SAFE_MPROTECT(addr, len, prot) \
 	safe_mprotect(__FILE__, __LINE__, (addr), (len), (prot))
 
-/*
- * Following functions are inline because the behaviour may depend on
- * -D_FILE_OFFSET_BITS=64 compile flag.
- */
-
-static inline int safe_ftruncate(const char *file, const int lineno,
-                                 int fd, off_t length)
-{
-	int rval;
-
-	rval = ftruncate(fd, length);
-
-	if (rval == -1) {
-		tst_brk_(file, lineno, TBROK | TERRNO,
-			"ftruncate(%d,%ld) failed", fd, (long)length);
-	} else if (rval) {
-		tst_brk_(file, lineno, TBROK | TERRNO,
-			"Invalid ftruncate(%d,%ld) return value %d", fd,
-			(long)length, rval);
-	}
-
-	return rval;
-}
-#define SAFE_FTRUNCATE(fd, length) \
-	safe_ftruncate(__FILE__, __LINE__, (fd), (length))
-
-static inline int safe_posix_fadvise(const char *file, const int lineno,
-                                int fd, off_t offset, off_t len, int advice)
-{
-	int rval;
-
-	rval = posix_fadvise(fd, offset, len, advice);
-
-	if (rval)
-		tst_brk_(file, lineno, TBROK,
-			"posix_fadvise(%d,%ld,%ld,%d) failed: %s",
-			fd, (long)offset, (long)len, advice, tst_strerrno(rval));
-
-	return rval;
-}
-#define SAFE_POSIX_FADVISE(fd, offset, len, advice) \
-	safe_posix_fadvise(__FILE__, __LINE__, (fd), (offset), (len), (advice))
-
-static inline int safe_truncate(const char *file, const int lineno,
-                                const char *path, off_t length)
-{
-	int rval;
-
-	rval = truncate(path, length);
-
-	if (rval == -1) {
-		tst_brk_(file, lineno, TBROK | TERRNO,
-			"truncate(%s,%ld) failed", path, (long)length);
-	} else if (rval) {
-		tst_brk_(file, lineno, TBROK | TERRNO,
-			"Invalid truncate(%s,%ld) return value %d", path,
-			(long)length, rval);
-	}
-
-	return rval;
-}
-#define SAFE_TRUNCATE(path, length) \
-	safe_truncate(__FILE__, __LINE__, (path), (length))
-
-static inline int safe_stat(const char *file, const int lineno,
-                            const char *path, struct stat *buf)
-{
-	int rval;
-
-	rval = stat(path, buf);
-
-	if (rval == -1) {
-		tst_brk_(file, lineno, TBROK | TERRNO,
-			"stat(%s,%p) failed", path, buf);
-	} else if (rval) {
-		tst_brk_(file, lineno, TBROK | TERRNO,
-			"Invalid stat(%s,%p) return value %d", path, buf,
-			rval);
-	}
-
-	return rval;
-}
-#define SAFE_STAT(path, buf) \
-	safe_stat(__FILE__, __LINE__, (path), (buf))
-
-static inline int safe_fstat(const char *file, const int lineno,
-                             int fd, struct stat *buf)
-{
-	int rval;
-
-	rval = fstat(fd, buf);
-
-	if (rval == -1) {
-		tst_brk_(file, lineno, TBROK | TERRNO,
-			"fstat(%d,%p) failed", fd, buf);
-	} else if (rval) {
-		tst_brk_(file, lineno, TBROK | TERRNO,
-			"Invalid fstat(%d,%p) return value %d", fd, buf, rval);
-	}
-
-	return rval;
-}
-#define SAFE_FSTAT(fd, buf) \
-	safe_fstat(__FILE__, __LINE__, (fd), (buf))
-
-static inline int safe_lstat(const char *file, const int lineno,
-	const char *path, struct stat *buf)
-{
-	int rval;
-
-	rval = lstat(path, buf);
-
-	if (rval == -1) {
-		tst_brk_(file, lineno, TBROK | TERRNO,
-			"lstat(%s,%p) failed", path, buf);
-	} else if (rval) {
-		tst_brk_(file, lineno, TBROK | TERRNO,
-			"Invalid lstat(%s,%p) return value %d", path, buf,
-			rval);
-	}
-
-	return rval;
-}
-#define SAFE_LSTAT(path, buf) \
-	safe_lstat(__FILE__, __LINE__, (path), (buf))
-
-static inline int safe_statfs(const char *file, const int lineno,
-                              const char *path, struct statfs *buf)
-{
-	int rval;
-
-	rval = statfs(path, buf);
-
-	if (rval == -1) {
-		tst_brk_(file, lineno, TBROK | TERRNO,
-			"statfs(%s,%p) failed", path, buf);
-	} else if (rval) {
-		tst_brk_(file, lineno, TBROK | TERRNO,
-			"Invalid statfs(%s,%p) return value %d", path, buf,
-			rval);
-	}
-
-	return rval;
-}
-#define SAFE_STATFS(path, buf) \
-	safe_statfs(__FILE__, __LINE__, (path), (buf))
-
-static inline off_t safe_lseek(const char *file, const int lineno,
-                               int fd, off_t offset, int whence)
-{
-	off_t rval;
-
-	rval = lseek(fd, offset, whence);
-
-	if (rval == (off_t) -1) {
-		tst_brk_(file, lineno, TBROK | TERRNO,
-			"lseek(%d,%ld,%d) failed", fd, (long)offset, whence);
-	} else if (rval < 0) {
-		tst_brk_(file, lineno, TBROK | TERRNO,
-			"Invalid lseek(%d,%ld,%d) return value %ld", fd,
-			(long)offset, whence, (long)rval);
-	}
-
-	return rval;
-}
-#define SAFE_LSEEK(fd, offset, whence) \
-	safe_lseek(__FILE__, __LINE__, (fd), (offset), (whence))
-
-static inline int safe_getrlimit(const char *file, const int lineno,
-                                 int resource, struct rlimit *rlim)
-{
-	int rval;
-
-	rval = getrlimit(resource, rlim);
-
-	if (rval == -1) {
-		tst_brk_(file, lineno, TBROK | TERRNO,
-			"getrlimit(%d,%p) failed", resource, rlim);
-	} else if (rval) {
-		tst_brk_(file, lineno, TBROK | TERRNO,
-			"Invalid getrlimit(%d,%p) return value %d", resource,
-			rlim, rval);
-	}
-
-	return rval;
-}
-#define SAFE_GETRLIMIT(resource, rlim) \
-	safe_getrlimit(__FILE__, __LINE__, (resource), (rlim))
-
-static inline int safe_setrlimit(const char *file, const int lineno,
-                                 int resource, const struct rlimit *rlim)
-{
-	int rval;
-
-	rval = setrlimit(resource, rlim);
-
-	if (rval == -1) {
-		tst_brk_(file, lineno, TBROK | TERRNO,
-			"setrlimit(%d,%p) failed", resource, rlim);
-	} else if (rval) {
-		tst_brk_(file, lineno, TBROK | TERRNO,
-			"Invalid setrlimit(%d,%p) return value %d", resource,
-			rlim, rval);
-	}
-
-	return rval;
-}
-#define SAFE_SETRLIMIT(resource, rlim) \
-	safe_setrlimit(__FILE__, __LINE__, (resource), (rlim))
-
 typedef void (*sighandler_t)(int);
 sighandler_t safe_signal(const char *file, const int lineno,
 	int signum, sighandler_t handler);
@@ -702,4 +493,4 @@ int safe_sysinfo(const char *file, const int lineno, struct sysinfo *info);
 
 void safe_print_file(const char *file, const int lineno, char *path);
 
-#endif /* SAFE_MACROS_H__ */
+#endif /* TST_SAFE_MACROS_H__ */
diff --git a/include/tst_safe_macros_inline.h b/include/tst_safe_macros_inline.h
new file mode 100644
index 000000000..c497f6059
--- /dev/null
+++ b/include/tst_safe_macros_inline.h
@@ -0,0 +1,229 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2010-2024 Linux Test Project
+ * Copyright (c) 2011-2015 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef TST_SAFE_MACROS_INLINE_H__
+#define TST_SAFE_MACROS_INLINE_H__
+
+/*
+ * Following functions are inline because the behaviour may depend on
+ * -D_FILE_OFFSET_BITS=64 compile flag.
+ *
+ * Do not add other functions here.
+ */
+
+static inline int safe_ftruncate(const char *file, const int lineno,
+	int fd, off_t length)
+{
+	int rval;
+
+	rval = ftruncate(fd, length);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"ftruncate(%d,%ld) failed", fd, (long)length);
+	} else if (rval) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid ftruncate(%d,%ld) return value %d", fd,
+			(long)length, rval);
+	}
+
+	return rval;
+}
+
+#define SAFE_FTRUNCATE(fd, length) \
+	safe_ftruncate(__FILE__, __LINE__, (fd), (length))
+
+static inline int safe_posix_fadvise(const char *file, const int lineno,
+	int fd, off_t offset, off_t len, int advice)
+{
+	int rval;
+
+	rval = posix_fadvise(fd, offset, len, advice);
+
+	if (rval)
+		tst_brk_(file, lineno, TBROK,
+			"posix_fadvise(%d,%ld,%ld,%d) failed: %s",
+			fd, (long)offset, (long)len, advice, tst_strerrno(rval));
+
+	return rval;
+}
+
+#define SAFE_POSIX_FADVISE(fd, offset, len, advice) \
+	safe_posix_fadvise(__FILE__, __LINE__, (fd), (offset), (len), (advice))
+
+static inline int safe_truncate(const char *file, const int lineno,
+	const char *path, off_t length)
+{
+	int rval;
+
+	rval = truncate(path, length);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"truncate(%s,%ld) failed", path, (long)length);
+	} else if (rval) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid truncate(%s,%ld) return value %d", path,
+			(long)length, rval);
+	}
+
+	return rval;
+}
+
+#define SAFE_TRUNCATE(path, length) \
+	safe_truncate(__FILE__, __LINE__, (path), (length))
+
+static inline int safe_stat(const char *file, const int lineno,
+	const char *path, struct stat *buf)
+{
+	int rval;
+
+	rval = stat(path, buf);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"stat(%s,%p) failed", path, buf);
+	} else if (rval) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid stat(%s,%p) return value %d", path, buf,
+			rval);
+	}
+
+	return rval;
+}
+
+#define SAFE_STAT(path, buf) \
+	safe_stat(__FILE__, __LINE__, (path), (buf))
+
+static inline int safe_fstat(const char *file, const int lineno,
+	int fd, struct stat *buf)
+{
+	int rval;
+
+	rval = fstat(fd, buf);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"fstat(%d,%p) failed", fd, buf);
+	} else if (rval) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid fstat(%d,%p) return value %d", fd, buf, rval);
+	}
+
+	return rval;
+}
+#define SAFE_FSTAT(fd, buf) \
+	safe_fstat(__FILE__, __LINE__, (fd), (buf))
+
+static inline int safe_lstat(const char *file, const int lineno,
+	const char *path, struct stat *buf)
+{
+	int rval;
+
+	rval = lstat(path, buf);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"lstat(%s,%p) failed", path, buf);
+	} else if (rval) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid lstat(%s,%p) return value %d", path, buf,
+			rval);
+	}
+
+	return rval;
+}
+#define SAFE_LSTAT(path, buf) \
+	safe_lstat(__FILE__, __LINE__, (path), (buf))
+
+static inline int safe_statfs(const char *file, const int lineno,
+	const char *path, struct statfs *buf)
+{
+	int rval;
+
+	rval = statfs(path, buf);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"statfs(%s,%p) failed", path, buf);
+	} else if (rval) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid statfs(%s,%p) return value %d", path, buf,
+			rval);
+	}
+
+	return rval;
+}
+
+#define SAFE_STATFS(path, buf) \
+	safe_statfs(__FILE__, __LINE__, (path), (buf))
+
+static inline off_t safe_lseek(const char *file, const int lineno,
+	int fd, off_t offset, int whence)
+{
+	off_t rval;
+
+	rval = lseek(fd, offset, whence);
+
+	if (rval == (off_t) -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"lseek(%d,%ld,%d) failed", fd, (long)offset, whence);
+	} else if (rval < 0) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid lseek(%d,%ld,%d) return value %ld", fd,
+			(long)offset, whence, (long)rval);
+	}
+
+	return rval;
+}
+
+#define SAFE_LSEEK(fd, offset, whence) \
+	safe_lseek(__FILE__, __LINE__, (fd), (offset), (whence))
+
+static inline int safe_getrlimit(const char *file, const int lineno,
+	int resource, struct rlimit *rlim)
+{
+	int rval;
+
+	rval = getrlimit(resource, rlim);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"getrlimit(%d,%p) failed", resource, rlim);
+	} else if (rval) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid getrlimit(%d,%p) return value %d", resource,
+			rlim, rval);
+	}
+
+	return rval;
+}
+
+#define SAFE_GETRLIMIT(resource, rlim) \
+	safe_getrlimit(__FILE__, __LINE__, (resource), (rlim))
+
+static inline int safe_setrlimit(const char *file, const int lineno,
+	int resource, const struct rlimit *rlim)
+{
+	int rval;
+
+	rval = setrlimit(resource, rlim);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"setrlimit(%d,%p) failed", resource, rlim);
+	} else if (rval) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid setrlimit(%d,%p) return value %d", resource,
+			rlim, rval);
+	}
+
+	return rval;
+}
+
+#define SAFE_SETRLIMIT(resource, rlim) \
+	safe_setrlimit(__FILE__, __LINE__, (resource), (rlim))
+
+#endif /* TST_SAFE_MACROS_INLINE_H__ */
-- 
2.43.0


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

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

* Re: [LTP] [PATCH 2/2] include: Move inline functions to special header
  2024-03-18 16:25 ` [LTP] [PATCH 2/2] include: Move inline functions to special header Petr Vorel
@ 2024-03-19  6:32   ` Jan Stancek
  2024-03-26 13:33   ` Cyril Hrubis
  1 sibling, 0 replies; 6+ messages in thread
From: Jan Stancek @ 2024-03-19  6:32 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

On Mon, Mar 18, 2024 at 5:26 PM Petr Vorel <pvorel@suse.cz> wrote:
>
> 9120d8a22 ("safe_macros: turn functions with off_t parameter into static
> inline") changed some functions to inline because they depend on
> -D_FILE_OFFSET_BITS=64. Separate them into it's own header, because
> normal functions should be in C files.
>
> Signed-off-by: Petr Vorel <pvorel@suse.cz>

I'm for separating these too.

Acked-by: Jan Stancek <jstancek@redhat.com>


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

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

* Re: [LTP] [PATCH 1/2] tst_safe_macros: Move implementations into C file, rename
  2024-03-18 16:25 [LTP] [PATCH 1/2] tst_safe_macros: Move implementations into C file, rename Petr Vorel
  2024-03-18 16:25 ` [LTP] [PATCH 2/2] include: Move inline functions to special header Petr Vorel
@ 2024-03-26 13:24 ` Cyril Hrubis
  1 sibling, 0 replies; 6+ messages in thread
From: Cyril Hrubis @ 2024-03-26 13:24 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH 2/2] include: Move inline functions to special header
  2024-03-18 16:25 ` [LTP] [PATCH 2/2] include: Move inline functions to special header Petr Vorel
  2024-03-19  6:32   ` Jan Stancek
@ 2024-03-26 13:33   ` Cyril Hrubis
  2024-03-26 14:28     ` Petr Vorel
  1 sibling, 1 reply; 6+ messages in thread
From: Cyril Hrubis @ 2024-03-26 13:33 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hi!
Good idea:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH 2/2] include: Move inline functions to special header
  2024-03-26 13:33   ` Cyril Hrubis
@ 2024-03-26 14:28     ` Petr Vorel
  0 siblings, 0 replies; 6+ messages in thread
From: Petr Vorel @ 2024-03-26 14:28 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Jan, Cyril,

thanks a lot, merged!

Kind regards,
Petr

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

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

end of thread, other threads:[~2024-03-26 14:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-18 16:25 [LTP] [PATCH 1/2] tst_safe_macros: Move implementations into C file, rename Petr Vorel
2024-03-18 16:25 ` [LTP] [PATCH 2/2] include: Move inline functions to special header Petr Vorel
2024-03-19  6:32   ` Jan Stancek
2024-03-26 13:33   ` Cyril Hrubis
2024-03-26 14:28     ` Petr Vorel
2024-03-26 13:24 ` [LTP] [PATCH 1/2] tst_safe_macros: Move implementations into C file, rename Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox