@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2015 Linux Test Project
+ * Copyright (c) 2010-2018 Linux Test Project
* Copyright (c) 2011-2015 Cyril Hrubis <chrubis@suse.cz>
*
* This program is free software: you can redistribute it and/or modify
@@ -48,6 +48,10 @@
#define SAFE_CREAT(pathname, mode) \
safe_creat(__FILE__, __LINE__, NULL, (pathname), (mode))
+#define SAFE_CHROOT(path) \
+ safe_chroot(__FILE__, __LINE__, (path))
+int safe_chroot(const char *file, const int lineno, const char *path);
+
#define SAFE_DIRNAME(path) \
safe_dirname(__FILE__, __LINE__, NULL, (path))
@@ -152,3 +152,16 @@ struct group *safe_getgrnam(const char *file, const int lineno,
return rval;
}
+
+int safe_chroot(const char *file, const int lineno, const char *path)
+{
+ int rval;
+
+ rval = chroot(path);
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "chroot(%s) failed", path);
+ }
+
+ return rval;
+}
Signed-off-by: Petr Vorel <pvorel@suse.cz> --- include/tst_safe_macros.h | 6 +++++- lib/tst_safe_macros.c | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-)