summaryrefslogtreecommitdiffstats
path: root/collectors/cgroups.plugin/sys_fs_cgroup.c
diff options
context:
space:
mode:
authorStelios Fragkakis <52996999+stelfrag@users.noreply.github.com>2023-02-08 20:53:43 +0200
committerGitHub <noreply@github.com>2023-02-08 20:53:43 +0200
commit7f0486761408f5eae806671434751fae6de358dd (patch)
tree1f9efaf091f01716e54c104566bf1557b4704181 /collectors/cgroups.plugin/sys_fs_cgroup.c
parent870ce8516b1272b03712d7417d444b10045cd105 (diff)
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
Diffstat (limited to 'collectors/cgroups.plugin/sys_fs_cgroup.c')
-rw-r--r--collectors/cgroups.plugin/sys_fs_cgroup.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/collectors/cgroups.plugin/sys_fs_cgroup.c b/collectors/cgroups.plugin/sys_fs_cgroup.c
index 66db0b7281..e63e042d09 100644
--- a/collectors/cgroups.plugin/sys_fs_cgroup.c
+++ b/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);