[CRIU] [PATCH 1/6] lib: add support for --action-script in libcriu

Tycho Andersen tycho.andersen at canonical.com
Tue Jul 29 15:22:46 PDT 2014


Hi Serge,

On Tue, Jul 29, 2014 at 10:04:41PM +0000, Serge Hallyn wrote:
> Quoting Tycho Andersen (tycho.andersen at canonical.com):
> >
> > +int criu_add_action_script(char *script)
> > +{
> > +	void *m;
> > +	opts->n_action_scripts++;
> > +	m = realloc(opts->action_scripts, sizeof(char*) * opts->n_action_scripts);
> > +	if (!m)
> 
> Need to dec opts->n_action_scripts here as well?

Yes, of course. Here's the updated patch.

Tycho


lib: add support for --action-script in libcriu

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 cr-service.c       | 15 +++++++++++++++
 lib/criu.c         | 21 +++++++++++++++++++++
 lib/criu.h         |  1 +
 protobuf/rpc.proto |  2 ++
 4 files changed, 39 insertions(+)

diff --git a/cr-service.c b/cr-service.c
index 64ce751..11e9778 100644
--- a/cr-service.c
+++ b/cr-service.c
@@ -300,6 +300,21 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
 			return -1;
 	}
 
+	for (i = 0; i < req->n_action_scripts; i++) {
+		struct script *script;
+
+		script = xmalloc(sizeof(*script));
+		if(!script)
+			return -1;
+
+		script->path = xstrdup(req->action_scripts[i]);
+		if (!script->path) {
+			free(script);
+			return -1;
+		}
+		list_add(&script->node, &opts.scripts);
+	}
+
 	if (req->has_cpu_cap)
 		opts.cpu_cap = req->cpu_cap;
 
diff --git a/lib/criu.c b/lib/criu.c
index 7c1ac07..2dd22da 100644
--- a/lib/criu.c
+++ b/lib/criu.c
@@ -259,6 +259,27 @@ er:
 	return -ENOMEM;
 }
 
+int criu_add_action_script(char *script)
+{
+	void *m;
+	opts->n_action_scripts++;
+	m = realloc(opts->action_scripts, sizeof(char*) * opts->n_action_scripts);
+	if (!m) {
+		opts->n_action_scripts--;
+		return -1;
+	}
+	opts->action_scripts = m;
+
+	m = strdup(script);
+	opts->action_scripts[opts->n_action_scripts - 1] = m;
+	if (!m) {
+		opts->n_action_scripts--;
+		return -1;
+	}
+
+	return 0;
+}
+
 static CriuResp *recv_resp(int socket_fd)
 {
 	unsigned char buf[CR_MAX_MSG_SIZE];
diff --git a/lib/criu.h b/lib/criu.h
index 18faaef..5ab09c3 100644
--- a/lib/criu.h
+++ b/lib/criu.h
@@ -47,6 +47,7 @@ void criu_set_log_level(int log_level);
 void criu_set_log_file(char *log_file);
 void criu_set_cpu_cap(unsigned int cap);
 void criu_set_root(char *root);
+int criu_add_action_script(char *script);
 int criu_set_exec_cmd(int argc, char *argv[]);
 int criu_add_ext_mount(char *key, char *val);
 int criu_add_veth_pair(char *in, char *out);
diff --git a/protobuf/rpc.proto b/protobuf/rpc.proto
index e50d97c..1604f37 100644
--- a/protobuf/rpc.proto
+++ b/protobuf/rpc.proto
@@ -45,6 +45,8 @@ message criu_opts {
 	repeated string			exec_cmd	= 22;
 
 	repeated ext_mount_map		ext_mnt		= 23;
+
+	repeated string			action_scripts	= 24;
 }
 
 message criu_dump_resp {
-- 
1.9.1



More information about the CRIU mailing list