[CRIU] [PATCH v3 3/8] dump: stat fd by fstatat()

Kinsbursky Stanislav skinsbursky at openvz.org
Mon Mar 5 13:00:56 EST 2012


This is a cleanup patch - it allows to get stats for file descriptor without
opening.

Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>

---
 cr-dump.c |   19 ++++++++++---------
 1 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 718685e..064304c 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -327,10 +327,19 @@ static int dump_one_fd(pid_t pid, int pid_fd_dir, char *d_name, struct cr_fdset
 		       struct sk_queue *sk_queue)
 {
 	struct stat fd_stat;
-	int err = -1;
+	int err;
 	struct fd_parms p;
 	int lfd;
 
+	err = fstatat(pid_fd_dir, d_name, &fd_stat, 0);
+	if (err < 0) {
+		pr_perror("Failed to fstatat %d/%s", pid_fd_dir, d_name);
+		return -1;
+	}
+
+	if (read_fd_params(pid, d_name, &fd_stat, &p))
+		return -1;
+
 	lfd = openat(pid_fd_dir, d_name, O_RDONLY);
 	if (lfd < 0) {
 		err = try_dump_socket(pid, atoi(d_name), cr_fdset, sk_queue);
@@ -341,14 +350,6 @@ static int dump_one_fd(pid_t pid, int pid_fd_dir, char *d_name, struct cr_fdset
 		return -1;
 	}
 
-	if (fstat(lfd, &fd_stat) < 0) {
-		pr_perror("Can't get stat on %ld", p.fd_name);
-		goto out_close;
-	}
-
-	if (read_fd_params(pid, d_name, &fd_stat, &p))
-		return -1;
-
 	if (S_ISCHR(fd_stat.st_mode) &&
 	    (major(fd_stat.st_rdev) == TTY_MAJOR ||
 	     major(fd_stat.st_rdev) == UNIX98_PTY_SLAVE_MAJOR)) {



More information about the CRIU mailing list