[lxc-devel] [lxcfs/master] fix container run pid host mode /proc/stat error log

yinhongbo on Github lxc-bot at linuxcontainers.org
Mon Aug 19 09:11:38 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 880 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190819/e768abb6/attachment.bin>
-------------- next part --------------
From 714b2bd2f02d895d5223b0606c3278487342f779 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=B9=E6=B4=AA=E6=B3=A2?= <yinhongbo at bytedance.com>
Date: Mon, 19 Aug 2019 17:02:19 +0800
Subject: [PATCH] fix container run pid=host mode /proc/stat warnning log

---
 bindings.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/bindings.c b/bindings.c
index 014f400..7a1b6e1 100644
--- a/bindings.c
+++ b/bindings.c
@@ -4883,6 +4883,16 @@ static int proc_stat_read(char *buf, size_t size, off_t offset,
 	lxcfs_v("initpid: %d\n", initpid);
 	if (initpid <= 0)
 		initpid = fc->pid;
+
+    /*
+     * when container run with host pid namespace initpid == 1, cgroup will "/"
+     * we should return host os's /proc contents.
+     * in some case cpuacct_usage.all in "/" will larger then /proc/stat
+     */
+    if (initpid == 1) {
+        return read_file("/proc/stat", buf, size, d);
+    }
+
 	cg = get_pid_cgroup(initpid, "cpuset");
 	lxcfs_v("cg: %s\n", cg);
 	if (!cg)


More information about the lxc-devel mailing list