ef2d4d8159
Fix 'permission denied' errors trying to unlink disk images (bz #1289327) Fix qemu:///session connect race failures (bz #1271183) driver: log missing modules as INFO, not WARN (bz #1274849)
56 lines
1.8 KiB
Diff
56 lines
1.8 KiB
Diff
From: Cole Robinson <crobinso@redhat.com>
|
|
Date: Thu, 21 Jan 2016 13:14:54 -0500
|
|
Subject: [PATCH] lxc: fuse: Fix /proc/meminfo size calculation
|
|
|
|
We virtualize bits of /proc/meminfo by replacing host values with
|
|
values specific to the container.
|
|
|
|
However for calculating the final size of the returned data, we are
|
|
using the size of the original file and not the altered copy, which
|
|
could give garbelled output.
|
|
|
|
(cherry picked from commit 8418245a7e00f873594f1000c9606d08265088e0)
|
|
---
|
|
src/lxc/lxc_fuse.c | 13 +++++--------
|
|
1 file changed, 5 insertions(+), 8 deletions(-)
|
|
|
|
diff --git a/src/lxc/lxc_fuse.c b/src/lxc/lxc_fuse.c
|
|
index f9c02c0..e6369f8 100644
|
|
--- a/src/lxc/lxc_fuse.c
|
|
+++ b/src/lxc/lxc_fuse.c
|
|
@@ -131,7 +131,6 @@ static int lxcProcHostRead(char *path, char *buf, size_t size, off_t offset)
|
|
static int lxcProcReadMeminfo(char *hostpath, virDomainDefPtr def,
|
|
char *buf, size_t size, off_t offset)
|
|
{
|
|
- int copied = 0;
|
|
int res;
|
|
FILE *fd = NULL;
|
|
char *line = NULL;
|
|
@@ -159,7 +158,7 @@ static int lxcProcReadMeminfo(char *hostpath, virDomainDefPtr def,
|
|
}
|
|
|
|
res = -1;
|
|
- while (copied < size && getline(&line, &n, fd) > 0) {
|
|
+ while (getline(&line, &n, fd) > 0) {
|
|
char *ptr = strchr(line, ':');
|
|
if (!ptr)
|
|
continue;
|
|
@@ -219,13 +218,11 @@ static int lxcProcReadMeminfo(char *hostpath, virDomainDefPtr def,
|
|
res = -errno;
|
|
goto cleanup;
|
|
}
|
|
-
|
|
- copied += strlen(line);
|
|
- if (copied > size)
|
|
- copied = size;
|
|
}
|
|
- res = copied;
|
|
- memcpy(buf, virBufferCurrentContent(new_meminfo), copied);
|
|
+ res = strlen(virBufferCurrentContent(new_meminfo));
|
|
+ if (res > size)
|
|
+ res = size;
|
|
+ memcpy(buf, virBufferCurrentContent(new_meminfo), res);
|
|
|
|
cleanup:
|
|
VIR_FREE(line);
|