[5/6] actions: Move shell scripts into helper

Submitted by Pavel Emelianov on April 21, 2016, 12:57 p.m.

Details

Message ID 5718CE21.4080906@virtuozzo.com
State Accepted
Series "Cleanup action scripts"
Commit db718ab39227c207e47487ac37d11fe1b78a58fd
Headers show

Commit Message

Pavel Emelianov April 21, 2016, 12:57 p.m.
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/action-scripts.c | 41 +++++++++++++++++++++++++++--------------
 1 file changed, 27 insertions(+), 14 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/action-scripts.c b/criu/action-scripts.c
index bd5c094..01c6a02 100644
--- a/criu/action-scripts.c
+++ b/criu/action-scripts.c
@@ -39,25 +39,13 @@  static int scripts_mode = SCRIPTS_NONE;
 static int rpc_sk;
 static LIST_HEAD(scripts);
 
-int run_scripts(enum script_actions act)
+static int run_shell_scripts(const char *action)
 {
-	struct script *script;
 	int ret = 0;
+	struct script *script;
 	char image_dir[PATH_MAX];
-	const char *action = action_names[act];
 	char root_item_pid[16];
 
-	pr_debug("Running %s scripts\n", action);
-
-	if (scripts_mode == SCRIPTS_NONE)
-		return 0;
-
-	if (scripts_mode == SCRIPTS_RPC) {
-		pr_debug("\tRPC\n");
-		ret = send_criu_rpc_script(act, (char *)action, rpc_sk);
-		goto out;
-	}
-
 	if (setenv("CRTOOLS_SCRIPT_ACTION", action, 1)) {
 		pr_perror("Can't set CRTOOLS_SCRIPT_ACTION=%s", action);
 		return -1;
@@ -84,6 +72,31 @@  int run_scripts(enum script_actions act)
 
 	unsetenv("CRTOOLS_SCRIPT_ACTION");
 
+	return ret;
+}
+
+int run_scripts(enum script_actions act)
+{
+	int ret = 0;
+	const char *action = action_names[act];
+
+	pr_debug("Running %s scripts\n", action);
+
+	if (scripts_mode == SCRIPTS_NONE)
+		return 0;
+
+	if (scripts_mode == SCRIPTS_RPC) {
+		pr_debug("\tRPC\n");
+		ret = send_criu_rpc_script(act, (char *)action, rpc_sk);
+		goto out;
+	}
+
+	if (scripts_mode == SCRIPTS_SHELL) {
+		ret = run_shell_scripts(action);
+		goto out;
+	}
+
+	BUG();
 out:
 	if (ret)
 		pr_err("One of more action scripts failed\n");