Commit bc1f9d72 authored by Andrey Vagin's avatar Andrey Vagin Committed by Cyrill Gorcunov

Skip a standard destriptor only if it's tty (v2)

ZDTM tests redirect standart descriptors to /dev/null

v2: * Skip tty only if it's a standard descriptor.
    * No strcmps on names.
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Acked-by: 's avatarPavel Emelyanov <xemul@parallels.com>
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent 89dde261
...@@ -219,34 +219,6 @@ err: ...@@ -219,34 +219,6 @@ err:
return ret; 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, 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) unsigned int flags, struct cr_fdset *cr_fdset)
{ {
...@@ -254,9 +226,6 @@ static int dump_one_fd(char *pid_fd_dir, int dir, char *fd_name, unsigned long p ...@@ -254,9 +226,6 @@ static int dump_one_fd(char *pid_fd_dir, int dir, char *fd_name, unsigned long p
struct stat st_buf; struct stat st_buf;
int fd; int fd;
if (should_ignore_fd(pid_fd_dir, dir, fd_name))
return 0;
fd = openat(dir, fd_name, O_RDONLY); fd = openat(dir, fd_name, O_RDONLY);
if (fd < 0) { if (fd < 0) {
pr_perror("Failed to openat %s/%d %s\n", pid_fd_dir, dir, fd_name); pr_perror("Failed to openat %s/%d %s\n", pid_fd_dir, dir, fd_name);
...@@ -268,6 +237,17 @@ static int dump_one_fd(char *pid_fd_dir, int dir, char *fd_name, unsigned long p ...@@ -268,6 +237,17 @@ static int dump_one_fd(char *pid_fd_dir, int dir, char *fd_name, unsigned long p
return -1; return -1;
} }
if (S_ISCHR(st_buf.st_mode) &&
( major(st_buf.st_rdev) == TTY_MAJOR ||
major(st_buf.st_rdev) == UNIX98_PTY_SLAVE_MAJOR)) {
/* skip only standard destriptors */
if (atoi(fd_name) < 3) {
pr_info("... Skipping tty ... %s/%s\n", pid_fd_dir, fd_name);
return 0;
}
goto err;
}
if (S_ISREG(st_buf.st_mode)) if (S_ISREG(st_buf.st_mode))
return dump_one_reg_file(FDINFO_FD, atol(fd_name), return dump_one_reg_file(FDINFO_FD, atol(fd_name),
fd, 1, pos, flags, cr_fdset); fd, 1, pos, flags, cr_fdset);
...@@ -283,6 +263,7 @@ static int dump_one_fd(char *pid_fd_dir, int dir, char *fd_name, unsigned long p ...@@ -283,6 +263,7 @@ static int dump_one_fd(char *pid_fd_dir, int dir, char *fd_name, unsigned long p
st_buf.st_ino, flags, cr_fdset); st_buf.st_ino, flags, cr_fdset);
} }
err:
pr_err("Can't dump file %s of that type [%x]\n", fd_name, st_buf.st_mode); pr_err("Can't dump file %s of that type [%x]\n", fd_name, st_buf.st_mode);
return 1; return 1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment