Changes

Jump to: navigation, search

C API

201 bytes added, 23:31, 19 December 2013
misc fixes
'''libcriu''' is a C API for CRIU, which is a simple wrapper around our [[RPC]]. Although you can use [[RPC]] directly, libcriu provides is a wrapper providing the interface that is much easier to use in from C appscode. Note that [[RPC]] is supported in the first place, and if you want the most recent set of features you should probably use [[RPC]]directly.
== Beginning ==
You could find libcriu header at '''functions are defined in <code>lib/criu.h'''</code>. To create '''a library <code>lib/libcriu.so''' </code>, run '''<code>make''' </code> in the main directory.
== Setup options ==
=== init options ===
 Call '''<code>int criu_init_opts(void)''' </code> to init initialize request options.  Note: it should be called before using any other functions from libcriu , except <code>criu_check()</code>. Also you should use it to reinit reinitialize options. It return returns 0 on success and -1 on fail.
=== set service address ===
 Use '''<code>void criu_set_service_address(char *address)''' </code> to specify path to a CRIU service socket. Call it with NULL to make libcriu use the default address: (currently <code>/var/run/criu_service.socket</code>).
=== set dump/restore options ===
Use <code>criu_set_* </code> functions to setup dump/restore options. 
<pre>
void criu_set_pid(int pid);
</pre>
If no pid is set on dump, CRIU will dump client the calling process by defaultitself.'''{{Note:''' Whole |If a calling process is not run as root, the whole process tree <pid> to be dumped must have the same uid, as a client, or client's uid must be == 0, otherwise CRIU won't refuses to dump nothing at all. See [[Usage#Security]].}}
'''{{Note:''' |<code>images_dir_fd </code> is '''required''' at dump/restore, all other options may not might be setleft unset.Client The client must open directory for/with images by himself itself and set <code>images_dir_fd </code> to it's the opened directory fd.CRIU will open /proc/<client's_pid>/fd/<images_dir_fd>, so it will work, even if the client is in another namespace.}}
The logic of setting request is the same as when setting options in console. Here is an example:
<pre> #criu restore -D /path/to/imgs_dir -v4 -o restore.log</pre> 
is equal to:
<pre>
== check/dump/restore ==
 
Use this functions to check/dump/restore:
<pre>
== Examples ==
 
You could find example of using libcriu at test/libcriu.

Navigation menu