[CRIU] [PATCH 3/4] files: add support of O_PATH

Andrey Vagin avagin at openvz.org
Mon Apr 7 03:00:14 PDT 2014


fcntl(F_GETOWN) doesn't work for fd with O_PATH.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 files.c       | 31 +++++++++++++++++++------------
 pie/util-fd.c |  7 +++++--
 2 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/files.c b/files.c
index a83cd83..49a3a4e 100644
--- a/files.c
+++ b/files.c
@@ -233,20 +233,27 @@ static int fill_fd_params(struct parasite_ctl *ctl, int fd, int lfd,
 	pr_info("%d fdinfo %d: pos: 0x%16"PRIx64" flags: %16o/%#x\n",
 		ctl->pid.real, fd, p->pos, p->flags, (int)p->fd_flags);
 
-	ret = fcntl(lfd, F_GETSIG, 0);
-	if (ret < 0) {
-		pr_perror("Can't get owner signum on %d", lfd);
-		return -1;
-	}
-	p->fown.signum = ret;
+	if (!(p->flags & O_PATH)) {
+		if (opts->fown.pid < 0) {
+			pr_err("Unable to get owner\n");
+			return 1;
+		}
 
-	if (opts->fown.pid == 0)
-		return 0;
+		ret = fcntl(lfd, F_GETSIG, 0);
+		if (ret < 0) {
+			pr_perror("Can't get owner signum on %d", lfd);
+			return -1;
+		}
+		p->fown.signum = ret;
 
-	p->fown.pid	 = opts->fown.pid;
-	p->fown.pid_type = opts->fown.pid_type;
-	p->fown.uid	 = opts->fown.uid;
-	p->fown.euid	 = opts->fown.euid;
+		if (opts->fown.pid == 0)
+			return 0;
+
+		p->fown.pid	 = opts->fown.pid;
+		p->fown.pid_type = opts->fown.pid_type;
+		p->fown.uid	 = opts->fown.uid;
+		p->fown.euid	 = opts->fown.euid;
+	}
 
 	return 0;
 }
diff --git a/pie/util-fd.c b/pie/util-fd.c
index 12d1bf3..eb0319f 100644
--- a/pie/util-fd.c
+++ b/pie/util-fd.c
@@ -88,7 +88,7 @@ int send_fds(int sock, struct sockaddr_un *saddr, int len,
 			p->flags = (char)flags;
 
 			ret = __sys(fcntl)(fd, F_GETOWN_EX, (long)&owner_ex);
-			if (ret) {
+			if (ret && ret != -EBADF) {
 				pr_err("fcntl(%d, F_GETOWN_EX) -> %d\n", fd, ret);
 				return -1;
 			}
@@ -96,7 +96,10 @@ int send_fds(int sock, struct sockaddr_un *saddr, int len,
 			/*
 			 * Simple case -- nothing is changed.
 			 */
-			if (owner_ex.pid == 0) {
+			if (ret == -EBADF) { /* O_PATH */
+				p->fown.pid = -1;
+				continue;
+			} else if (owner_ex.pid == 0) {
 				p->fown.pid = 0;
 				continue;
 			}
-- 
1.8.5.3



More information about the CRIU mailing list