summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCosta Tsaousis <costa@netdata.cloud>2024-01-12 15:56:54 +0200
committerGitHub <noreply@github.com>2024-01-12 15:56:54 +0200
commitcac1e1f30b832fb7000107ba82dfadcf509281ee (patch)
treee20d032fc8e5d1b9eddbcc397283a170781f802f
parentab576694f7acbaaa01023a49eb00af591660e051 (diff)
fix thread name on fatal and cgroup netdev rename crash (#16771)
* fix thread name on fatal * fix cgroup missing reference counter dup
-rw-r--r--collectors/cgroups.plugin/cgroup-top.c19
-rw-r--r--libnetdata/log/log.c11
2 files changed, 20 insertions, 10 deletions
diff --git a/collectors/cgroups.plugin/cgroup-top.c b/collectors/cgroups.plugin/cgroup-top.c
index aa158a0102..de794d8811 100644
--- a/collectors/cgroups.plugin/cgroup-top.c
+++ b/collectors/cgroups.plugin/cgroup-top.c
@@ -15,17 +15,17 @@ void cgroup_netdev_link_init(void) {
}
const DICTIONARY_ITEM *cgroup_netdev_get(struct cgroup *cg) {
- if(cg->cgroup_netdev_link)
- return cg->cgroup_netdev_link;
-
-
- struct cgroup_netdev_link t = {
+ if(!cg->cgroup_netdev_link) {
+ struct cgroup_netdev_link t = {
.read_slot = 0,
- .received = { NAN, NAN },
- .sent = { NAN, NAN },
- };
+ .received = {NAN, NAN},
+ .sent = {NAN, NAN},
+ };
+
+ cg->cgroup_netdev_link =
+ dictionary_set_and_acquire_item(cgroup_netdev_link_dict, cg->id, &t, sizeof(struct cgroup_netdev_link));
+ }
- cg->cgroup_netdev_link = dictionary_set_and_acquire_item(cgroup_netdev_link_dict, cg->id, &t, sizeof(struct cgroup_netdev_link));
return dictionary_acquired_item_dup(cgroup_netdev_link_dict, cg->cgroup_netdev_link);
}
@@ -34,6 +34,7 @@ void cgroup_netdev_delete(struct cgroup *cg) {
dictionary_acquired_item_release(cgroup_netdev_link_dict, cg->cgroup_netdev_link);
dictionary_del(cgroup_netdev_link_dict, cg->id);
dictionary_garbage_collect(cgroup_netdev_link_dict);
+ cg->cgroup_netdev_link = NULL;
}
}
diff --git a/libnetdata/log/log.c b/libnetdata/log/log.c
index b93ef2cc29..abc1207824 100644
--- a/libnetdata/log/log.c
+++ b/libnetdata/log/log.c
@@ -2305,7 +2305,16 @@ void netdata_logger_fatal( const char *file, const char *function, const unsigne
char action_data[70+1];
snprintfz(action_data, 70, "%04lu@%-10.10s:%-15.15s/%d", line, file, function, saved_errno);
- const char *thread_tag = thread_log_fields[NDF_THREAD_TAG].entry.txt;
+ char os_threadname[NETDATA_THREAD_NAME_MAX + 1];
+ const char *thread_tag = netdata_thread_tag();
+ if(!netdata_thread_tag_exists()) {
+ if (!netdata_thread_tag_exists()) {
+ os_thread_get_current_name_np(os_threadname);
+ if ('\0' != os_threadname[0])
+ /* If it is not an empty string replace "MAIN" thread_tag */
+ thread_tag = os_threadname;
+ }
+ }
if(!thread_tag)
thread_tag = "UNKNOWN";