[CRIU] [PATCH cr 5/9] util: add a function for running scripts

Andrey Vagin avagin at openvz.org
Mon Sep 17 03:50:10 EDT 2012


Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 include/util.h |    1 +
 util.c         |   17 +++++++++++++++++
 2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/include/util.h b/include/util.h
index cda081c..93749b3 100644
--- a/include/util.h
+++ b/include/util.h
@@ -323,5 +323,6 @@ static inline int read_img_str(int fd, char **pstr, int size)
 
 extern void *shmalloc(size_t bytes);
 extern void shfree_last(void *ptr);
+extern int run_scripts(char *action);
 
 #endif /* UTIL_H_ */
diff --git a/util.c b/util.c
index 0e047a1..e459527 100644
--- a/util.c
+++ b/util.c
@@ -387,3 +387,20 @@ void shfree_last(void *ptr)
 	sh_bytes_left += sh_last_size;
 	sh_last_size = 0;
 }
+
+int run_scripts(char *action)
+{
+	struct script *script;
+	int ret = 0;
+
+	if (setenv("CRTOOLS_SCRIPT_ACTION", action, 1)) {
+		pr_perror("Can't set CRTOOL_SCRIPT_ACTION=%s\n", action);
+		return -1;
+	}
+
+	list_for_each_entry(script, &opts.scripts, node)
+		ret |= system(script->path);
+
+	unsetenv("CRTOOLS_SCRIPT_ACTION");
+	return ret;
+}
-- 
1.7.1



More information about the CRIU mailing list