[CRIU] [PATCH 3/2] libcriu: Ability to fetch arguments from notifications

Pavel Emelyanov xemul at parallels.com
Thu Jun 26 03:06:44 PDT 2014


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 at parallels.com>
---
 lib/criu.c | 11 ++++++++---
 lib/criu.h | 15 ++++++++++++++-
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/lib/criu.c b/lib/criu.c
index a827671..7653ff1 100644
--- a/lib/criu.c
+++ b/lib/criu.c
@@ -19,7 +19,7 @@ const char *criu_lib_version = CRIU_VERSION;
 
 static char *service_address = CR_DEFAULT_SERVICE_ADDRESS;
 static CriuOpts *opts;
-static int (*notify)(char *action);
+static int (*notify)(char *action, criu_notify_arg_t na);
 static int saved_errno;
 
 void criu_set_service_address(char *path)
@@ -47,13 +47,18 @@ int criu_init_opts(void)
 	return 0;
 }
 
-void criu_set_notify(int (*cb)(char *action))
+void criu_set_notify(int (*cb)(char *action, criu_notify_arg_t na))
 {
 	notify = cb;
 	opts->has_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)
 {
 	opts->has_pid	= true;
@@ -275,7 +280,7 @@ again:
 
 	if ((*resp)->type == CRIU_REQ_TYPE__NOTIFY) {
 		if (notify)
-			ret = notify((*resp)->notify->script);
+			ret = notify((*resp)->notify->script, (*resp)->notify);
 
 		ret = send_notify_ack(fd, ret);
 		if (!ret)
diff --git a/lib/criu.h b/lib/criu.h
index c994fd6..7950206 100644
--- a/lib/criu.h
+++ b/lib/criu.h
@@ -42,7 +42,20 @@ void criu_set_log_level(int log_level);
 void criu_set_log_file(char *log_file);
 void criu_set_cpu_cap(unsigned int cap);
 int criu_set_exec_cmd(int argc, char *argv[]);
-void criu_set_notify(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(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
  * from the list down below.
-- 
1.8.4.2




More information about the CRIU mailing list