Просмотр исходного кода

Fix random crash on agent shutdown (#14470)

Check MMAP failure. If fail to create semaphore, clear the shm_cgroup_ebpf.header to avoid crash during shutdown on thread cleanup
Stelios Fragkakis 2 лет назад
Родитель
Сommit
7f04867614
1 измененных файлов с 3 добавлено и 1 удалено
  1. 3 1
      collectors/cgroups.plugin/sys_fs_cgroup.c

+ 3 - 1
collectors/cgroups.plugin/sys_fs_cgroup.c

@@ -589,7 +589,8 @@ void netdata_cgroup_ebpf_initialize_shm()
                                                                        PROT_READ | PROT_WRITE, MAP_SHARED,
                                                                        shm_fd_cgroup_ebpf, 0);
 
-    if (!shm_cgroup_ebpf.header) {
+    if (unlikely(MAP_FAILED == shm_cgroup_ebpf.header)) {
+        shm_cgroup_ebpf.header = NULL;
         collector_error("Cannot map shared memory used between cgroup and eBPF, integration won't happen");
         goto end_init_shm;
     }
@@ -606,6 +607,7 @@ void netdata_cgroup_ebpf_initialize_shm()
 
     collector_error("Cannot create semaphore, integration between eBPF and cgroup won't happen");
     munmap(shm_cgroup_ebpf.header, length);
+    shm_cgroup_ebpf.header = NULL;
 
 end_init_shm:
     close(shm_fd_cgroup_ebpf);