@cryptotaxi247 / netdata-1 / commits / 7f0486761

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 committed Feb 8, 2023 at 20:53 UTC 7f0486761408f5eae806671434751fae6de358dd
1 file changed +3 -1
collectors/cgroups.plugin/sys_fs_cgroup.c
+3 -1
@@ -589,7 +589,8 @@ void netdata_cgroup_ebpf_initialize_shm()
589 PROT_READ | PROT_WRITE, MAP_SHARED,
590 shm_fd_cgroup_ebpf, 0);
591
592 - if (!shm_cgroup_ebpf.header) {
592 + if (unlikely(MAP_FAILED == shm_cgroup_ebpf.header)) {
593 + shm_cgroup_ebpf.header = NULL;
594 collector_error("Cannot map shared memory used between cgroup and eBPF, integration won't happen");
595 goto end_init_shm;
596 }
@@ -606,6 +607,7 @@ void netdata_cgroup_ebpf_initialize_shm()
607
608 collector_error("Cannot create semaphore, integration between eBPF and cgroup won't happen");
609 munmap(shm_cgroup_ebpf.header, length);
610 + shm_cgroup_ebpf.header = NULL;
611
612 end_init_shm:
613 close(shm_fd_cgroup_ebpf);