The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxcfs/pull/385
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === The sscanf() line got removed on accident. Closes #384. Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
From 157231ab2af99bfd94d345d1e6955e9b8de48d8e Mon Sep 17 00:00:00 2001 From: Christian Brauner <christian.brau...@ubuntu.com> Date: Tue, 24 Mar 2020 10:03:06 +0100 Subject: [PATCH] proc_fuse: fix swap calculations The sscanf() line got removed on accident. Closes #384. Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com> --- src/proc_fuse.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/proc_fuse.c b/src/proc_fuse.c index 4cec492..7851e03 100644 --- a/src/proc_fuse.c +++ b/src/proc_fuse.c @@ -1071,13 +1071,14 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset, if (ret >= 0) { memswlimit = get_min_memlimit(cgroup, true); memswlimit = memswlimit / 1024; + if (safe_uint64(memswusage_str, &memswusage, 10) < 0) lxcfs_error("Failed to convert memswusage %s", memswusage_str); memswusage = memswusage / 1024; } if (safe_uint64(memusage_str, &memusage, 10) < 0) - lxcfs_error("Failed to convert memusage %s", memswusage_str); + lxcfs_error("Failed to convert memusage %s", memusage_str); memlimit /= 1024; memusage /= 1024; @@ -1103,10 +1104,16 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset, snprintf(lbuf, 100, "MemAvailable: %8" PRIu64 " kB\n", memlimit - memusage + mstat.total_cache / 1024); printme = lbuf; } else if (startswith(line, "SwapTotal:") && memswlimit > 0 && opts && opts->swap_off == false) { - snprintf(lbuf, 100, "SwapTotal: %8" PRIu64 " kB\n", - (memswlimit >= memlimit) - ? (memswlimit - memlimit) - : 0); + uint64_t hostswtotal = 0; + + sscanf(line + STRLITERALLEN("SwapTotal:"), "%" PRIu64, &hostswtotal); + if (hostswtotal < memswlimit) + memswlimit = hostswtotal; + + if (memswlimit >= memlimit) + memswlimit -= memlimit; + + snprintf(lbuf, 100, "SwapTotal: %8" PRIu64 " kB\n", memswlimit); printme = lbuf; } else if (startswith(line, "SwapTotal:") && opts && opts->swap_off == true) { snprintf(lbuf, 100, "SwapTotal: %8" PRIu64 " kB\n", (uint64_t)0);
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel