[CRIU] [PATCH cr 3/9] crtools: add ability to execute external scripts (v2)

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


Scripts are executed when external actions required.
CRTOOLS_SCRIPT_ACTION contains a required action.
If a script doesn't know a current action, it should exit with 0.

The first usecase will be lock/unlock network.

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

diff --git a/crtools.c b/crtools.c
index 0b65115..d5bb0b9 100644
--- a/crtools.c
+++ b/crtools.c
@@ -72,6 +72,7 @@ int main(int argc, char *argv[])
 	/* Default options */
 	opts.final_state = TASK_DEAD;
 	INIT_LIST_HEAD(&opts.veth_pairs);
+	INIT_LIST_HEAD(&opts.scripts);
 
 	if (init_service_fd())
 		return -1;
@@ -97,6 +98,7 @@ int main(int argc, char *argv[])
 			{ "pidfile", required_argument, 0, 46},
 			{ "veth-pair", required_argument, 0, 47},
 			{ "partial-session", required_argument, 0, 48},
+			{ "script", required_argument, 0, 49},
 			{ },
 		};
 
@@ -202,6 +204,18 @@ int main(int argc, char *argv[])
 		case 48:
 			opts.partial_session = true;
 			break;
+		case 49:
+			{
+				struct script *script;
+
+				script = xmalloc(sizeof(struct script));
+				if (script == NULL)
+					return -1;
+
+				script->path = optarg;
+				list_add(&script->node, &opts.scripts);
+			}
+			break;
 		case 'V':
 			pr_msg("Version: %d.%d\n", CRIU_VERSION_MAJOR, CRIU_VERSION_MINOR);
 			return 0;
@@ -293,6 +307,10 @@ usage:
 	pr_msg("  --evasive-devices	use any path to a device file if the original one is inaccessible\n");
 	pr_msg("  --partial-session	allow to work with a part of a process session\n");
 	pr_msg("  --veth-pair [IN=OUT]	correspondence between outside and inside names of veth devices\n");
+	pr_msg("  --script [SCRIPT] 	add an external script\n");
+	pr_msg("			The environment variable CRTOOL_SCRIPT_ACTION contains one of the actions:\n");
+	pr_msg("			* network-lock - lock network in a target network namespace");
+	pr_msg("			* network-unlock - unlock network in a target network namespace");
 
 	pr_msg("\n* Logging:\n");
 	pr_msg("  -o|--log-file [NAME]  log file name (relative path is relative to --images-dir)\n");
diff --git a/include/crtools.h b/include/crtools.h
index d59980f..f1769db 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -82,6 +82,11 @@ enum {
 	CR_FD_MAX
 };
 
+struct script {
+	struct list_head node;
+	char *path;
+};
+
 struct cr_options {
 	int			final_state;
 	char			*show_dump_file;
@@ -97,6 +102,7 @@ struct cr_options {
 	char			*root;
 	char			*pidfile;
 	struct list_head	veth_pairs;
+	struct list_head	scripts;
 };
 
 extern struct cr_options opts;
-- 
1.7.1



More information about the CRIU mailing list