@@ -50,6 +50,11 @@ int safe_dup(const char *file, const int lineno, int oldfd);
#define SAFE_DUP(oldfd) \
safe_dup(__FILE__, __LINE__, (oldfd))
+int safe_dup2(const char *file, const int lineno, int oldfd, int newfd);
+
+#define SAFE_DUP2(oldfd, newfd) \
+ safe_dup2(__FILE__, __LINE__, (oldfd), (newfd))
+
#define SAFE_GETCWD(buf, size) \
safe_getcwd(__FILE__, __LINE__, NULL, (buf), (size))
@@ -415,6 +415,24 @@ int safe_dup(const char *file, const int lineno, int oldfd)
return rval;
}
+int safe_dup2(const char *file, const int lineno, int oldfd, int newfd)
+{
+ int rval;
+
+ rval = dup2(oldfd, newfd);
+
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "dup2(%i, %i) failed", oldfd, newfd);
+ } else if (rval != newfd) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "Invalid dup2(%i, %i) return value %d",
+ oldfd, newfd, rval);
+ }
+
+ return rval;
+}
+
sighandler_t safe_signal(const char *file, const int lineno,
int signum, sighandler_t handler)
{
Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com> --- include/tst_safe_macros.h | 5 +++++ lib/tst_safe_macros.c | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+)