[CRIU] [PATCH] Add an optional --script-data argument to criu
Tycho Andersen
tycho.andersen at canonical.com
Thu Oct 16 01:39:47 PDT 2014
When restoring a particular container, we would like to pass the container id
to our network-{lock,unlock} script so that it can figure out which is the
right network to lock and unlock. We add a --script-data argument, which can be
used to set an environment variable that is exported for scripts to inspect.
Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
Makefile | 2 +-
action-scripts.c | 8 ++++++++
crtools.c | 6 ++++++
include/cr_options.h | 1 +
4 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index f2d06ab..e87575f 100644
--- a/Makefile
+++ b/Makefile
@@ -250,7 +250,7 @@ criu-$(CRTOOLSVERSION).tar.bz2:
v$(CRTOOLSVERSION) | bzip2 > $@
.PHONY: dist tar
-install: $(PROGRAM) $(CRIU-LIB) install-man
+install: $(PROGRAM) $(CRIU-LIB)
$(E) " INSTALL " $(PROGRAM)
$(Q) mkdir -p $(DESTDIR)$(SBINDIR)
$(Q) install -m 755 $(PROGRAM) $(DESTDIR)$(SBINDIR)
diff --git a/action-scripts.c b/action-scripts.c
index d2b1a59..638dfc5 100644
--- a/action-scripts.c
+++ b/action-scripts.c
@@ -39,6 +39,11 @@ int run_scripts(enum script_actions act)
return -1;
}
+ if (opts.script_data && setenv("CRTOOLS_SCRIPT_DATA", opts.script_data, 1)) {
+ pr_perror("Can't set CRTOOLS_SCRIPT_DATA=%s", opts.script_data);
+ return -1;
+ }
+
list_for_each_entry(script, &opts.scripts, node) {
if (script->path == SCRIPT_RPC_NOTIFY) {
pr_debug("\tRPC\n");
@@ -51,6 +56,9 @@ int run_scripts(enum script_actions act)
unsetenv("CRTOOLS_SCRIPT_ACTION");
unsetenv("CRTOOLS_IMAGE_DIR");
+ unsetenv("CRTOOLS_SCRIPT_DATA");
+ if (ret)
+ pr_err("Script exited with code %d\n", ret);
return ret;
}
diff --git a/crtools.c b/crtools.c
index a245bbb..bca60ae 100644
--- a/crtools.c
+++ b/crtools.c
@@ -187,6 +187,7 @@ int main(int argc, char *argv[], char *envp[])
{ "exec-cmd", no_argument, 0, 1059},
{ "manage-cgroups", no_argument, 0, 1060},
{ "cgroup-root", required_argument, 0, 1061},
+ { "script-data", required_argument, 0, 1062},
{ },
};
@@ -392,6 +393,9 @@ int main(int argc, char *argv[], char *envp[])
return -1;
}
break;
+ case 1062:
+ opts.script_data = optarg;
+ break;
case 'M':
{
char *aux;
@@ -591,6 +595,8 @@ usage:
" --veth-pair IN=OUT map inside veth device name to outside one\n"
" --link-remap allow to link unlinked files back when possible\n"
" --action-script FILE add an external action script\n"
+" --script-data A string of data to pass to action scripts as the\n"
+" CRTOOLS_SCRIPT_DATA environment variable.\n"
" -j|--" OPT_SHELL_JOB " allow to dump and restore shell jobs\n"
" -l|--" OPT_FILE_LOCKS " handle file locks, for safety, only used for container\n"
" -L|--libdir path to a plugin directory (by default " CR_PLUGIN_DEFAULT ")\n"
diff --git a/include/cr_options.h b/include/cr_options.h
index a9f9e92..73ca5e8 100644
--- a/include/cr_options.h
+++ b/include/cr_options.h
@@ -58,6 +58,7 @@ struct cr_options {
char *new_global_cg_root;
struct list_head new_cgroup_roots;
bool aufs; /* auto-deteced, not via cli */
+ char *script_data;
};
extern struct cr_options opts;
--
1.9.1
More information about the CRIU
mailing list