Fix the path to the host specific system configurations
[staging/basesystem.git] / service / system / system_manager / server / src / ss_system_manager_error_event_triggers.cpp
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup  tag_SystemManager
19 /// \brief    This file provides support for IAT error event logging.
20 ///
21 ///////////////////////////////////////////////////////////////////////////////
22 #include <system_service/ss_system_manager_notifications.h>
23 #include <native_service/frameworkunified_framework_if.h>
24 #include <native_service/frameworkunified_multithreading.h>
25 #include <system_service/ss_services.h>
26 #include <system_service/ss_client_names.h>
27 #include <system_service/ss_power_service_if.h>
28 #include <processlauncher/ProcessLauncher_if.h>
29 #include <processlauncher/ss_sm_process_launcher_protocol.h>
30 #include <processlauncher/ss_sm_process_launcher.h>
31 #include <heartbeat/ss_hb_if.h>
32 #include <system_service/ss_heartbeat_service_protocol.h>
33 #include <string.h>
34 #include <system_service/ss_power_service_notifications.h>
35 #include <system_service/ss_power_service_protocol.h>
36 #include <stub/ss_diag.h>
37 #include <system_service/ss_test_clients.h>
38 #include <native_service/ns_np_service_protocol.h>
39 #include <native_service/frameworkunified_application.h>
40 #include <system_service/ss_sm_thread_names.h>
41 #include <system_service/ss_templates.h>
42 #include <native_service/ns_plogger_if.h>
43 #include <native_service/frameworkunified_thread_priority.h>
44 #include <native_service/ns_np_service_nor_persistence.h>
45 #include <native_service/cl_process.h>
46 #include <stdlib.h>
47 #include <stdio.h>
48 #include <fcntl.h>
49 #include <dirent.h>
50 #include <sys/mman.h>
51 #include <sys/procfs.h>
52 #include <libgen.h>
53 #include <spawn.h>
54 #include <errno.h>
55 #include <sys/timeb.h>
56 #include <string>
57 #include "ss_system_manager.h"
58 #include "ss_sm_systemmanagerlog.h"
59 #include "ss_sm_signals.h"
60 #include "ss_sm_default_paths.h"
61 #include "ss_sm_version.h"
62
63 ///////////////////////////////////////////////////////////////////////////////
64 /// \ingroup OnHeartBeatErrorDetected
65 ///          This function gets called when a heartbeat failure is detected.
66 ///
67 /// \param [in] f_hApp
68 ///         HANDLE - Handle of the Client Application
69 ///
70 /// \return Status
71 ///         EFrameworkunifiedStatus - success or error
72 ///////////////////////////////////////////////////////////////////////////////
73 EFrameworkunifiedStatus CSystemManager::OnHeartBeatErrorDetected(HANDLE f_hApp) {
74   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
75   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
76   BOOL l_resetRequired;
77   EErrorEventResetType l_resetType;
78   SMLoggingInfo l_loggingInfo;
79   std::string l_moduleBinaryName;
80   UI_32 l_ix;
81   THbReportData l_HBReport;
82
83   INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
84
85   if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < THbReportData > (f_hApp, l_HBReport))) {
86     LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
87   } else {
88     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " Report contains : %d entries.", l_HBReport.nNumOfModules);
89
90     for (l_ix = 0; l_ix < l_HBReport.nNumOfModules; l_ix++) {
91       if (HB_STATUS_TIMEOUT == l_HBReport.tModuleList[l_ix].ProcHBState) {
92         std::string l_moduleQueueName = l_HBReport.tModuleList[l_ix].ProcQueueName;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
93
94         m_HBReport.eEntireState = l_HBReport.eEntireState;
95         m_HBReport.nNumOfModules = l_HBReport.nNumOfModules;
96         memcpy(&m_HBReport.tModuleList[l_ix], &l_HBReport.tModuleList[l_ix], sizeof(TSmModuleInfo));
97
98         TEXT(__FUNCTION__,  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
99              " ERROR EVENT: Heartbeat error detected from: %s.",  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
100              l_moduleQueueName.c_str());  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
101
102         l_eStatus = GetBinaryNameOfProcess(l_moduleQueueName, l_moduleBinaryName);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
103
104         if (eFrameworkunifiedStatusOK != l_eStatus) {
105           FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
106                  " Warning. Unable to identify binary name for SM child process with queue name: %s."
107                  " The process name will be missing from the .csv and the core file will not be archived.",
108                  l_moduleQueueName.c_str());
109         } else {
110           strncpy(l_loggingInfo.binaryFileName,
111                   l_moduleBinaryName.c_str(),
112                   sizeof(l_loggingInfo.binaryFileName) - 1);
113         }
114
115         if (eFrameworkunifiedStatusOK != (l_eStatus = ActOnModuleFailure(f_hApp, l_moduleQueueName, l_resetRequired))) {
116           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
117                  " Error. ActOnModuleFailure(%s,%d) errored: %d/'%s'",
118                  l_moduleQueueName.c_str(), l_resetRequired,
119                  l_eStatus, GetStr(l_eStatus).c_str());
120         }
121
122         l_resetType =
123             (FALSE == l_resetRequired) ?
124                 eErrorEventResetTypeNone :
125                 eErrorEventResetTypeHard;
126
127         if (eErrorEventResetTypeNone != l_resetType) {
128           l_loggingInfo.resetReason =
129               e_SS_SM_CPU_RESET_REASON_GENERIC_ERR;
130         }
131
132         l_eStatus = ErrorEventEnqueue(f_hApp,
133             eErrorEventTypeHeartBeatFailure, l_moduleQueueName,
134             l_resetType, l_loggingInfo);
135
136         LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
137             "ErrorEventEnqueue(eErrorEventTypeHeartBeatFailure)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
138       }
139     }
140   }
141
142   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
143   return (l_eStatus);
144 }
145
146 ///////////////////////////////////////////////////////////////////////////////
147 /// \ingroup OnProcessTermDetected
148 ///
149 ///
150 ///
151 /// \param Handle to AGL application.
152 ///
153 /// \return EFrameworkunifiedStatus
154 /// Success ==> eFrameworkunifiedStatusOK
155 /// Failure ==> Other values
156 ///////////////////////////////////////////////////////////////////////////////
157 EFrameworkunifiedStatus CSystemManager::OnProcessTermDetected(HANDLE f_hApp) {
158   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
159   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
160   int l_clRet;
161   int l_count = 0;
162
163   // When multiple child processes terminate, CL_ProcessCleanup() returns 1. If 1 is returned, it repeats.
164   do {
165     CL_ProcessCleanupInfo_t l_procInfo;
166
167     l_count++;
168
169     l_clRet = CL_ProcessCleanup(m_ClProcessSigFd, &l_procInfo);
170     if (l_clRet != 0 && l_clRet != 1) {
171       FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
172           " Warning: CL_ProcessCleanup(%d):%s", l_clRet,
173           strerror(errno));
174       l_eStatus = eFrameworkunifiedStatusFail;
175       break;
176     }
177
178     FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "PID:%d code:%d status:%d",
179         l_procInfo.pid, l_procInfo.code, l_procInfo.status);
180
181     // Terminate a process group to reclaim descendants of an anomaly terminated process
182     SS_ASERT_ERRNO(0 == CL_ProcessAbortGroup(l_procInfo.pid));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
183
184     BOOL bIsExited = (CLD_EXITED == l_procInfo.code) ? TRUE : FALSE;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
185     SMProcessExitInfo l_procExitInfo;
186     memset(&l_procExitInfo, 0, sizeof(l_procExitInfo));
187     l_procExitInfo.pid = l_procInfo.pid;
188     // Process exit value when si_code == CLD_EXITED, else delivered signal number.
189     l_procExitInfo.exitValue = l_procInfo.status;
190     l_procExitInfo.signalNumber = SS_SM_ABORT_SIGNAL;
191
192     // If GroupRelaunch is required, kill the remaining services
193     SS_String l_moduleQueueName("");
194     if (eFrameworkunifiedStatusOK == FindNameOfTerminatedProcess(l_procExitInfo.pid, l_moduleQueueName)) {
195       for (GroupRelaunchModuleListIter l_itr =
196           m_GroupRelaunchModuleList.begin();
197           m_GroupRelaunchModuleList.end() != l_itr; l_itr++) {
198         if (l_itr->name == l_moduleQueueName) {
199           if (l_itr->bIsKilled) {  // LCOV_EXCL_BR_LINE 200: relaunch module bIsKilled is always false
200             // LCOV_EXCL_START 200: relaunch module bIsKilled is always false
201             AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
202             // Normal during forced Relaunch
203             l_procExitInfo.exitValue = SS_SM_EXIT_RELAUNCH;
204             bIsExited = TRUE;
205             l_itr->bIsKilled = FALSE;
206             // LCOV_EXCL_STOP
207           } else {
208             FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "GroupRelaunch(%d/%d)",
209                 m_GroupRelaunchCount, m_GroupRelaunchLimit);
210
211             if (m_GroupRelaunchCount < m_GroupRelaunchLimit) {
212               SS_ASERT(  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
213                   FrameworkunifiedNPPublishNotification(f_hApp,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
214                       NTFY_SSNeedAplRestart, NULL, 0));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
215
216               // Issue ErrorEvent
217               SMLoggingInfo l_loggingInfo;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
218               SS_String l_moduleBinaryName("");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
219
220               l_loggingInfo.pid = l_procExitInfo.pid;
221               l_loggingInfo.exitValue = l_procExitInfo.exitValue;
222               l_loggingInfo.signalNumber = SS_SM_ABORT_SIGNAL;
223               if (eFrameworkunifiedStatusOK != GetBinaryNameOfProcess(l_moduleQueueName, l_moduleBinaryName)) {  // LCOV_EXCL_BR_LINE 200: cannot be error
224                 AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
225                 SS_ASERT(0);  // LCOV_EXCL_LINE 200: cannot be error
226               } else {
227                 snprintf(l_loggingInfo.binaryFileName,
228                     sizeof(l_loggingInfo.binaryFileName),
229                     "%s", l_moduleBinaryName.c_str());
230               }
231
232               l_eStatus = ErrorEventEnqueue(f_hApp,
233                   eErrorEventTypeGroupRelaunch, l_itr->name,
234                   eErrorEventResetTypeNone, l_loggingInfo);
235               LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
236                   "ErrorEventEnqueue()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
237
238               // Relaunch normally and do not leave anomaly LOGs
239               l_procExitInfo.exitValue = SS_SM_EXIT_RELAUNCH;
240               bIsExited = TRUE;
241
242               for (GroupRelaunchModuleListIter l_itr =
243                   m_GroupRelaunchModuleList.begin();
244                   m_GroupRelaunchModuleList.end() != l_itr;
245                   l_itr++) {
246                 if (l_itr->name != l_moduleQueueName) {  // LCOV_EXCL_BR_LINE 200: name always be equal because of outer if judge  // NOLINT(whitespace/line_length)
247                   // LCOV_EXCL_START 200: name always be equal
248                   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
249                   ModuleLaunchListIter l_ModuleListIter;
250                   if (eFrameworkunifiedStatusOK
251                       != GetModuleIterator(
252                           l_itr->name.c_str(),
253                           l_ModuleListIter)) {
254                     SS_ASERT(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
255                   } else {
256                     killpg(l_ModuleListIter->pid,
257                         SS_SM_TERMINATE_SIGNAL);
258                     l_itr->bIsKilled = TRUE;
259                   }
260                   // LCOV_EXCL_STOP
261                 }
262               }
263
264               m_GroupRelaunchCount++;
265             } else {
266               // Reboot system
267               ModuleLaunchListIter l_ModuleListIter;
268               if (eFrameworkunifiedStatusOK == GetModuleIterator(l_moduleQueueName.c_str(), l_ModuleListIter)) {  // LCOV_EXCL_BR_LINE 200:cannot be error   // NOLINT(whitespace/line_length)
269                 l_ModuleListIter->relaunch_count = l_ModuleListIter->retry_cnt;
270               } else {
271                 AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
272                 SS_ASERT(0);  // LCOV_EXCL_LINE 200: cannot be error
273               }
274             }
275             break;
276           }
277         }
278       }
279     }
280
281     if (isPreLaunchedProcess(l_procExitInfo.pid)) {  // LCOV_EXCL_BR_LINE 200:prelaunch mode is not valid at UT test //NOLINT (whitespace/line_length)
282       // LCOV_EXCL_START 200 :prelaunch mode is not valid at UT test
283       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
284       l_eStatus = OnPreLaunchedProcessTermDetected(f_hApp, l_procExitInfo, bIsExited);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
285       if (eFrameworkunifiedStatusOK != l_eStatus) {
286         LOG_ERROR("OnPreLaunchedProcessTermDetected()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
287         l_eStatus = eFrameworkunifiedStatusFail;
288         // If an error occurs here, the zombie process may be collected and continued.
289       }
290       // LCOV_EXCL_STOP
291     } else if (bIsExited) {
292       l_eStatus = OnProcessExitDetected(f_hApp, l_procExitInfo);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
293       if (eFrameworkunifiedStatusOK != l_eStatus) {
294         LOG_ERROR("OnProcessExitDetected()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
295         l_eStatus = eFrameworkunifiedStatusFail;
296         // If an error occurs here, the zombie process may be collected and continued.
297       }
298     } else {
299       l_eStatus = OnProcessCrashDetected(f_hApp, l_procExitInfo);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
300       if (eFrameworkunifiedStatusOK != l_eStatus) {
301         LOG_ERROR("OnProcessCrashDetected()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
302         l_eStatus = eFrameworkunifiedStatusFail;
303         // If an error occurs here, the zombie process may be collected and continued.
304       }
305     }
306   } while (l_clRet == 1 && l_count < 50);
307
308   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
309   return (l_eStatus);
310 }
311
312 BOOL CSystemManager::isPreLaunchedProcess(int f_pid) {
313   BOOL l_bIsExist = FALSE;
314
315   PreLaunchModuleListIter l_itr;
316   for (l_itr = m_PreLaunchModuleList.begin();
317       m_PreLaunchModuleList.end() != l_itr; l_itr++) {
318     if (l_itr->pid == f_pid) {    // LCOV_EXCL_BR_LINE 200:prelaunch mode is not valid at UT test //NOLINT (whitespace/line_length)
319       // LCOV_EXCL_START 200 :prelaunch mode is not valid at UT test
320       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
321       l_bIsExist = TRUE;
322       break;
323       // LCOV_EXCL_STOP
324     }
325   }
326   return l_bIsExist;
327 }
328
329 EFrameworkunifiedStatus CSystemManager::OnPreLaunchedProcessTermDetected(HANDLE f_hApp, SMProcessExitInfo &f_procExitInfo, BOOL f_bIsExited) {  // LCOV_EXCL_START 200 :prelaunch mode is not valid at UT test  // NOLINT(whitespace/line_length)
330   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
331   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
332
333   PreLaunchModuleListIter l_itr;
334   for (l_itr = m_PreLaunchModuleList.begin();
335       m_PreLaunchModuleList.end() != l_itr; l_itr++) {
336     if (l_itr->pid == static_cast<int>(f_procExitInfo.pid)) {
337       break;
338     }
339   }
340
341   try {
342     if (m_PreLaunchModuleList.end() == l_itr) {
343       SS_ASERT(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
344       throw eFrameworkunifiedStatusFail;
345     }
346
347     BOOL l_bIsNeedRelaunched = FALSE;
348
349     if ((SS_SM_RELAUNCH_NO_LIMIT == l_itr->relaunchLimit)
350         || (l_itr->relaunchLimit > l_itr->relaunchCount)) {
351       l_itr->relaunchCount++;
352       FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "Relaunch %s(%d/%d)",
353           l_itr->name.c_str(), l_itr->relaunchCount,
354           l_itr->relaunchLimit);
355       if (-1 == (l_itr->pid = l_itr->LaunchFunc())) {
356         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Relaunch %s Failed",
357             l_itr->name.c_str());
358       } else {
359         l_bIsNeedRelaunched = TRUE;
360       }
361     }
362
363     if (!l_bIsNeedRelaunched) {
364       if (l_itr->critical) {
365         SMLoggingInfo l_loggingInfo;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
366         EErrorEventType l_ErrorType;
367
368         l_itr->pid = -1;
369
370         l_loggingInfo.pid = f_procExitInfo.pid;
371         l_loggingInfo.exitValue = f_procExitInfo.exitValue;
372         l_loggingInfo.signalNumber = f_procExitInfo.signalNumber;
373         l_loggingInfo.resetReason =
374             e_SS_SM_CPU_RESET_REASON_GENERIC_ERR;
375         snprintf(l_loggingInfo.binaryFileName,
376             sizeof(l_loggingInfo.binaryFileName), "%s",
377             l_itr->binaryFileName.c_str());
378
379         if (f_bIsExited) {
380           FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "%s exited",
381               l_itr->name.c_str());
382           l_ErrorType = eErrorEventTypeProcessExit;
383         } else {
384           FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "%s crashed",
385               l_itr->name.c_str());
386           l_ErrorType = eErrorEventTypeProcessCrash;
387         }
388
389         l_eStatus = ErrorEventEnqueue(f_hApp, l_ErrorType, l_itr->name,
390             eErrorEventResetTypeHard, l_loggingInfo);
391         LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "ErrorEventEnqueue()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
392       } else {
393         FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "%s removed",
394             l_itr->name.c_str());
395         l_itr->pid = -1;
396       }
397     }
398   } catch (EFrameworkunifiedStatus e) {
399     l_eStatus = e;
400   }
401
402   return l_eStatus;
403 }
404 // LCOV_EXCL_STOP
405
406 ///////////////////////////////////////////////////////////////////////////////
407 /// \ingroup OnProcessCrashDetected
408 /// Initiate logging and recovery for an abnormal process termination.
409 /// The terminated process may or may not be a child of system manager.
410 /// If the process is a child of SM, then a validation check must ensue
411 /// to ensure that the process crash is not the result of a failed heartbeat
412 /// and subsequent termination signal sent from System Manager. This function
413 /// is NOT called for processes that exit normally.
414 ///
415 /// See OnProcessCrashDetected.
416 ///
417 /// \param Handle to AGL application.
418 ///
419 /// \return EFrameworkunifiedStatus
420 /// Success ==> eFrameworkunifiedStatusOK
421 /// Failure ==> Other values
422 ///////////////////////////////////////////////////////////////////////////////
423 EFrameworkunifiedStatus CSystemManager::OnProcessCrashDetected(HANDLE f_hApp,
424         SMProcessExitInfo &f_procExitInfo) {
425   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
426   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
427   BOOL l_resetRequired = TRUE;
428   SS_String l_moduleQueueName("");
429   SS_String l_moduleBinaryName("");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
430   EErrorEventResetType l_resetType;
431
432   INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
433
434   TEXT(__FUNCTION__, " PROCESS CRASH: Process PID: %d", f_procExitInfo.pid);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
435
436   if (eFrameworkunifiedStatusOK
437       != (l_eStatus = FindNameOfTerminatedProcess(f_procExitInfo.pid, l_moduleQueueName))) {
438     // Normally, logging COULD continue, but stopping logging also solves a PosixBasedOS001 errata
439     // where a process crashes and is removed from the SM process launch map and is ALSO
440     // detected by the exit detector as a 'normal' exit. The FindNameOfTerminatedProcess()
441     // will continue properly IF a crash and removal from the map has not occurred
442     // for the same process.
443     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
444         " Error. FindNameOfTerminatedProcess() returned error: %d/'%s' for PID: %d."
445             " No recovery possible. Logging has been suspended for this event.",
446         l_eStatus, GetStr(l_eStatus).c_str(), f_procExitInfo.pid);
447   } else {
448     l_eStatus = GetBinaryNameOfProcess(l_moduleQueueName, l_moduleBinaryName);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
449     if (eFrameworkunifiedStatusOK != l_eStatus) {  // LCOV_EXCL_BR_LINE 200: cannot be error
450       // LCOV_EXCL_START 200: cannot be error
451       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
452       FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
453           " Warning. Unable to identify binary for SM child process PID: %d, Queue Name: %s."
454               " The process binary name will be missing from the .csv file.",
455           f_procExitInfo.pid, l_moduleQueueName.c_str());
456       // LCOV_EXCL_STOP
457     } else {
458       strncpy(f_procExitInfo.binaryFileName, l_moduleBinaryName.c_str(),
459           sizeof(f_procExitInfo.binaryFileName) - 1);
460
461       f_procExitInfo.binaryFileName[sizeof(f_procExitInfo.binaryFileName) - 1] = '\0';
462     }
463
464     if (eFrameworkunifiedStatusOK
465         != (l_eStatus = ActOnModuleFailure(f_hApp, l_moduleQueueName,
466             l_resetRequired))) {
467       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
468           " Error. ActOnModuleFailure(%s,%d) errored: %d/'%s'",
469           l_moduleQueueName.c_str(), l_resetRequired, l_eStatus,
470           GetStr(l_eStatus).c_str());
471     } else {
472       FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__,
473           "Info. ActOnModuleFailure() returned reset status: %d/'%s'.",
474           l_resetRequired, GetStr(l_resetRequired).c_str());
475     }
476
477     l_resetType =
478         (FALSE == l_resetRequired) ?
479             eErrorEventResetTypeNone : eErrorEventResetTypeHard;
480
481     SMLoggingInfo l_loggingInfo;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
482
483     l_loggingInfo.pid = f_procExitInfo.pid;
484     l_loggingInfo.exitValue = f_procExitInfo.exitValue;
485     l_loggingInfo.signalNumber = f_procExitInfo.signalNumber;
486     snprintf(l_loggingInfo.binaryFileName,
487         sizeof(l_loggingInfo.binaryFileName), "%s",
488         f_procExitInfo.binaryFileName);
489     if (eErrorEventResetTypeNone != l_resetType) {
490       l_loggingInfo.resetReason = e_SS_SM_CPU_RESET_REASON_GENERIC_ERR;
491     }
492
493     l_eStatus = ErrorEventEnqueue(f_hApp, eErrorEventTypeProcessCrash,
494         l_moduleQueueName, l_resetType, l_loggingInfo);
495
496     LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
497         "ErrorEventEnqueue(eErrorEventTypeProcessCrash)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
498   }
499
500   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
501   return (l_eStatus);
502 }
503
504 ///////////////////////////////////////////////////////////////////////////////
505 /// \ingroup OnProcessExitDetected
506 /// Initiate logging and recovery for System Manager child processes that
507 /// exit normally via the last brace of main(), exit(), or have their last
508 /// thread exit. This function is NOT called for processes that terminate
509 /// unexpectedly.
510 ///
511 /// See OnProcessExitDetected.
512 ///
513 /// \param Handle to AGL application.
514 ///
515 /// \return EFrameworkunifiedStatus
516 /// Success ==> eFrameworkunifiedStatusOK
517 /// Failure ==> Other values
518 ///////////////////////////////////////////////////////////////////////////////
519 EFrameworkunifiedStatus CSystemManager::OnProcessExitDetected(HANDLE f_hApp,
520         SMProcessExitInfo &f_procExitInfo) {
521   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
522   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
523   SS_String l_moduleQueueName("");
524
525   INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
526
527   TEXT(__FUNCTION__, "PROCESS EXIT: PID:%d exitValue:%d", f_procExitInfo.pid,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
528       f_procExitInfo.exitValue);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
529
530   if (eFrameworkunifiedStatusOK
531       != (l_eStatus = FindNameOfTerminatedProcess(f_procExitInfo.pid,
532           l_moduleQueueName))) {
533      // This happens when SMs to EXEC debugging commands, etc.
534      // Since this is not an error, set LOGs to WARN levels and set the return codes to OK.
535     FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__, "%s: pid:%d is unknown service",
536         GetStr(l_eStatus).c_str(), f_procExitInfo.pid);
537     l_eStatus = eFrameworkunifiedStatusOK;
538   } else {
539     if (0 == f_procExitInfo.exitValue) {
540       ModuleLaunchListIter l_moduleListIter;
541
542       if (eFrameworkunifiedStatusOK != (l_eStatus = RemoveModuleEntryFromHB(f_hApp, l_moduleQueueName.c_str()))) {  // LCOV_EXCL_BR_LINE 4: NSFW  // NOLINT(whitespace/line_length)
543         // LCOV_EXCL_START 4: NSFW
544         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
545         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
546             " Error: RemoveModuleEntryFromHB(%s) errored: %d/'%s'",
547             l_moduleQueueName.c_str(), l_eStatus,
548             GetStr(l_eStatus).c_str());
549         // LCOV_EXCL_STOP
550       }
551
552       l_eStatus = GetModuleIterator(l_moduleQueueName.c_str(),
553           l_moduleListIter);
554       if (eFrameworkunifiedStatusOK != l_eStatus) {  // LCOV_EXCL_BR_LINE 200:cannot be error
555         // LCOV_EXCL_START 200:cannot be error
556         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
557         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
558             " Error: Module %s not found in Group Launch Map",
559             l_moduleQueueName.c_str());
560         // LCOV_EXCL_STOP
561       } else {
562         l_eStatus = SendRequestToLauncher(f_hApp, l_moduleListIter,  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
563             ePLThrdCmd_TERMINATE_MODULE_REQST,  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
564             "ePLThrdCmd_TERMINATE_MODULE_REQST");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
565
566         LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
567             "SendRequestToLauncher()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
568
569         // Do not add relaunch_count for normal termination.
570         l_moduleListIter->relaunch_status = RelaunchSafe;
571       }
572     } else if (SS_SM_EXIT_RELAUNCH == f_procExitInfo.exitValue) {
573       ModuleLaunchListIter l_moduleListIter;
574
575       if (eFrameworkunifiedStatusOK != (l_eStatus = RemoveModuleEntryFromHB(f_hApp, l_moduleQueueName.c_str()))) {  // LCOV_EXCL_BR_LINE 4: nsfw error  // NOLINT(whitespace/line_length)
576         // LCOV_EXCL_START 4: nsfw error
577         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
578         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
579             " Error: RemoveModuleEntryFromHB(%s) errored: %d/'%s'",
580             l_moduleQueueName.c_str(), l_eStatus,
581             GetStr(l_eStatus).c_str());
582         // LCOV_EXCL_STOP
583       }
584
585       l_eStatus = GetModuleIterator(l_moduleQueueName.c_str(),
586           l_moduleListIter);
587       if (eFrameworkunifiedStatusOK != l_eStatus) {  // LCOV_EXCL_BR_LINE 200:cannot be error
588         // LCOV_EXCL_START 200:cannot be error
589         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
590         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
591             " Error: Module %s not found in Group Launch Map",
592             l_moduleQueueName.c_str());
593         // LCOV_EXCL_STOP
594       } else {
595         l_eStatus = SendRequestToLauncher(f_hApp, l_moduleListIter,  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
596             ePLThrdCmd_RELAUNCH_MODULE_REQST,  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
597             "ePLThrdCmd_RELAUNCH_MODULE_REQST");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
598
599         LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
600             "SendRequestToLauncher()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
601
602         // Do not add relaunch_count for normal Relaunch
603         l_moduleListIter->relaunch_status = RelaunchSafe;
604       }
605     } else {
606       SS_String l_moduleBinaryName("");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
607       BOOL l_resetRequired = TRUE;
608       EErrorEventResetType l_resetType;
609
610       l_eStatus = GetBinaryNameOfProcess(l_moduleQueueName, l_moduleBinaryName);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
611       if (eFrameworkunifiedStatusOK != l_eStatus) {  // LCOV_EXCL_BR_LINE 200: cannot be error
612         // LCOV_EXCL_START 200: cannot be error
613         AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
614         FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
615             " Warning. Unable to identify binary for SM child process PID: %d, Queue Name: %s."
616                 " The process binary name will be missing from the .csv file.",
617             f_procExitInfo.pid, l_moduleQueueName.c_str());
618         // LCOV_EXCL_STOP
619       } else {
620         strncpy(f_procExitInfo.binaryFileName,
621             l_moduleBinaryName.c_str(),
622             sizeof(f_procExitInfo.binaryFileName) - 1);
623
624         f_procExitInfo.binaryFileName[sizeof(f_procExitInfo.binaryFileName)
625             - 1] = '\0';
626       }
627
628       if (eFrameworkunifiedStatusOK
629           != (l_eStatus = ActOnModuleFailure(f_hApp,
630               l_moduleQueueName, l_resetRequired))) {
631         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
632             " Error. ActOnModuleFailure(%s,%d) errored: %d/'%s'",
633             l_moduleQueueName.c_str(), l_resetRequired, l_eStatus,
634             GetStr(l_eStatus).c_str());
635       }
636
637       l_resetType =
638           (FALSE == l_resetRequired) ?
639               eErrorEventResetTypeNone : eErrorEventResetTypeHard;
640
641       SMLoggingInfo l_loggingInfo;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
642
643       l_loggingInfo.pid = f_procExitInfo.pid;
644       l_loggingInfo.exitValue = f_procExitInfo.exitValue;
645       l_loggingInfo.signalNumber = f_procExitInfo.signalNumber;
646       snprintf(l_loggingInfo.binaryFileName,
647           sizeof(l_loggingInfo.binaryFileName), "%s",
648           f_procExitInfo.binaryFileName);
649       if (eErrorEventResetTypeNone != l_resetType) {
650         l_loggingInfo.resetReason = e_SS_SM_CPU_RESET_REASON_GENERIC_ERR;
651       }
652
653       l_eStatus = ErrorEventEnqueue(f_hApp, eErrorEventTypeProcessExit,
654           l_moduleQueueName, l_resetType, l_loggingInfo);
655       LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
656           "ErrorEventEnqueue(eErrorEventTypeProcessExit)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
657     }
658   }
659
660   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
661   return (l_eStatus);
662 }
663
664 ///////////////////////////////////////////////////////////////////////////////
665 /// \ingroup OnBootMicroResetNotification
666 /// Called from the logging shadow when the boot micro notifies the shadow of
667 /// an unexpected boot micro reset during the last power cycle.
668 ///
669 /// \param [in] hApp - Application handle.
670 ///
671 /// \return EFrameworkunifiedStatus
672 /// Success ==> eFrameworkunifiedStatusOK
673 /// Failure ==> Other values
674 ///////////////////////////////////////////////////////////////////////////////
675 EFrameworkunifiedStatus CSystemManager::OnBootMicroResetNotification(HANDLE hApp) {
676   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
677   std::string l_moduleName;
678   EFrameworkunifiedStatus l_eStatus;
679
680   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
681
682   if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < eSMBootMicroResetReason > (hApp, m_BootMicroResetReason))) {
683     LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
684   } else {
685     l_moduleName = FrameworkunifiedGetMsgSrc(hApp);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
686
687     TEXT(__FUNCTION__,  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
688         " ERROR EVENT: A boot micro reset has occurred. Reset reason: %d/'%s'.",  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
689         m_BootMicroResetReason, GetStr(m_BootMicroResetReason).c_str());  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
690
691     l_eStatus = ErrorEventEnqueue(hApp, eErrorEventTypeBootMicroReset, l_moduleName);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
692
693     LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
694         "ErrorEventEnqueue(eErrorEventTypeBootMicroReset)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
695   }
696
697   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
698   return (l_eStatus);
699 }
700
701 ///////////////////////////////////////////////////////////////////////////////
702 /// \ingroup RequestBootMicroLog
703 /// Request boot micro log from the logging shadow.
704 ///
705 /// \param [in] hApp - Application handle.
706 ///
707 /// \return EFrameworkunifiedStatus
708 /// Success ==> eFrameworkunifiedStatusOK
709 /// Failure ==> Other values
710 ///////////////////////////////////////////////////////////////////////////////
711 EFrameworkunifiedStatus CSystemManager::RequestBootMicroLog(HANDLE hApp) {
712   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
713   EFrameworkunifiedStatus l_eStatus;
714
715   l_eStatus = FrameworkunifiedPublishEvent(hApp,   // Event received by PS Logging Shadow
716       SS_SM_BOOT_MICRO_LOG_REQ,
717       NULL,
718       NULL, 0);
719
720   LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
721       "FrameworkunifiedPublishEvent(SS_SM_BOOT_MICRO_LOG_REQ)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
722
723   bool result =
724       m_errorEventTimers[eSM_ERROR_EVENT_TIMER_BOOT_MICRO_LOG_RSPN].Start(
725           SS_ERROR_EVENT_BOOT_MICRO_LOG_RESPONSE_TO_SEC, 0, 0, 0);
726   if (FALSE == result) {
727     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
728         " Error. Failed to start timer eSM_TIMER_BOOT_MICRO_LOG_RESPONSE.");
729   }
730
731   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
732   return (l_eStatus);
733 }
734
735 ///////////////////////////////////////////////////////////////////////////////
736 /// \ingroup OnLowSystemMemory
737 /// Called when a low memory error has been detected.
738 ///
739 /// \param [in] hApp - Application handle.
740 ///
741 /// \return EFrameworkunifiedStatus
742 /// Success ==> eFrameworkunifiedStatusOK
743 /// Failure ==> Other values
744 ///////////////////////////////////////////////////////////////////////////////
745 EFrameworkunifiedStatus CSystemManager::OnLowSystemMemory(HANDLE hApp) {
746   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
747   SysMem l_SysMem;
748   std::string l_moduleName;
749   EFrameworkunifiedStatus l_eStatus;
750   SMLoggingInfo l_loggingInfo;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
751
752   if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < SysMem > (hApp, l_SysMem))) {
753     LOG_ERROR("ReadMsg()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
754   } else {
755     m_FreeMemAvailable = l_SysMem.FreeMemoryBytes;
756
757     TEXT(__FUNCTION__,  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
758         " ERROR EVENT: System Low Memory detected. Remaining memory: %d.",  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
759         m_FreeMemAvailable);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
760
761     l_moduleName = FrameworkunifiedGetMsgSrc(hApp);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
762     l_loggingInfo.resetReason = e_SS_SM_CPU_RESET_REASON_GENERIC_ERR;
763     l_eStatus = ErrorEventEnqueue(hApp, eErrorEventTypeSystemLowMemory,
764         l_moduleName, eErrorEventResetTypeHard, l_loggingInfo);
765
766     LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
767         "ErrorEventEnqueue(eErrorEventTypeSystemLowMemory)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
768   }
769
770   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
771   return l_eStatus;
772 }  // End of EFrameworkunifiedStatus CSystemManager::OnLowSystemMemory( HANDLE hApp )
773
774 EFrameworkunifiedStatus CSystemManager::OnPropagateSystemError(HANDLE hApp) {
775   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
776   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
777
778   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
779
780   SS_ASERT(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
781
782   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
783   return (l_eStatus);
784 }
785
786 ///////////////////////////////////////////////////////////////////////////////
787 /// \ingroup OnUserInvokedLoggingRequest
788 /// Called when the end user invokes a error event logging request by means
789 /// of hard key or other direct input method.
790 ///
791 /// \param [in] hApp - Application handle.
792 ///
793 /// \return EFrameworkunifiedStatus
794 /// Success ==> eFrameworkunifiedStatusOK
795 /// Failure ==> Other values
796 ///////////////////////////////////////////////////////////////////////////////
797 EFrameworkunifiedStatus CSystemManager::OnUserInvokedLoggingRequest(HANDLE f_hApp) {
798   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
799   TSystemManagerLoggingRequestInfo l_logInfo;
800   EErrorEventType l_errorEventType;
801   std::string l_moduleName;
802   EFrameworkunifiedStatus l_eStatus;
803   SMLoggingInfo l_loggingInfo;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
804
805   if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg < TSystemManagerLoggingRequestInfo > (f_hApp, l_logInfo))) {  // LCOV_EXCL_BR_LINE 4: NSFW error case  // NOLINT(whitespace/line_length)
806     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
807     LOG_ERROR("ReadMsg()");  // LCOV_EXCL_LINE 4: NSFW error case
808   } else {
809     l_moduleName = FrameworkunifiedGetMsgSrc(f_hApp);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
810     l_loggingInfo.messageStr = l_logInfo.messageStr;
811     l_loggingInfo.suffixStr = l_logInfo.suffixStr;
812
813     switch (l_logInfo.logType) {
814     case e_SS_SM_CAPTURE_ALL_LOGS:
815       l_errorEventType = eErrorEventTypeUserInvokedCollectAllLogs;
816       break;
817
818     case e_SS_SM_SCREEN_CAPTURE:
819       l_errorEventType = eErrorEventTypeUserInvokedCollectScreenShot;
820       break;
821
822     case e_SS_SM_CAPTURE_INTERFACEUNIFIED_LOGS:
823       l_errorEventType = eErrorEventTypeUserInvokedCollectInterfaceunifiedLogs;
824       break;
825
826     case e_SS_SM_CAPTURE_DEV_LOGS:
827       l_errorEventType = eErrorEventTypeUserInvokedCollectDevLogs;
828       break;
829
830     case e_SS_SM_CAPTURE_MODULE_LOGS:
831       l_errorEventType = eErrorEventTypeModuleInvokedCollectDebugLogs;
832       break;
833
834     case e_SS_SM_CAPTURE_DTC_LOGS:
835       l_errorEventType = eErrorEventTypeDtcEvent;
836       break;
837
838     case e_SS_SM_CAPTURE_NAVI_LOGS:
839       l_errorEventType = eErrorEventTypeUserInvokedCollectNaviLog;
840       break;
841
842     case e_SS_SM_CAPTURE_GROUP_RELAUNCH:
843       l_errorEventType = eErrorEventTypeGroupRelaunch;
844       break;
845
846     default:
847       l_errorEventType = eErrorEventTypeMaxValue;
848       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
849           " Error. Received unknown user invoked log type: %d. Dropping request.",
850           l_logInfo.logType);
851       break;
852     }
853
854     if (eErrorEventTypeMaxValue != l_errorEventType) {  // LCOV_EXCL_BR_LINE 200: will not be the else case
855       TEXT(__FUNCTION__,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
856           " ERROR EVENT: User invoked logging request %d/'%s' received. "  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
857               "Adding the request to the event queue.",  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
858           l_logInfo.logType, GetStr(l_logInfo.logType).c_str());  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
859
860       l_eStatus = ErrorEventEnqueue(f_hApp, l_errorEventType,
861           l_moduleName, eErrorEventResetTypeNone, l_loggingInfo);
862
863       LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
864           "ErrorEventEnqueue(UserInvoked)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
865     }
866   }
867
868   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
869   return (l_eStatus);
870 }
871
872 ///////////////////////////////////////////////////////////////////////////////
873 /// \ingroup OnEelExportRequest
874 /// Called when a removable device is inserted and contains the EEL_Export
875 /// trigger.
876 ///
877 /// \param [in] hApp - Application handle.
878 ///
879 /// \return EFrameworkunifiedStatus
880 /// Success ==> eFrameworkunifiedStatusOK
881 /// Failure ==> Other values
882 ///////////////////////////////////////////////////////////////////////////////
883 EFrameworkunifiedStatus CSystemManager::OnEelExportRequest(HANDLE f_hApp) {
884   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
885   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
886   UI_32 l_strlen = FrameworkunifiedGetMsgLength(f_hApp);
887   CHAR l_path[l_strlen];  // NOLINT
888
889   if (l_strlen == 0) {  // LCOV_EXCL_BR_LINE 200: restricted by iterface_unified
890     // LCOV_EXCL_START 200: restricted by iterface_unified
891     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
892     SS_ASERT(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
893     return eFrameworkunifiedStatusFail;
894     // LCOV_EXCL_STOP
895   }
896
897   if (sizeof(l_path) != FrameworkunifiedGetMsgLength(f_hApp)) {  // LCOV_EXCL_BR_LINE 6: must be equal
898     // LCOV_EXCL_START 6: must be equal
899     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
900     LOG_ERROR("DataSize mismatch");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
901     // LCOV_EXCL_STOP
902   } else if (eFrameworkunifiedStatusOK  // LCOV_EXCL_BR_LINE 4: NSFW error case
903       != (l_eStatus = FrameworkunifiedGetMsgDataOfSize(f_hApp, &l_path[0],
904           static_cast<UI_32>(sizeof(l_path)), eSMRRelease))) {
905     // LCOV_EXCL_START 4: NSFW error case
906     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
907     LOG_ERROR("FrameworkunifiedGetMsgDataOfSize()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
908     // LCOV_EXCL_STOP
909   } else {
910     TEXT(__FUNCTION__,
911         " ERROR EVENT: EelExport request received. Adding the request to the event queue.");  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
912     std::string l_moduleName = FrameworkunifiedGetMsgSrc(f_hApp);
913     SMLoggingInfo l_loggingInfo;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
914
915     l_path[l_strlen - 1] = '\0';
916     l_loggingInfo.path = l_path;
917
918     l_eStatus = ErrorEventEnqueue(f_hApp, eErrorEventTypeEelExport,
919         l_moduleName, eErrorEventResetTypeNone, l_loggingInfo);
920
921     LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
922         "ErrorEventEnqueue(eErrorEventTypeEelExport)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
923   }
924
925   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
926   return (l_eStatus);
927 }
928
929 ///////////////////////////////////////////////////////////////////////////////
930 /// \ingroup OnSystemmanagerEmmcLogsRequest
931 /// Called when a removable device is inserted and contains the LOGGERSERVICE_EMMC_LOGS
932 /// trigger.
933 ///
934 /// \param [in] hApp - Application handle.
935 ///
936 /// \return EFrameworkunifiedStatus
937 /// Success ==> eFrameworkunifiedStatusOK
938 /// Failure ==> Other values
939 ///////////////////////////////////////////////////////////////////////////////
940 EFrameworkunifiedStatus CSystemManager::OnSystemmanagerEmmcLogsRequest(HANDLE f_hApp) {
941   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
942   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
943   UI_32 l_strlen = FrameworkunifiedGetMsgLength(f_hApp);
944   CHAR l_path[l_strlen];  // NOLINT
945
946   if (l_strlen == 0) {  // LCOV_EXCL_BR_LINE 4:NSFW
947     // LCOV_EXCL_START 4:NSFW
948     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
949     SS_ASERT(0);
950     return eFrameworkunifiedStatusFail;
951     // LCOV_EXCL_STOP
952   }
953
954   if (sizeof(l_path) != FrameworkunifiedGetMsgLength(f_hApp)) {  // LCOV_EXCL_BR_LINE 8: CHAR l_path[l_strlen]
955     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
956     LOG_ERROR("DataSize mismatch");  // LCOV_EXCL_LINE 8: CHAR l_path[l_strlen]
957   } else if (eFrameworkunifiedStatusOK != (l_eStatus = FrameworkunifiedGetMsgDataOfSize(f_hApp, &l_path[0], static_cast<UI_32>(sizeof(l_path)), eSMRRelease))) {  // LCOV_EXCL_BR_LINE 4:NSFW error case  // NOLINT(whitespace/line_length)
958     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
959     LOG_ERROR("FrameworkunifiedGetMsgDataOfSize()");  // LCOV_EXCL_LINE 4:NSFW error case
960   } else {
961     TEXT(__FUNCTION__,  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
962         " ERROR EVENT: LOGGERSERVICE_EMMC_LOGS request received. Adding the request to the event queue.");  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
963     std::string l_moduleName = FrameworkunifiedGetMsgSrc(f_hApp);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
964     SMLoggingInfo l_loggingInfo;
965
966     l_path[l_strlen - 1u] = '\0';
967     l_loggingInfo.path = l_path;
968
969     l_eStatus = ErrorEventEnqueue(f_hApp, eErrorEventTypeInterfaceunifiedEmmcLogs,
970         l_moduleName, eErrorEventResetTypeNone, l_loggingInfo);
971
972     LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
973         "ErrorEventEnqueue(eErrorEventTypeInterfaceunifiedEmmcLogs)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
974   }
975
976   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
977   return (l_eStatus);
978 }
979
980 ///////////////////////////////////////////////////////////////////////////////
981 /// \ingroup OnSystemmanagerClearLogsRequest
982 /// Called when a clear LOGGERSERVICE_EMMC_LOGS requested
983 /// trigger.
984 ///
985 /// \param [in] hApp - Application handle.
986 ///
987 /// \return EFrameworkunifiedStatus
988 /// Success ==> eFrameworkunifiedStatusOK
989 /// Failure ==> Other values
990 ///////////////////////////////////////////////////////////////////////////////
991 EFrameworkunifiedStatus CSystemManager::OnSystemmanagerClearLogsRequest(HANDLE f_hApp) {
992   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
993   EFrameworkunifiedStatus l_eStatus;
994   std::string l_moduleName = FrameworkunifiedGetMsgSrc(f_hApp);
995
996   l_eStatus = ErrorEventEnqueue(f_hApp, eErrorEventTypeUserInvokedClearLogs,  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
997       l_moduleName, eErrorEventResetTypeNone);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
998
999   LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
1000       "ErrorEventEnqueue(eErrorEventTypeUserInvokedClearLogs)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
1001
1002   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1003   return (l_eStatus);
1004 }
1005
1006 ///////////////////////////////////////////////////////////////////////////////
1007 /// \ingroup OnDiagLoggingRequest
1008 /// Called by logger to initiate log artifact collection and storage on behalf
1009 /// of diagnostic services.
1010 ///
1011 /// \param [in] hApp - Application handle.
1012 ///
1013 /// \return EFrameworkunifiedStatus
1014 /// Success ==> eFrameworkunifiedStatusOK
1015 /// Failure ==> Other values
1016 ///////////////////////////////////////////////////////////////////////////////
1017 EFrameworkunifiedStatus CSystemManager::OnDiagLoggingRequest(HANDLE f_hApp) {
1018   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1019   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1020   UI_32 l_strlen = FrameworkunifiedGetMsgLength(f_hApp);
1021   CHAR l_path[l_strlen];  // NOLINT
1022
1023   if (l_strlen == 0) {  // LCOV_EXCL_BR_LINE 200: restricted by iterface_unified
1024     // LCOV_EXCL_START 200: restricted by iterface_unified
1025     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
1026     SS_ASERT(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1027     return eFrameworkunifiedStatusFail;
1028     // LCOV_EXCL_STOP
1029   }
1030
1031   if (sizeof(l_path) != FrameworkunifiedGetMsgLength(f_hApp)) {  // LCOV_EXCL_BR_LINE 6: must be equal
1032     // LCOV_EXCL_START 6: must be equal
1033     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1034     LOG_ERROR("DataSize mismatch");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1035     // LCOV_EXCL_STOP
1036   } else if (eFrameworkunifiedStatusOK  // LCOV_EXCL_BR_LINE 4: NSFW error case
1037       != (l_eStatus = FrameworkunifiedGetMsgDataOfSize(f_hApp, &l_path[0],
1038         static_cast<UI_32>(sizeof(l_path)), eSMRRelease))) {  // NOLINT
1039     // LCOV_EXCL_START 4: NSFW error case
1040     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
1041     LOG_ERROR("FrameworkunifiedGetMsgDataOfSize()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
1042     // LCOV_EXCL_STOP
1043   } else {
1044     TEXT(__FUNCTION__,  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
1045         " ERROR EVENT: SS_SM_ERROR_EVENT_DIAG_LOG_REQ request received. Adding the request to the event queue.");  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
1046     std::string l_moduleName = FrameworkunifiedGetMsgSrc(f_hApp);
1047     SMLoggingInfo l_loggingInfo;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
1048
1049     l_path[l_strlen - 1u] = '\0';
1050     l_loggingInfo.path = l_path;
1051
1052     l_eStatus = ErrorEventEnqueue(f_hApp, eErrorEventTypeDiagEvent,
1053         l_moduleName, eErrorEventResetTypeNone, l_loggingInfo);
1054
1055     LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
1056         "ErrorEventEnqueue(eErrorEventTypeDiagEvent)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
1057   }
1058
1059   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1060   return (l_eStatus);
1061 }
1062
1063 ///////////////////////////////////////////////////////////////////////////////
1064 /// \ingroup OnCanLoggingRequest
1065 ///  This function is called by logger to initiate log artifact collection
1066 ///  and storage when signaled via CAN.
1067 ///
1068 /// \param [in] hApp - Application handle.
1069 ///
1070 /// \return EFrameworkunifiedStatus
1071 /// Success ==> eFrameworkunifiedStatusOK
1072 /// Failure ==> Other values
1073 ///////////////////////////////////////////////////////////////////////////////
1074 EFrameworkunifiedStatus CSystemManager::OnCANLoggingRequest(HANDLE f_hApp) {
1075   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1076   EFrameworkunifiedStatus l_eStatus;
1077   std::string l_moduleName;
1078
1079   l_moduleName = FrameworkunifiedGetMsgSrc(f_hApp);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
1080
1081   TEXT(__FUNCTION__,  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
1082       " ERROR EVENT: SS_SM_ERROR_EVENT_CAN_LOG_REQ received from %s.",  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
1083       l_moduleName.c_str());  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
1084
1085   l_eStatus = ErrorEventEnqueue(f_hApp, eErrorEventTypeCanEvent, l_moduleName);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
1086
1087   LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
1088       "ErrorEventEnqueue(eErrorEventTypeCanEvent)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
1089
1090   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1091   return (l_eStatus);
1092 }
1093