From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 3/9] safe_macros: Add SAFE_SETNS()
Date: Wed, 18 Mar 2020 16:37:55 +0100 [thread overview]
Message-ID: <20200318153801.3529-4-chrubis@suse.cz> (raw)
In-Reply-To: <20200318153801.3529-1-chrubis@suse.cz>
From: Cyril Hrubis <metan@ucw.cz>
Signed-off-by: Cyril Hrubis <metan@ucw.cz>
---
include/tst_safe_macros.h | 4 ++++
lib/tst_safe_macros.c | 12 ++++++++++++
2 files changed, 16 insertions(+)
diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index 80c4d9cb9..291f2a722 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -547,4 +547,8 @@ int safe_personality(const char *filename, unsigned int lineno,
void safe_unshare(const char *file, const int lineno, int flags);
#define SAFE_UNSHARE(flags) safe_unshare(__FILE__, __LINE__, (flags))
+
+void safe_setns(const char *file, const int lineno, int fd, int nstype);
+#define SAFE_SETNS(fd, nstype) safe_setns(__FILE__, __LINE__, (fd), (nstype));
+
#endif /* SAFE_MACROS_H__ */
diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
index f5413a18e..353ef5b1d 100644
--- a/lib/tst_safe_macros.c
+++ b/lib/tst_safe_macros.c
@@ -6,6 +6,7 @@
#define _GNU_SOURCE
#include <unistd.h>
#include <errno.h>
+#include "lapi/setns.h"
#include <sched.h>
#include "config.h"
#ifdef HAVE_SYS_FANOTIFY_H
@@ -202,3 +203,14 @@ void safe_unshare(const char *file, const int lineno, int flags)
}
}
}
+
+void safe_setns(const char *file, const int lineno, int fd, int nstype)
+{
+ int ret;
+
+ ret = setns(fd, nstype);
+ if (ret == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO, "setns(%i, %i) failed",
+ fd, nstype);
+ }
+}
--
2.24.1
next prev parent reply other threads:[~2020-03-18 15:37 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-18 15:37 [LTP] [PATCH v2 0/9] Add basic time namespace testcases Cyril Hrubis
2020-03-18 15:37 ` [LTP] [PATCH v2 1/9] lapi/namespace_constants.h: Add CLONE_NEWTIME Cyril Hrubis
2020-03-18 15:37 ` [LTP] [PATCH v2 2/9] lapi: Add a configure check and fallback for setns Cyril Hrubis
2020-03-18 15:37 ` Cyril Hrubis [this message]
2020-03-23 16:11 ` [LTP] [PATCH v2 3/9] safe_macros: Add SAFE_SETNS() Petr Vorel
2020-03-30 14:09 ` Cyril Hrubis
2020-03-18 15:37 ` [LTP] [PATCH v2 4/9] include/tst_timer: Fix normalization Cyril Hrubis
2020-03-18 15:37 ` [LTP] [PATCH v2 5/9] syscalls/sysinfo03: Add time namespace test Cyril Hrubis
2020-03-19 7:55 ` Li Wang
2020-03-19 22:00 ` Cyril Hrubis
2020-03-20 7:32 ` Li Wang
2020-03-23 18:47 ` Petr Vorel
2020-03-18 15:37 ` [LTP] [PATCH v2 6/9] syscalls/clock_nanosleep03: Add test for time namespace Cyril Hrubis
2020-03-18 15:37 ` [LTP] [PATCH v2 7/9] syscalls/clock_gettime03: Add basic time namespace test Cyril Hrubis
2020-03-18 15:38 ` [LTP] [PATCH v2 8/9] containers/timens: Add basic error test Cyril Hrubis
2020-03-18 15:38 ` [LTP] [PATCH v2 9/9] syscalls/timerfd04: Add time namespace test Cyril Hrubis
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=20200318153801.3529-4-chrubis@suse.cz \
--to=chrubis@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox