From 185cfc05eecc8ebd2388e9c033ff63a71ae4ca20 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Thu, 21 Apr 2016 15:57:05 +0300 Subject: [PATCH] actions: Move shell scripts into helper Signed-off-by: Pavel Emelyanov --- criu/action-scripts.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/criu/action-scripts.c b/criu/action-scripts.c index bd5c094db..01c6a026b 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");