[v4,14/19] files: Close old service fd in clone_service_fd()

Submitted by Kirill Tkhai on Jan. 10, 2018, 2:02 p.m.

Details

Message ID 151559295593.31108.2862383726703657893.stgit@localhost.localdomain
State Accepted
Series "Introduce custom per-task service fds placement"
Headers show

Commit Message

Kirill Tkhai Jan. 10, 2018, 2:02 p.m.
Next patches will make service_fd_base not contant.
It will be "floating" and change from task to task.
This patch makes preparation for that: it closes
old service fd after it's duplicated.

Currently the code is unused as in case of
!(rsti(me)->clone_flags & CLONE_FILES), the child
has the same id as its parent, and the duplication
just does not occur.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/util.c |    2 ++
 1 file changed, 2 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/util.c b/criu/util.c
index ef1f11607..d8e7a48fe 100644
--- a/criu/util.c
+++ b/criu/util.c
@@ -558,6 +558,8 @@  int clone_service_fd(struct pstree_item *me)
 				continue;
 			pr_perror("Unable to clone %d->%d", old, new);
 		}
+		if (ret >= 0 && !(rsti(me)->clone_flags & CLONE_FILES))
+			close(old);
 	}
 
 	service_fd_id = id;