[CRIU] [PATCH 2/3] scripts: Use numeric script names

Pavel Emelyanov xemul at parallels.com
Wed Sep 3 12:43:46 PDT 2014


Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 action-scripts.c         | 11 ++++++++++-
 cr-dump.c                |  2 +-
 cr-restore.c             |  4 ++--
 include/action-scripts.h | 11 ++++++++++-
 net.c                    |  4 ++--
 5 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/action-scripts.c b/action-scripts.c
index fc95f9a..c247ca9 100644
--- a/action-scripts.c
+++ b/action-scripts.c
@@ -11,11 +11,20 @@
 #include "cr-service.h"
 #include "action-scripts.h"
 
-int run_scripts(char *action)
+static char *action_names[] = {
+	[ ACT_POST_DUMP ]	= "post-dump",
+	[ ACT_POST_RESTORE ]	= "post-restore",
+	[ ACT_NET_LOCK ]	= "network-lock",
+	[ ACT_NET_UNLOCK ]	= "network-unlock",
+	[ ACT_SETUP_NS ]	= "setup-namespaces",
+};
+
+int run_scripts(enum script_actions act)
 {
 	struct script *script;
 	int ret = 0;
 	char image_dir[PATH_MAX];
+	char *action = action_names[act];
 
 	pr_debug("Running %s scripts\n", action);
 
diff --git a/cr-dump.c b/cr-dump.c
index e544fdc..91336e8 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1873,7 +1873,7 @@ err:
 		 * Thus ask user via script if we're to break
 		 * checkpoint.
 		 */
-		post_dump_ret = run_scripts("post-dump");
+		post_dump_ret = run_scripts(ACT_POST_DUMP);
 		if (post_dump_ret) {
 			post_dump_ret = WEXITSTATUS(post_dump_ret);
 			pr_info("Post dump script passed with %d\n", post_dump_ret);
diff --git a/cr-restore.c b/cr-restore.c
index 000baf0..d4a2a46 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -1680,7 +1680,7 @@ static int restore_root_task(struct pstree_item *init)
 	if (ret)
 		goto out;
 
-	ret = run_scripts("setup-namespaces");
+	ret = run_scripts(ACT_SETUP_NS);
 	if (ret)
 		goto out;
 
@@ -1700,7 +1700,7 @@ static int restore_root_task(struct pstree_item *init)
 	if (ret < 0)
 		goto out_kill;
 
-	ret = run_scripts("post-restore");
+	ret = run_scripts(ACT_POST_RESTORE);
 	if (ret != 0) {
 		pr_err("Aborting restore due to script ret code %d\n", ret);
 		timing_stop(TIME_RESTORE);
diff --git a/include/action-scripts.h b/include/action-scripts.h
index 87c3b30..d8b4724 100644
--- a/include/action-scripts.h
+++ b/include/action-scripts.h
@@ -9,6 +9,15 @@ struct script {
 
 #define SCRIPT_RPC_NOTIFY	(char *)0x1
 
+enum script_actions {
+	ACT_POST_DUMP,
+	ACT_POST_RESTORE,
+	ACT_NET_LOCK,
+	ACT_NET_UNLOCK,
+	ACT_SETUP_NS,
+};
+
 extern int add_script(char *path, int arg);
-extern int run_scripts(char *action);
+extern int run_scripts(enum script_actions);
+
 #endif /* __CR_ACTION_SCRIPTS_H__ */
diff --git a/net.c b/net.c
index bdf8d44..543f24c 100644
--- a/net.c
+++ b/net.c
@@ -592,7 +592,7 @@ int network_lock(void)
 	if  (!(root_ns_mask & CLONE_NEWNET))
 		return 0;
 
-	return run_scripts("network-lock");
+	return run_scripts(ACT_NET_LOCK);
 }
 
 void network_unlock(void)
@@ -603,7 +603,7 @@ void network_unlock(void)
 	rst_unlock_tcp_connections();
 
 	if (root_ns_mask & CLONE_NEWNET)
-		run_scripts("network-unlock");
+		run_scripts(ACT_NET_UNLOCK);
 }
 
 int veth_pair_add(char *in, char *out)
-- 
1.8.4.2




More information about the CRIU mailing list