Skip to content

Commit

Permalink
remote: Use tmp file buffer when restore ip dump
Browse files Browse the repository at this point in the history
When CRIU calls the ip tool on restore, it passes the fd of remote
socket by replacing the STDIN before execvp. The stdin is used by the
ip tool to receive input. However, the ip tool calls ftell(stdin)
which fails with "Illegal seek" since UNIX sockets do not support file
positioning operations. To resolve this issue, read the received
content from the UNIX socket and store it into temporary file, then
replace STDIN with the fd of this tmp file.

Fixes checkpoint-restore#311

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
  • Loading branch information
rst0git committed Sep 13, 2018
1 parent d23332f commit b5ed5da
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions criu/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -1914,19 +1914,46 @@ static int dump_netns_conf(struct ns_id *ns, struct cr_imgset *fds)

static int restore_ip_dump(int type, int pid, char *cmd)
{
int ret = -1;
int ret = -1, sockfd, n, written;
FILE *tmp_file;
struct cr_img *img;
char buf[1024];

img = open_image(type, O_RSTR, pid);
if (empty_image(img)) {
close_image(img);
return 0;
}
sockfd = img_raw_fd(img);
tmp_file = tmpfile();
if (!tmp_file) {
pr_perror("Failed to open tmpfile");
return -1;
}

while ((n = read(sockfd, buf, 1024)) > 0) {
written = fwrite(buf, sizeof(char), n, tmp_file);
if (written < n) {
pr_perror("Failed to write to tmpfile "
"[written: %d; total: %d]", written, n);
return -1;
}
}

if (fseek(tmp_file, 0, SEEK_SET)) {
pr_perror("Failed to set file position to beginning of tmpfile");
return -1;
}

if (img) {
ret = run_ip_tool(cmd, "restore", NULL, NULL, img_raw_fd(img), -1, 0);
ret = run_ip_tool(cmd, "restore", NULL, NULL, fileno(tmp_file), -1, 0);
close_image(img);
}

if(fclose(tmp_file)) {
pr_perror("Failed to close tmpfile");
}

return ret;
}

Expand Down

0 comments on commit b5ed5da

Please sign in to comment.