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

yinhongbo on Github lxc-bot at linuxcontainers.org
Mon Aug 26 17:34:55 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 935 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190826/88e5cc09/attachment.bin>
-------------- next part --------------
From a4bd57aefbaa714d5a41dcacba9e97f00b0822b0 Mon Sep 17 00:00:00 2001
From: Hongbo Yin <yinhongbo at bytedance.com>
Date: Tue, 27 Aug 2019 01:33:04 +0800
Subject: [PATCH] fix container run pid host mode /proc/stat error log

Signed-off-by: Hongbo Yin <yinhongbo at bytedance.com>
---
 bindings.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/bindings.c b/bindings.c
index 014f400..89fe28d 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