[lxc-devel] [PATCH 2/2] lxc-start shouldn't exit with error, if there is inherited fd's.
Vladimir Smirnov
civil at yandex-team.ru
Wed Aug 24 10:17:50 UTC 2011
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 <civil at 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
More information about the lxc-devel
mailing list