[CRIU] [PATCH 5/6] parasite: Don't assign error number on logfd
Cyrill Gorcunov
gorcunov at openvz.org
Tue Feb 14 08:42:00 EST 2012
In case if recv_fd failed we must not assign error
number as logfd, it's bloody wrong. Moreover, never
close descriptors which were not ever used or point
to standart descriptors.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
include/types.h | 1 +
parasite.c | 19 ++++++++++++++-----
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/include/types.h b/include/types.h
index b329630..4ae0c88 100644
--- a/include/types.h
+++ b/include/types.h
@@ -10,6 +10,7 @@
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
+#define STDFILENO_MAX 2
/* prctl */
#define ARCH_SET_GS 0x1001
diff --git a/parasite.c b/parasite.c
index edda844..3ec0f22 100644
--- a/parasite.c
+++ b/parasite.c
@@ -27,7 +27,7 @@ static void __parasite_data *brk_tail;
static struct page_entry __parasite_data page;
static struct vma_entry __parasite_data vma;
-static int __parasite_data logfd = -1;
+static int __parasite_data logfd = STDOUT_FILENO;
static int __parasite_data tsock = -1;
static unsigned char __parasite_data hex[] = "0123456789abcdef";
@@ -391,14 +391,23 @@ static int init(struct parasite_init_args *args)
static int set_logfd()
{
- logfd = recv_fd(tsock);
- return logfd;
+ int ret;
+
+ ret = recv_fd(tsock);
+ if (ret >= 0)
+ logfd = ret;
+
+ return ret;
}
static int fini()
{
- sys_close(logfd);
- sys_close(tsock);
+ if (logfd > STDFILENO_MAX)
+ sys_close(logfd);
+
+ if (tsock >= 0)
+ sys_close(tsock);
+
return 0;
}
--
1.7.7.6
More information about the CRIU
mailing list