d3d9a8
From 98c8e44f749dd7ed0aa8c540f566bda54d7adfa1 Mon Sep 17 00:00:00 2001
d3d9a8
From: Andrey Vagin <avagin@openvz.org>
d3d9a8
Date: Thu, 2 Jul 2015 12:47:07 +0300
d3d9a8
Subject: [PATCH] pipe: don't create a tranport descriptor for inhereted pipes
d3d9a8
d3d9a8
Otherwise we can get an error like this:
d3d9a8
1: \t\tCreate transport fd /crtools-fd-1-5
d3d9a8
...
d3d9a8
1: Found id pipe:[122747] (fd 8) in inherit fd list
d3d9a8
1: File pipe:[122747] will be restored from fd 9 duped from inherit
d3d9a8
d3d9a8
1: Error (util.c:131): fd 5 already in use (called at files.c:872)
d3d9a8
Signed-off-by: Andrey Vagin <avagin@openvz.org>
d3d9a8
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
d3d9a8
---
d3d9a8
 files.c |  3 +++
d3d9a8
 pipes.c | 20 ++++++++++++--------
d3d9a8
 2 files changed, 15 insertions(+), 8 deletions(-)
d3d9a8
d3d9a8
diff --git a/files.c b/files.c
d3d9a8
index 4eeb988..3e69be7 100644
d3d9a8
--- a/files.c
d3d9a8
+++ b/files.c
d3d9a8
@@ -1394,6 +1394,9 @@ bool inherited_fd(struct file_desc *d, int *fd_p)
d3d9a8
 	if (i_fd < 0)
d3d9a8
 		return false;
d3d9a8
 
d3d9a8
+	if (fd_p == NULL)
d3d9a8
+		return true;
d3d9a8
+
d3d9a8
 	*fd_p = dup(i_fd);
d3d9a8
 	if (*fd_p < 0)
d3d9a8
 		pr_perror("Inherit fd DUP failed");
d3d9a8
diff --git a/pipes.c b/pipes.c
d3d9a8
index 7590472..62f550c 100644
d3d9a8
--- a/pipes.c
d3d9a8
+++ b/pipes.c
d3d9a8
@@ -393,18 +393,22 @@ static int collect_one_pipe(void *o, ProtobufCMessage *base)
d3d9a8
 	pr_info("Collected pipe entry ID %#x PIPE ID %#x\n",
d3d9a8
 			pi->pe->id, pi->pe->pipe_id);
d3d9a8
 
d3d9a8
-	list_for_each_entry(tmp, &pipes, list)
d3d9a8
-		if (pi->pe->pipe_id == tmp->pe->pipe_id)
d3d9a8
-			break;
d3d9a8
+	if (file_desc_add(&pi->d, pi->pe->id, &pipe_desc_ops))
d3d9a8
+		return -1;
d3d9a8
 
d3d9a8
-	if (&tmp->list == &pipes)
d3d9a8
-		INIT_LIST_HEAD(&pi->pipe_list);
d3d9a8
-	else
d3d9a8
-		list_add(&pi->pipe_list, &tmp->pipe_list);
d3d9a8
+	INIT_LIST_HEAD(&pi->pipe_list);
d3d9a8
+	if (!inherited_fd(&pi->d, NULL)) {
d3d9a8
+		list_for_each_entry(tmp, &pipes, list)
d3d9a8
+			if (pi->pe->pipe_id == tmp->pe->pipe_id)
d3d9a8
+				break;
d3d9a8
+
d3d9a8
+		if (&tmp->list != &pipes)
d3d9a8
+			list_add(&pi->pipe_list, &tmp->pipe_list);
d3d9a8
+	}
d3d9a8
 
d3d9a8
 	list_add_tail(&pi->list, &pipes);
d3d9a8
-	return file_desc_add(&pi->d, pi->pe->id, &pipe_desc_ops);
d3d9a8
 
d3d9a8
+	return 0;
d3d9a8
 }
d3d9a8
 
d3d9a8
 struct collect_image_info pipe_cinfo = {