criu
criu copied to clipboard
criu C API dump does not work
I am trying to dump the program state using criu C API, however it seems that there's multiple errors that doesn't really allow me to check point. My sample code for a tracee is below
#include <stdio.h>
#include <unistd.h>
int main()
{
//for(int i = 0; i < 20; i++)
for(int i = 0;;i++)
{
printf("HELLO %d\n", i);
sleep(1);
}
}
The code to get the checkpoint is below
#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>
#include "path/to/criu.h"
int main(int argc, char **argv)
{
assert(argc == 2);
int fd = open("tmp/dump", O_DIRECTORY);
if(fd == -1)
{
fprintf(stderr, "failed to open: %s\n", strerror(errno));
return 1;
}
int pid = atoi(argv[1]);
criu_init_opts();
criu_set_service_address(NULL);
criu_set_pid(pid);
//criu_set_service_binary("./sample");
criu_set_images_dir_fd(fd);
criu_set_log_level(4);
//criu_set_log_file("dump.log");
int rv = criu_dump();
printf("criu_dump returned %d\n", rv);
return 0;
}
I run them in the following step.
- compile with libcriu.so linked for the checkpointing code
- run the sample code
- check the pid with
ps -ef | grep sample - run the checkpointing code in root (e.g. if the pid of the sample was 10000,
sudo ./a.out 10000)
Describe the results you received: I get the following outputs.
Can't exec criu swrk: No such file or directory
Can't read request: Connection reset by peer
Can't receive response: Connection reset by peer
criu_dump returned -70
I can make the first error message go away by simply uncommenting the line with function //criu_set_service_binary("./sample");
but it would start the sample process from the beginning with execlp, and that's not what I want. Has anyone faced the similar/same issue?
Additional information you deem important (e.g. issue happens only occasionally): I ran on ubuntu 16.04. I am using the following version on git repo: commit 98ac646f868d97b621c81939a8139e7a63d37393
libcriu needs the criu binary in the path and it sounds like it cannot find the criu binary.
Can't exec criu swrk: No such file or directory
The criu_set_service_binary() function can also be used to set the path to the criu binary.
Example:
https://github.com/checkpoint-restore/criu/blob/8cf99be39709238a99aaf5ca9f7f83f04233b3f4/test/others/libcriu/test_join_ns.c#L72
thank you. I was making the binary to be the tracee. So that was a dumb mistake...