[CRIU] [PATCH] lib: add inherit_fd
Ruslan Kuprieiev
rkuprieiev at cloudlinux.com
Thu Oct 13 06:07:36 PDT 2016
It is already present in CLI and RPC, so libcriu should reflect it too.
Signed-off-by: Ruslan Kuprieiev <rkuprieiev at cloudlinux.com>
---
lib/c/criu.c | 41 +++++++++++++++++++++++++++++++++++++++++
lib/c/criu.h | 2 ++
2 files changed, 43 insertions(+)
diff --git a/lib/c/criu.c b/lib/c/criu.c
index 5c65d9f..a7df66a 100644
--- a/lib/c/criu.c
+++ b/lib/c/criu.c
@@ -799,6 +799,47 @@ int criu_add_irmap_path(char *path)
return criu_local_add_irmap_path(global_opts, path);
}
+int criu_local_add_inherit_fd(criu_opts *opts, int fd, char *key)
+{
+ int nr;
+ InheritFd **a, *f;
+
+ /* Inheriting is only supported with swrk mode */
+ if (opts->service_comm != CRIU_COMM_BIN)
+ return -1;
+
+ f = malloc(sizeof(*f));
+ if (!f)
+ goto er;
+ inherit_fd__init(f);
+
+ f->fd = fd;
+ f->key = strdup(key);
+ if (!f->key)
+ goto er_f;
+
+ nr = opts->rpc->n_inherit_fd + 1;
+ a = realloc(opts->rpc->inherit_fd, nr * sizeof(f));
+ if (!a)
+ goto err_k;
+
+ a[nr - 1] = f;
+ opts->rpc->inherit_fd = a;
+ opts->rpc->n_inherit_fd = nr;
+ return 0;
+err_k:
+ free(f->key);
+er_f:
+ free(f);
+er:
+ return -ENOMEM;
+}
+
+int criu_add_inherit_fd(int fd, char *key)
+{
+ return criu_local_add_inherit_fd(global_opts, fd, key);
+}
+
static CriuResp *recv_resp(int socket_fd)
{
unsigned char *buf = NULL;
diff --git a/lib/c/criu.h b/lib/c/criu.h
index 5755782..5785044 100644
--- a/lib/c/criu.h
+++ b/lib/c/criu.h
@@ -92,6 +92,7 @@ int criu_add_enable_fs(char *fs);
int criu_add_skip_mnt(char *mnt);
void criu_set_ghost_limit(unsigned int limit);
int criu_add_irmap_path(char *path);
+int criu_add_inherit_fd(int fd, char *key);
/*
* The criu_notify_arg_t na argument is an opaque
@@ -200,6 +201,7 @@ int criu_local_add_irmap_path(criu_opts *opts, char *path);
int criu_local_add_cg_props(criu_opts *opts, char *stream);
int criu_local_add_cg_props_file(criu_opts *opts, char *path);
int criu_local_add_cg_dump_controller(criu_opts *opts, char *name);
+int criu_local_add_inherit_fd(criu_opts *opts, int fd, char *key);
void criu_local_set_notify_cb(criu_opts *opts, int (*cb)(char *action, criu_notify_arg_t na));
--
2.5.5
More information about the CRIU
mailing list