2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-09-03 07:45:17 +00:00

libcriu: Ability to fetch arguments from notifications

After a bit more thinking I found a way to fetch arguments
from notifications -- pass opaque value into callback and
provide a set of calls for exploring one.

With this we can

a) provide more data if service supplies additional fields
   in the future
b) not check the action name to decide whether or not the
   requested argument is available

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Pavel Emelyanov
2014-06-26 13:58:53 +04:00
parent 5cea861d7f
commit 43e5d05134
3 changed files with 23 additions and 5 deletions

View File

@@ -19,7 +19,7 @@ const char *criu_lib_version = CRIU_VERSION;
static char *service_address = CR_DEFAULT_SERVICE_ADDRESS; static char *service_address = CR_DEFAULT_SERVICE_ADDRESS;
static CriuOpts *opts; static CriuOpts *opts;
static int (*notify)(char *action); static int (*notify)(char *action, criu_notify_arg_t na);
static int saved_errno; static int saved_errno;
void criu_set_service_address(char *path) void criu_set_service_address(char *path)
@@ -47,13 +47,18 @@ int criu_init_opts(void)
return 0; return 0;
} }
void criu_set_notify_cb(int (*cb)(char *action)) void criu_set_notify_cb(int (*cb)(char *action, criu_notify_arg_t na))
{ {
notify = cb; notify = cb;
opts->has_notify_scripts = true; opts->has_notify_scripts = true;
opts->notify_scripts = true; opts->notify_scripts = true;
} }
int criu_notify_pid(criu_notify_arg_t na)
{
return na->has_pid ? na->pid : 0;
}
void criu_set_pid(int pid) void criu_set_pid(int pid)
{ {
opts->has_pid = true; opts->has_pid = true;
@@ -374,7 +379,7 @@ again:
if ((*resp)->type == CRIU_REQ_TYPE__NOTIFY) { if ((*resp)->type == CRIU_REQ_TYPE__NOTIFY) {
if (notify) if (notify)
ret = notify((*resp)->notify->script); ret = notify((*resp)->notify->script, (*resp)->notify);
ret = send_notify_ack(fd, ret); ret = send_notify_ack(fd, ret);
if (!ret) if (!ret)

View File

@@ -50,7 +50,20 @@ void criu_set_root(char *root);
int criu_set_exec_cmd(int argc, char *argv[]); int criu_set_exec_cmd(int argc, char *argv[]);
int criu_add_ext_mount(char *key, char *val); int criu_add_ext_mount(char *key, char *val);
int criu_add_veth_pair(char *in, char *out); int criu_add_veth_pair(char *in, char *out);
void criu_set_notify_cb(int (*cb)(char *action));
/*
* The criu_notify_arg_t na argument is an opaque
* value that callbacks (cb-s) should pass into
* criu_notify_xxx() calls to fetch arbitrary values
* from notification. If the value is not available
* some non-existing one is reported.
*/
typedef struct _CriuNotify *criu_notify_arg_t;
void criu_set_notify_cb(int (*cb)(char *action, criu_notify_arg_t na));
/* Get pid of root task. 0 if not available */
int criu_notify_pid(criu_notify_arg_t na);
/* Here is a table of return values and errno's of functions /* Here is a table of return values and errno's of functions
* from the list down below. * from the list down below.

View File

@@ -9,7 +9,7 @@
#define SUCC_ECODE 42 #define SUCC_ECODE 42
static int actions_called = 0; static int actions_called = 0;
static int notify(char *action) static int notify(char *action, criu_notify_arg_t na)
{ {
printf("ACTION: %s\n", action); printf("ACTION: %s\n", action);
actions_called++; actions_called++;