lxcfs/0008-fix-hang.patch

80 lines
2.0 KiB
Diff
Raw Normal View History

From 0025ea3988eefdf9a7a0eff5d55d2524c105c485 Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Thu, 25 Nov 2021 14:54:20 +0800
Subject: [PATCH 08/17] fix-hang
---
src/proc_fuse.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index 0aaab71..48c4e68 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -43,6 +43,26 @@
#include "proc_cpuview.h"
#include "utils.h"
+static pthread_mutex_t container_dev_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+static void lock_mutex(pthread_mutex_t *l)
+{
+ int ret;
+
+ ret = pthread_mutex_lock(l);
+ if (ret)
+ log_exit("%s - returned %d\n", strerror(ret), ret);
+}
+
+static void unlock_mutex(pthread_mutex_t *l)
+{
+ int ret;
+
+ ret = pthread_mutex_unlock(l);
+ if (ret)
+ log_exit("%s - returned %d\n", strerror(ret), ret);
+}
+
struct memory_stat {
uint64_t hierarchical_memory_limit;
uint64_t hierarchical_memsw_limit;
@@ -492,6 +512,16 @@ struct devinfo* container_dev_read(pid_t pid) {
return head;
}
if (child_pid == 0) {
+ /* Disallow signal reception in child process */
+ sigset_t oldset;
+ sigset_t newset;
+ sigemptyset(&newset);
+ sigaddset(&newset, SIGTERM);
+ sigaddset(&newset, SIGINT);
+ sigaddset(&newset, SIGHUP);
+ sigaddset(&newset, SIGQUIT);
+ sigprocmask(SIG_BLOCK,&newset,&oldset);
+
close(mypipe[0]);
stream = fdopen(mypipe[1], "w");
if (stream == NULL) {
@@ -538,6 +568,8 @@ child_out:
lxcfs_error("Error opening pipe for reading: %s\n", strerror(errno));
goto err;
}
+ wait_for_pid(child_pid);
+ child_pid = 0;
while (fscanf(stream, "%100s%d", dev_name, &dev_num) == 2) {
if (dev_num == 0) {
break;
@@ -681,7 +713,9 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
if (!f)
return 0;
+ lock_mutex(&container_dev_mutex);
container_devinfo = container_dev_read(initpid);
+ unlock_mutex(&container_dev_mutex);
while (getline(&line, &linelen, f) != -1) {
ssize_t l;
--
2.27.0