Patch in attach changes lxc-start to set CLOEXEC instead of just
returning with error.

-- 
Best Regards, Vladimir Smirnov.

From 60588293338576adc086e5f507cf86732439bfa5 Mon Sep 17 00:00:00 2001
From: Vladimir Smirnov <ci...@yandex-team.ru>
Date: Mon, 22 Aug 2011 15:16:18 +0400
Subject: [PATCH 2/2] lxc-start shouldn't exit with error, if there is
 inherited fd's.

Previous patch fixed behaviour with clone, so it's now safe just to set O_CLOEXEC flag on
all inherited fd's.

Signed-off-by: Vladimir Smirnov <ci...@yandex-team.ru>
---
 src/lxc/start.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/lxc/start.c b/src/lxc/start.c
index b8ceff6..6df70dc 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -154,6 +154,7 @@ int lxc_check_inherited(int fd_to_ignore)
 	while (!readdir_r(dir, &dirent, &direntp)) {
 		char procpath[64];
 		char path[PATH_MAX];
+		int flags;
 
 		if (!direntp)
 			break;
@@ -174,14 +175,24 @@ int lxc_check_inherited(int fd_to_ignore)
 		/*
 		 * found inherited fd
 		 */
-		ret = -1;
+		flags = fcntl(fd, F_GETFD);
+		if (flags < 0) {
+			ret = -1;
+			ERROR("failed to get flags, fd %d on %s", fd, path);
+		}
+
+		fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
+		if (flags < 0) {
+			ret = -1;
+			ERROR("failed to set CLOEXEC, fd %d on %s", fd, path);
+		}
 
 		snprintf(procpath, sizeof(procpath), "/proc/self/fd/%d", fd);
 
 		if (readlink(procpath, path, sizeof(path)) == -1)
 			ERROR("readlink(%s) failed : %m", procpath);
 		else
-			ERROR("inherited fd %d on %s", fd, path);
+			WARN("inherited fd %d on %s", fd, path);
 	}
 
 	if (closedir(dir))
-- 
1.7.6

Attachment: signature.asc
Description: OpenPGP digital signature

------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, 
user administration capabilities and model configuration. Take 
the hassle out of deploying and managing Subversion and the 
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
_______________________________________________
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel

Reply via email to