Projects STRLCPY criu Commits 6c8ea604
🤬
  • ■ ■ ■ ■ ■ ■
    criu/filesystems.c
    skipped 381 lines
    382 382  static int tmpfs_dump(struct mount_info *pm)
    383 383  {
    384 384   int ret = -1, fd = -1, userns_pid = -1;
    385  - char tmpfs_path[PSFDS];
    386 385   struct cr_img *img;
    387 386   int tmp_fds[3], ntmp_fds = 0, i;
    388 387   
    skipped 28 lines
    417 416   if (!img)
    418 417   goto out;
    419 418   
    420  - sprintf(tmpfs_path, "/proc/self/fd/%d", fd);
    421  - 
    422 419   if (root_ns_mask & CLONE_NEWUSER)
    423 420   userns_pid = root_item->pid->real;
    424 421   
    425  - ret = cr_system_userns(-1, img_raw_fd(img), -1, "tar", (char *[])
     422 + ret = cr_system_userns(fd, img_raw_fd(img), -1, "tar", (char *[])
    426 423   { "tar", "--create",
    427 424   "--gzip",
    428 425   "--no-unquote",
    skipped 3 lines
    432 429   "--preserve-permissions",
    433 430   "--sparse",
    434 431   "--numeric-owner",
    435  - "--directory", tmpfs_path, ".", NULL }, 0, userns_pid);
     432 + "--directory", "/proc/self/fd/0", ".", NULL }, 0, userns_pid);
    436 433   
    437 434   if (ret)
    438 435   pr_err("Can't dump tmpfs content\n");
    skipped 436 lines
  • ■ ■ ■ ■ ■ ■
    criu/util.c
    skipped 492 lines
    493 493   return cr_system_userns(in, out, err, cmd, argv, flags, -1);
    494 494  }
    495 495   
     496 +static int close_fds(int minfd)
     497 +{
     498 + DIR *dir;
     499 + struct dirent *de;
     500 + int fd, ret, dfd;
     501 + 
     502 + dir = opendir("/proc/self/fd");
     503 + if (dir == NULL)
     504 + pr_perror("Can't open /proc/self/fd");
     505 + dfd = dirfd(dir);
     506 + 
     507 + while ((de = readdir(dir))) {
     508 + if (dir_dots(de))
     509 + continue;
     510 + 
     511 + ret = sscanf(de->d_name, "%d", &fd);
     512 + if (ret != 1) {
     513 + pr_err("Can't parse %s\n", de->d_name);
     514 + return -1;
     515 + }
     516 + if (dfd == fd)
     517 + continue;
     518 + if (fd < minfd)
     519 + continue;
     520 + close(fd);
     521 + }
     522 + closedir(dir);
     523 + 
     524 + return 0;
     525 +}
     526 + 
    496 527  int cr_system_userns(int in, int out, int err, char *cmd,
    497 528   char *const argv[], unsigned flags, int userns_pid)
    498 529  {
    skipped 56 lines
    555 586   
    556 587   if (reopen_fd_as_nocheck(STDERR_FILENO, err))
    557 588   goto out_chld;
     589 + 
     590 + close_fds(STDERR_FILENO + 1);
    558 591   
    559 592   execvp(cmd, argv);
    560 593   
    skipped 828 lines
Please wait...
Page is in error, reload to recover