@cryptotaxi247 / netdata-1 / commits / 2a292a84a

post the first status when there is no last status (#19912)

Costa Tsaousis committed Mar 20, 2025 at 10:32 UTC 2a292a84a31b5c3bb8fb2c391526f80a9731884b
1 file changed +14 -5
src/daemon/daemon-status-file.c
+14 -5
@@ -859,6 +859,7 @@ static void remove_old_status_files(const char *protected_dir) {
859 errno_clear();
860 }
861
862 +static bool daemon_status_file_saved = false;
863 static void daemon_status_file_save(BUFFER *wb, DAEMON_STATUS_FILE *ds, bool log) {
864 // IMPORTANT: NO LOCKS OR ALLOCATIONS HERE, THIS FUNCTION IS CALLED FROM SIGNAL HANDLERS
865 // THIS FUNCTION MUST USE ONLY ASYNC-SIGNAL-SAFE OPERATIONS
@@ -899,6 +900,9 @@ static void daemon_status_file_save(BUFFER *wb, DAEMON_STATUS_FILE *ds, bool log
900
901 if (!saved && log)
902 nd_log(NDLS_DAEMON, NDLP_ERR, "Failed to save status file in any location");
903 +
904 + if (saved)
905 + daemon_status_file_saved = true;
906 }
907
908 // --------------------------------------------------------------------------------------------------------------------
@@ -1064,7 +1068,7 @@ void daemon_status_file_check_crash(void) {
1068
1069 bool new_version = strcmp(last_session_status.version, session_status.version) != 0;
1070 bool this_is_a_crash = false;
1067 - bool crash_report_ignore = false;
1071 + bool no_previous_status = false;
1072 bool dump_json = true;
1073 const char *msg = "", *cause = "";
1074 switch(last_session_status.status) {
@@ -1072,8 +1076,8 @@ void daemon_status_file_check_crash(void) {
1076 case DAEMON_STATUS_NONE:
1077 // probably a previous version of netdata was running
1078 cause = "no last status";
1075 - msg = "No status found for the previous Netdata session";
1076 - crash_report_ignore = true;
1079 + msg = "No status found for the previous Netdata session (new Netdata, or older version)";
1080 + no_previous_status = true;
1081 break;
1082
1083 case DAEMON_STATUS_EXITED:
@@ -1264,8 +1268,8 @@ void daemon_status_file_check_crash(void) {
1268 if( // must be first for netdata.conf option to be used
1269 (r == DSF_REPORT_ALL || (this_is_a_crash && r == DSF_REPORT_CRASHES)) &&
1270
1267 - // not a useful report (no previous status file)
1268 - !crash_report_ignore &&
1271 + // we have a previous status, or we managed to save the current one
1272 + (!no_previous_status || daemon_status_file_saved) &&
1273
1274 // we are not running in CI
1275 (last_session_status.restarts >= 10 || !is_ci()) &&
@@ -1276,6 +1280,11 @@ void daemon_status_file_check_crash(void) {
1280 ) {
1281 netdata_conf_ssl();
1282
1283 + if(no_previous_status) {
1284 + last_session_status = session_status;
1285 + strncpyz(last_session_status.fatal.function, "no_status", sizeof(last_session_status.fatal.function) - 1);
1286 + }
1287 +
1288 struct post_status_file_thread_data d = {
1289 .cause = cause,
1290 .msg = msg,