]> git.proxmox.com Git - mirror_lxcfs.git/commitdiff
proc_fuse: fix swap calculations
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 24 Mar 2020 09:03:06 +0000 (10:03 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 24 Mar 2020 09:03:06 +0000 (10:03 +0100)
The sscanf() line got removed on accident.

Closes #384.
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/proc_fuse.c

index 4cec49279c6ebd327c698e650881a6aa33b193ff..7851e038daa944d02824a213bcc45b0042dea9d7 100644 (file)
@@ -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);