2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-30 22:05:36 +00:00

dump: Add should_ignore_fd helper

We should ignore tty devices for a while.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov
2011-10-04 14:07:07 +04:00
parent 609e431376
commit 2f3c929aff

View File

@@ -221,6 +221,34 @@ err:
return ret;
}
static bool should_ignore_fd(char *pid_fd_dir, int dir, char *fd_name)
{
if (!strcmp(fd_name, "0")) {
pr_info("... Skipping stdin ...\n");
return true;
} else if (!strcmp(fd_name, "1")) {
pr_info("... Skipping stdout ...\n");
return true;
} else if (!strcmp(fd_name, "2")) {
pr_info("... Skipping stderr ...\n");
return true;
} else {
char ttybuf[32];
if (readlinkat(dir, fd_name, ttybuf, sizeof(ttybuf)) > 0) {
if (!strncmp(ttybuf, "/dev/tty", 8)) {
pr_info("... Skipping tty ...\n");
return true;
}
} else {
pr_perror("Failed to readlink %s/%d %s\n", pid_fd_dir, dir, fd_name);
return false;
}
}
return false;
}
static int dump_one_fd(char *pid_fd_dir, int dir, char *fd_name, unsigned long pos,
unsigned int flags, struct cr_fdset *cr_fdset)
{
@@ -228,6 +256,9 @@ static int dump_one_fd(char *pid_fd_dir, int dir, char *fd_name, unsigned long p
struct stat st_buf;
int fd;
if (should_ignore_fd(pid_fd_dir, dir, fd_name))
return 0;
fd = openat(dir, fd_name, O_RDONLY);
if (fd < 0) {
pr_perror("Failed to openat %s/%d %s\n", pid_fd_dir, dir, fd_name);
@@ -254,26 +285,6 @@ static int dump_one_fd(char *pid_fd_dir, int dir, char *fd_name, unsigned long p
st_buf.st_ino, flags, cr_fdset);
}
if (!strcmp(fd_name, "0")) {
pr_info("... Skipping stdin ...\n");
return 0;
}
if (!strcmp(fd_name, "1")) {
pr_info("... Skipping stdout ...\n");
return 0;
}
if (!strcmp(fd_name, "2")) {
pr_info("... Skipping stderr ...\n");
return 0;
}
if (!strcmp(fd_name, "3")) {
pr_info("... Skipping tty ...\n");
return 0;
}
pr_err("Can't dump file %s of that type [%x]\n", fd_name, st_buf.st_mode);
return 1;
}