[CRIU] [PATCH] criu check: don't run as non-root
Kir Kolyshkin
kir at openvz.org
Thu Dec 12 12:02:30 PST 2013
In case criu check is run as non-root, a lot of information is printed
to a user, with the only missing bit is it should run it as root.
Fix it.
I still don't like the fact that some other stuff is printed here,
like the timestamp and the __FILE__:__LINE__, but this should be
fixed separately.
Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
cr-check.c | 3 +++
include/util.h | 1 +
util.c | 10 ++++++++++
3 files changed, 14 insertions(+)
diff --git a/cr-check.c b/cr-check.c
index 6fd3273..064d286 100644
--- a/cr-check.c
+++ b/cr-check.c
@@ -533,6 +533,9 @@ int cr_check(void)
log_set_loglevel(LOG_WARN);
+ if (!is_root_user())
+ return -1;
+
if (mntns_collect_root(getpid())) {
pr_err("Can't collect root mount point\n");
return -1;
diff --git a/include/util.h b/include/util.h
index bad91b2..c081921 100644
--- a/include/util.h
+++ b/include/util.h
@@ -272,6 +272,7 @@ extern void shfree_last(void *ptr);
extern int run_scripts(char *action);
extern int cr_system(int in, int out, int err, char *cmd, char *const argv[]);
+extern int is_root_user(void);
static inline bool dir_dots(struct dirent *de)
{
diff --git a/util.c b/util.c
index 0b10f0d..c591331 100644
--- a/util.c
+++ b/util.c
@@ -571,3 +571,13 @@ out:
return ret;
}
+
+int is_root_user()
+{
+ if (geteuid() != 0) {
+ pr_err("You need to be root to run this command\n");
+ return 0;
+ }
+
+ return 1;
+}
--
1.8.1.4
More information about the CRIU
mailing list