@cryptotaxi247 / netdata-1 / commits / 60f8835d0

post status syncrhonously (#19766)

* fix printing null strings * post status file sync

Costa Tsaousis committed Mar 4, 2025 at 11:30 UTC 60f8835d08c0a636206a24c915f014a02a512d64
2 files changed +9 -13
src/daemon/analytics.c
+2 -1
@@ -932,7 +932,8 @@ void analytics_statistic_send(const analytics_statistic_t *statistic) {
932
933 nd_log(NDLS_DAEMON, NDLP_DEBUG,
934 "%s/anonymous-statistics.sh '%s' '%s' '%s'",
935 - netdata_configured_primary_plugins_dir, statistic->action, action_result, action_data);
935 + netdata_configured_primary_plugins_dir, statistic->action,
936 + action_result ? action_result : "", action_data ? action_data : "");
937
938 POPEN_INSTANCE *instance = spawn_popen_run(buffer_tostring(cmd));
939 if (instance) {
src/daemon/daemon-status-file.c
+7 -12
@@ -778,6 +778,7 @@ void post_status_file(struct post_status_file_thread_data *d) {
778 struct curl_slist *headers = NULL;
779 headers = curl_slist_append(headers, "Content-Type: application/json");
780 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
781 + curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L);
782
783 CURLcode rc = curl_easy_perform(curl);
784 if(rc == CURLE_OK) {
@@ -790,15 +791,6 @@ void post_status_file(struct post_status_file_thread_data *d) {
791 curl_slist_free_all(headers);
792 }
793
793 -void *post_status_file_thread(void *ptr) {
794 - struct post_status_file_thread_data *d = (struct post_status_file_thread_data *)ptr;
795 - post_status_file(d);
796 - freez((void *)d->cause);
797 - freez((void *)d->msg);
798 - freez(d);
799 - return NULL;
800 -}
801 -
794 // --------------------------------------------------------------------------------------------------------------------
795 // check last status on startup and post-crash report
796
@@ -1024,11 +1016,14 @@ void daemon_status_file_check_crash(void) {
1016 netdata_conf_ssl();
1017
1018 struct post_status_file_thread_data *d = calloc(1, sizeof(*d));
1027 - d->cause = strdupz(cause);
1028 - d->msg = strdupz(msg);
1019 + d->cause = cause;
1020 + d->msg = msg;
1021 d->status = &last_session_status;
1022 d->priority = pri.post;
1031 - nd_thread_create("post_status_file", NETDATA_THREAD_OPTION_DONT_LOG | NETDATA_THREAD_OPTION_DEFAULT, post_status_file_thread, d);
1023 + post_status_file(d);
1024 +
1025 + // MacOS crashes when starting under launchctl, when we create a thread to post the status file,
1026 + // so we post the status file synchronously, with a timeout of 10 seconds.
1027 }
1028 }
1029