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

Tycho Andersen tycho.andersen at canonical.com
Mon Aug 4 06:18:05 PDT 2014


Hi Pavel,

On Mon, Aug 04, 2014 at 01:54:37PM +0400, Pavel Emelyanov wrote:
> On 07/29/2014 09:06 PM, Tycho Andersen wrote:
> 
> Hi, Tycho!
> 
> The issue with action scripts in library is quite nasty.
> 
> First of all, when using service, we cannot ask one to call any scripts, since
> service is run as root and making it run user-provided code is unsafe. Instead
> of doing this we make service respond back via socket when some script should
> be called. At that time service waits for the client to do the action and wake
> service back. This is what p.haul does and what Andrey pointed out.
> 
> As far as the library is concerned -- I had an idea that we could register a
> callback, that should be called when the service reports that we have to make
> some action, but I haven't tried implementing it yet.
> 
> How do you think actions would be suitable for you when used with library?

I think that exists already, doesn't it? That's what Andrew pointed me
to (viz. criu_set_notify_cb()). Or do I misunderstand?

Tycho

> Thanks,
> Pavel
> 
> > Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
> > ---
> >  cr-service.c       | 15 +++++++++++++++
> >  lib/criu.c         | 19 +++++++++++++++++++
> >  lib/criu.h         |  1 +
> >  protobuf/rpc.proto |  2 ++
> >  4 files changed, 37 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..9d84c83 100644
> > --- a/lib/criu.c
> > +++ b/lib/criu.c
> > @@ -259,6 +259,25 @@ 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)
> > +		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 {
> > 
> 


More information about the CRIU mailing list