lxcfs/0010-fix-hang.patch
2019-12-13 15:46:40 +08:00

49 lines
1.5 KiB
Diff

diff --git a/bindings.c b/bindings.c
index b921d7e..1023e7f 100644
--- a/bindings.c
+++ b/bindings.c
@@ -111,6 +111,7 @@ struct pidns_init_store {
static struct pidns_init_store *pidns_hash_table[PIDNS_HASH_SIZE];
static pthread_mutex_t pidns_store_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t slurp_file_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t diskstats_mutex = PTHREAD_MUTEX_INITIALIZER;
static void lock_mutex(pthread_mutex_t *l)
{
int ret;
@@ -4002,6 +4003,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[1] = fdopen(mypipe[1], "w");
if (stream[1] == NULL) {
@@ -4048,6 +4059,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[0], "%100s%d", dev_name, &dev_num) == 2) {
if (dev_num == 0) {
break;
@@ -4148,7 +4161,9 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
if (!f)
goto err;
+ lock_mutex(&diskstats_mutex);
container_devinfo = container_dev_read(initpid);
+ unlock_mutex(&diskstats_mutex);
while (getline(&line, &linelen, f) != -1) {
ssize_t l;