From d6ae662374e3ed4e6a1db330c5b652b35127cc35 Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Mon, 21 Jan 2013 17:34:27 +0400 Subject: [PATCH] cr-dump: call stat for /proc/pid/fd/X directly This patch can be committed instead of: [PATCH 1/6] cr-dump: move parasite_drain_fds_seized out of dump_task_files [PATCH 2/6] cr-dump: fix dumping file locks in a mount namespace readlink is not required here and a file can be unavailable, if a process is in another mnt namespace Signed-off-by: Andrey Vagin Signed-off-by: Pavel Emelyanov --- cr-dump.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/cr-dump.c b/cr-dump.c index 2b72e52e8..a13f98709 100644 --- a/cr-dump.c +++ b/cr-dump.c @@ -694,36 +694,23 @@ err: static int get_fd_by_ino(unsigned long i_no, struct parasite_drain_fd *dfds, pid_t pid) { - int i, ret = -1; - char path[PATH_MAX]; - char buf[40]; + int i; + char buf[PATH_MAX]; struct stat fd_stat; - i = 0; - while (i < dfds->nr_fds) { + for (i = 0; i < dfds->nr_fds; i++) { snprintf(buf, sizeof(buf), "/proc/%d/fd/%d", pid, dfds->fds[i]); - buf[39] = '\0'; - memset(path, 0, sizeof(path)); - ret = readlink(buf, path, sizeof(path)); - if (ret < 0) { - pr_err("Read link %s failed!\n", buf); - goto err; - } - - if (stat(path, &fd_stat) == -1) { - i++; - pr_msg("Could not get %s stat!\n", path); + if (stat(buf, &fd_stat) == -1) { + pr_msg("Could not get %s stat!\n", buf); continue; } if (fd_stat.st_ino == i_no) return dfds->fds[i]; - i++; } -err: return -1; }