From 2f3c929aff65366706d4f90c670dbf416a24d715 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Tue, 4 Oct 2011 14:07:07 +0400 Subject: [PATCH] dump: Add should_ignore_fd helper We should ignore tty devices for a while. Signed-off-by: Cyrill Gorcunov --- cr-dump.c | 51 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/cr-dump.c b/cr-dump.c index 4069ca55d..e8f0de77b 100644 --- a/cr-dump.c +++ b/cr-dump.c @@ -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; }