Re-organized sub-directory by category
[staging/basesystem.git] / service / system / system_manager / server / src / ss_system_manager_error_event_responses.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  SS_SM_Logging
19 /// \brief    This file supports SM logging.
20 ///
21 ///////////////////////////////////////////////////////////////////////////////
22 #include <native_service/frameworkunified_types.h>
23 #include <native_service/ns_plogger_if.h>
24 #include <stub/ss_diag.h>
25 #include <system_service/ss_ver.h>
26 #include <system_service/ss_services.h>
27 #include <system_service/ss_templates.h>
28 #include <system_service/ss_client_names.h>
29 #include <system_service/ss_sm_client_if.h>
30
31 #include <stdint.h>
32 #include <sys/stat.h>
33 #include <sys/types.h>
34 #include <sys/statvfs.h>
35 #include <fcntl.h>
36 #include <dirent.h>
37 #include <errno.h>
38 #include <sys/wait.h>
39 #include <boost/algorithm/string.hpp>
40 #include <fstream>
41 #include <iostream>
42 #include <iomanip>
43 #include <string>
44 #include <list>
45
46 #include "ss_system_manager.h"
47
48 ///////////////////////////////////////////////////////////////////////////
49 //  Function : OnObtainLoggerserviceLogRequest
50 //  brief    : Collect frameworkunifiedlog artifact and return a response to
51 //             SS_Logger.
52 ///////////////////////////////////////////////////////////////////////////
53 static int getExecedString(char* const argv[], std::stringstream &ss) {
54   int ret;
55   int pipeFd[2];  // 0:read, 1:write
56   pid_t pid;
57   ret = pipe(pipeFd);
58   if (ret != 0) {  // LCOV_EXCL_BR_LINE 5:pipe's error case
59     // LCOV_EXCL_START 5:pipe's error case
60     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
61     SS_ASERT_ERRNO(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
62     goto error_exit;
63     // LCOV_EXCL_STOP
64   }
65
66   pid = fork();
67   if (pid == -1) {  // LCOV_EXCL_BR_LINE 5:fork's error case
68     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
69     SS_ASERT_ERRNO(0);  // LCOV_EXCL_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
70   } else if (pid == 0) {
71     close(pipeFd[0]);    // unnecessary pile (closing read)
72     close(1);        // closing stdout
73     dup2(pipeFd[1], 1);  // take stdout to pipe
74     execve(argv[0], argv, environ);
75     SS_ASERT_ERRNO(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
76     exit(EXIT_FAILURE);
77   } else {
78     char readBuf[256];
79     ssize_t rs;
80     SS_ASERT_ERRNO(0 == close(pipeFd[1]));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
81
82     fd_set rfds;
83     FD_ZERO(&rfds);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
84     FD_SET(pipeFd[0], &rfds);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
85     struct timeval timeout;
86     timeout.tv_sec = 2;
87     timeout.tv_usec = 0;
88
89     int selRet = select(pipeFd[0] + 1, &rfds, NULL, NULL, &timeout);
90     switch (selRet) {
91     case 1:
92       if (FD_ISSET(pipeFd[0], &rfds)) {
93         do {
94           rs = read(pipeFd[0], readBuf, sizeof(readBuf) - 1);
95           if (rs > 0) {
96             readBuf[rs] = '\0';
97             ss << readBuf;
98           } else if (rs == -1) {  // LCOV_EXCL_BR_LINE 5:read's error case
99             // LCOV_EXCL_START 5:read's error case
100             AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
101             if (errno != EINTR) {
102               SS_ASERT_ERRNO(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
103               ret = -1;
104               break;
105             }
106             // LCOV_EXCL_STOP
107           }
108         } while (rs != 0);
109       } else {
110         SS_ASERT(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
111       }
112       break;
113     case -1:
114       SS_ASERT_ERRNO(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
115       break;
116     default:
117       // LCOV_EXCL_START 5:never be this case
118       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
119       if (0 == selRet) {
120         ss << "timeout" << std::endl;
121       } else {
122         ss << "ERR:rslt=" << selRet << std::endl;
123       }
124       break;
125       // LCOV_EXCL_STOP
126     }
127
128     // SM leaves processing to OnProcessExitDetected when using child process
129     // SS_ASERT_ERRNO(-1 != waitpid(pid,&status,0));
130   }
131   SS_ASERT_ERRNO(0 == close(pipeFd[0]));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
132 error_exit:
133   return ret;
134 }
135
136 static int saveProcsMemInfo(std::ofstream &fo) {
137   DIR *dir = NULL;
138   int ret = 0;
139
140   try {
141     struct dirent dent, *next;
142     // LCOV_EXCL_BR_START 11:unexpected branch  // NOLINT(whitespace/line_length)
143     {
144       fo << "******** mem info **********" << std::endl;
145       std::ifstream fin("/proc/meminfo");
146       std::string line;
147       while (fin && std::getline(fin, line)) {
148         fo << line << endl;
149       }
150     }
151
152     {
153       fo << "******** slab info **********" << std::endl;
154       std::ifstream fin("/proc/slabinfo");
155       std::string line;
156       while (fin && std::getline(fin, line)) {
157         fo << line << endl;
158       }
159     }
160
161     {
162       fo << "******** zone info **********" << std::endl;
163       std::ifstream fin("/proc/zoneinfo");
164       std::string line;
165       while (fin && std::getline(fin, line)) {
166         fo << line << endl;
167       }
168     }
169     // LCOV_EXCL_BR_STOP
170
171     // Linux dependency codes
172     dir = opendir("/proc");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
173     if (dir == NULL) {  // LCOV_EXCL_BR_LINE 5:opendir's error case
174       // LCOV_EXCL_START 11:opendir's error case
175       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
176       SS_ASERT_ERRNO(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
177       throw eFrameworkunifiedStatusFail;
178       // LCOV_EXCL_STOP
179     }
180
181     fo << "******** proc status **********" << std::endl;
182     while (0 == readdir_r(dir, &dent, &next) && next) {
183       if (DT_DIR == dent.d_type) {
184         struct stat statbuf;
185         std::string statPath("/proc/");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
186         statPath += dent.d_name;
187         statPath += "/status";
188
189         if (stat(statPath.c_str(), &statbuf) == 0) {
190           std::ifstream fin(statPath.c_str());  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
191           std::string line;
192           while (fin && std::getline(fin, line)) {
193             if (strstr(line.c_str(), "Name") != NULL
194                 || strstr(line.c_str(), "Pid") != NULL
195                 || strstr(line.c_str(), "Vm") != NULL) {
196               fo << line << endl;
197             }
198           }
199           fo << "************************************" << std::endl;
200         }
201       }
202     }
203     SS_ASERT_ERRNO(0 == closedir(dir));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
204   } catch (...) {
205     if (dir) {  // LCOV_EXCL_BR_LINE 5:opendir's error case
206       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
207       SS_ASERT_ERRNO(0 == closedir(dir));  // LCOV_EXCL_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
208     }
209     ret = -1;
210   }
211   return ret;
212 }
213
214 ///////////////////////////////////////////////////////////////////////////
215 //  Function : OnObtainLoggerserviceLogRequest
216 //  brief    : Collect frameworkunifiedlog artifact and return a response to
217 //             SS_Logger.
218 ///////////////////////////////////////////////////////////////////////////
219 EFrameworkunifiedStatus CSystemManager::SendLogArtifactResponseToLogger(HANDLE f_hApp,
220         EArtifactId f_artifactId, std::string f_artifactFilePathAndName) {
221   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
222   EFrameworkunifiedStatus l_eStatus;
223   HANDLE l_hLoggerServiceSession;
224   ModuleLaunchListIter l_ModuleListIter;
225   ARTIFACT_RESPONSE l_artifactResponse;
226
227   l_artifactResponse.ArtifactId = f_artifactId;
228
229   strncpy(l_artifactResponse.FilePathAndName,
230       f_artifactFilePathAndName.c_str(),
231       sizeof(l_artifactResponse.FilePathAndName) - 1);
232
233   if (eFrameworkunifiedStatusOK
234       != (l_eStatus = GetModuleIterator(SERVICE_LOGGER, l_ModuleListIter))) {
235     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
236         " Error: GetModuleIterator(%s) errored: %d/'%s'",
237         SERVICE_LOGGER, l_eStatus, GetStr(l_eStatus).c_str());
238   } else {
239     l_hLoggerServiceSession = l_ModuleListIter->hsession;
240
241     l_eStatus = FrameworkunifiedSendMsg(l_hLoggerServiceSession,
242         SS_SM_ERROR_EVENT_ARTIFACT_RSPN, sizeof(l_artifactResponse),
243         &l_artifactResponse);
244
245     LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
246         "FrameworkunifiedSendMsg(SS_SM_ERROR_EVENT_ARTIFACT_RSPN)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
247   }
248
249   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
250   return (l_eStatus);
251 }
252
253 ///////////////////////////////////////////////////////////////////////////////
254 /// \ingroup OnErrorEventArtifactRequest
255 /// Dispatch logging requests to the various handlers.
256 ///
257 /// \param f_hApp Framework application handle.
258 ///
259 /// \return EFrameworkunifiedStatus
260 /// Success ==> eFrameworkunifiedStatusOK
261 /// Failure ==> Other values
262 ///////////////////////////////////////////////////////////////////////////////
263 EFrameworkunifiedStatus CSystemManager::OnErrorEventArtifactRequest(HANDLE hApp) {
264   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
265   EFrameworkunifiedStatus l_eStatus;
266   INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
267
268   if (eFrameworkunifiedStatusOK
269       != (l_eStatus = ReadMsg < EArtifactId
270           > (hApp, m_requestedArtifactId))) {  // LCOV_EXCL_BR_LINE 200:NSFW error case
271     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
272     LOG_ERROR("ReadMsg()");  // LCOV_EXCL_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
273   } else {
274     switch (m_requestedArtifactId) {
275     case eArtifactIdBootMicroLog:
276       l_eStatus = OnObtainBootMicroLog(hApp);
277       LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "OnObtainBootMicroLog()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
278       break;
279
280     case eArtifactIdSystemDataCsv:
281       l_eStatus = OnObtainSystemmanagerSystemDataCsv(hApp);
282       LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "OnObtainSystemmanagerSystemDataCsv()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
283       break;
284
285     case eArtifactIdShowMemTxt:
286       l_eStatus = OnObtainShowMemTxt(hApp);
287       LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "OnObtainShowMemTxt()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
288       break;
289
290     case eArtifactIdProcessCore:
291       SS_ASERT(0);  // Never called in Linux PF // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
292       break;
293
294     case eArtifactIdDebugDumpLog:
295       l_eStatus = OnObtainDebugDumpLog(hApp);
296       LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "OnObtainDebugDumpLog()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
297       break;
298
299     default:
300       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
301           " Error: Unsupported logging artifact requested: %d.",
302           m_requestedArtifactId);
303       break;
304     }
305   }
306
307   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
308   return (l_eStatus);
309 }
310
311 ///////////////////////////////////////////////////////////////////////////////
312 /// \ingroup OnObtainBootMicroLog
313 /// Obtain the boot micro log content, write file to disk, and send filename to SL.
314 ///
315 /// \param [in] f_hApp - Application handle.
316 ///
317 /// \return EFrameworkunifiedStatus
318 /// Success ==> eFrameworkunifiedStatusOK
319 /// Failure ==> Other values
320 ///////////////////////////////////////////////////////////////////////////////
321 EFrameworkunifiedStatus CSystemManager::OnObtainBootMicroLog(HANDLE f_hApp) {
322   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
323   EFrameworkunifiedStatus l_eStatus;
324   INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
325   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(f_hApp));
326
327   l_eStatus = RequestBootMicroLog(f_hApp);
328   LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "RequestBootMicroLog");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
329
330   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
331   return (l_eStatus);
332 }
333
334 ///////////////////////////////////////////////////////////////////////////////
335 /// \ingroup OnBootMicroLogResponse
336 /// Boot micro log response sent from the logging shadow.
337 ///
338 /// \param [in] f_hApp - Application handle.
339 ///
340 /// \return EFrameworkunifiedStatus
341 /// Success ==> eFrameworkunifiedStatusOK
342 /// Failure ==> Other values
343 ///////////////////////////////////////////////////////////////////////////////
344 EFrameworkunifiedStatus CSystemManager::OnBootMicroLogResponse(HANDLE f_hApp) {
345   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
346   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
347   UI_32 l_len;
348   std::string l_artifactFilePathAndName;
349
350   m_errorEventTimers[eSM_ERROR_EVENT_TIMER_BOOT_MICRO_LOG_RSPN].Stop();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
351
352   INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
353   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(f_hApp));
354
355   if (0 == strcmp(TIMER_SERVICE_NAME, FrameworkunifiedGetMsgSrc(f_hApp))) {
356     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
357         " Info. Timer expired while waiting for the boot micro log.");
358   } else if (0 == (l_len = FrameworkunifiedGetMsgLength(f_hApp))) {  // LCOV_EXCL_BR_LINE 200:restricted by ss_sm_client
359     // LCOV_EXCL_START 200:restricted by ss_sm_client
360     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
361     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
362         " Error: Invalid log response received.  Length cannot be 0.");
363     // LCOV_EXCL_STOP
364   } else {
365     char l_buf[l_len];  // NOLINT
366     l_eStatus = FrameworkunifiedGetMsgDataOfSize(f_hApp, l_buf, static_cast<UI_32>(sizeof(l_buf)), eSMRRelease);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
367     if (eFrameworkunifiedStatusOK != l_eStatus) {  // LCOV_EXCL_BR_LINE 200:NSFW error case
368       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
369       LOG_ERROR("FrameworkunifiedGetMsgDataOfSize()");  // LCOV_EXCL_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
370     } else {
371       l_artifactFilePathAndName = "/tmp/bootmicro.log";
372       l_len = static_cast<UI_32>(strlen((const char *) l_buf));
373       std::ofstream l_stream(l_artifactFilePathAndName.c_str());  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
374       l_stream.write(l_buf, l_len);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
375       l_stream.close();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
376     }
377   }
378
379   l_eStatus = SendLogArtifactResponseToLogger(f_hApp, m_requestedArtifactId,
380       l_artifactFilePathAndName);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
381
382   if (l_eStatus != eFrameworkunifiedStatusOK) {
383     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
384         " Error: SendLogArtifactResponseToLogger(Artifact '%d', '%s') "
385             "errored: %d/'%s'", m_requestedArtifactId,
386         l_artifactFilePathAndName.c_str(), l_eStatus,
387         GetStr(l_eStatus).c_str());
388   }
389
390   return (l_eStatus);
391 }
392
393 ///////////////////////////////////////////////////////////////////////////////
394 /// \ingroup OnErrorEventBootMicroLogResponseTimeout
395 /// Called when the boot micro log request timer expires (e.g. no response).
396 ///
397 /// \param [in] f_hApp - Application handle.
398 ///
399 /// \return EFrameworkunifiedStatus
400 /// Success ==> eFrameworkunifiedStatusOK
401 /// Failure ==> Other values
402 ///////////////////////////////////////////////////////////////////////////////
403 EFrameworkunifiedStatus CSystemManager::OnErrorEventBootMicroLogResponseTimeout(HANDLE f_hApp) {
404   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
405   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
406   std::string l_artifactFilePathAndName = "";
407
408   FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
409       " Error: Boot micro log response timed out. Sending empty artifact response to SSL.");
410
411   l_eStatus = SendLogArtifactResponseToLogger(f_hApp, m_requestedArtifactId,
412       l_artifactFilePathAndName);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
413
414   if (l_eStatus != eFrameworkunifiedStatusOK) {
415     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
416         " Error: SendLogArtifactResponseToLogger(Artifact '%d', '%s') "
417             "errored: %d/'%s'", m_requestedArtifactId,
418         l_artifactFilePathAndName.c_str(), l_eStatus,
419         GetStr(l_eStatus).c_str());
420   }
421
422   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
423   return (l_eStatus);
424 }
425
426 ///////////////////////////////////////////////////////////////////////////////
427 /// \ingroup OnObtainSystemmanagerSystemDataCsv
428 /// Obtain system content, write file to disk, and send filename to SL.
429 ///
430 /// \param [in] f_hApp - Application handle.
431 ///
432 /// \return EFrameworkunifiedStatus
433 /// Success ==> eFrameworkunifiedStatusOK
434 /// Failure ==> Other values
435 ///////////////////////////////////////////////////////////////////////////////
436 EFrameworkunifiedStatus CSystemManager::OnObtainSystemmanagerSystemDataCsv(HANDLE f_hApp) {
437   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
438   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
439   // std::string   l_artifactFilePathAndName = "/tmp/frameworkunified_systemdata.csv";
440   // std::ofstream   l_stream(l_artifactFilePathAndName.c_str());
441   std::stringstream l_stream;
442   char *l_pSignalName;
443   INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
444
445   // Output version info
446   {
447     // LCOV_EXCL_BR_START 11:unexpected branch  // NOLINT(whitespace/line_length)
448     CSSVer ver;
449     l_stream << "********** PACKAGE VERSIONS **********\n";
450     l_stream << left;
451     l_stream << setw(16) << "PACKAGE" << setw(24) << "VERSION" << setw(10)
452         << "DATE" << endl;
453     for (SSVerPkgListIter ite = ver.begin(); ite != ver.end(); ite++) {
454       l_stream << setw(16) << ite->first;
455       l_stream << setw(24) << ite->second.version;
456       l_stream << setw(10) << ite->second.date << std::endl;
457     }
458     // LCOV_EXCL_BR_STOP
459     FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", l_stream.str().c_str());
460     l_stream.str("");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
461     l_stream.clear();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
462   }
463
464   // LCOV_EXCL_BR_START 11:unexpected branch  // NOLINT(whitespace/line_length)
465   l_stream << "********** Error Description Start ***********" << endl;
466   l_stream << "Error Event Type,"
467       << GetStr(m_errorEventCurrentIter->m_eventType) << endl;
468   l_stream << m_errorEventCurrentIter->m_eventEnqueueTimeStamp.c_str() << endl;
469   l_stream << "MessageStr,"
470       << m_errorEventCurrentIter->m_loggingInfo.messageStr.c_str() << endl;
471   // LCOV_EXCL_BR_STOP
472
473   {
474     UI_32 l_ErrLogCount = 0;
475     if (PowerHalGetResetInfo(AGL_ERRLOG_COUNTER, &l_ErrLogCount)) {  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
476       FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__,
477         "Could not get AGL_ERRLOG_COUNTER from power_hal.");
478     }
479
480     {
481       l_stream << "ErrLogCount," << l_ErrLogCount << "/"
482           << SS_SM_ERR_LOGGING_LIMIT << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
483     }
484   }
485
486   switch (m_errorEventCurrentIter->m_eventType) {
487   case eErrorEventTypeProcessCrash:
488     l_stream << "Crash Failure Binary Name,"
489         << m_errorEventCurrentIter->m_loggingInfo.binaryFileName << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
490     l_stream << "Module PID," << m_errorEventCurrentIter->m_loggingInfo.pid << endl;
491     l_stream << "Exit Value,"
492         << m_errorEventCurrentIter->m_loggingInfo.exitValue << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
493
494     l_pSignalName = strsignal(
495         m_errorEventCurrentIter->m_loggingInfo.signalNumber);
496     if (NULL != l_pSignalName) {
497       l_stream << "Exit Signal,"
498           << m_errorEventCurrentIter->m_loggingInfo.signalNumber  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
499           << "," << l_pSignalName << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
500     }
501
502     break;
503
504   case eErrorEventTypeProcessExit:
505     l_stream << "Exit Binary Name,"
506         << m_errorEventCurrentIter->m_loggingInfo.binaryFileName << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
507     l_stream << "Module PID," << m_errorEventCurrentIter->m_loggingInfo.pid << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
508     l_stream << "Exit Value,"
509         << m_errorEventCurrentIter->m_loggingInfo.exitValue << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
510     break;
511
512   case eErrorEventTypeHeartBeatFailure:
513     l_stream << "HB Failure Module Queue Name,"
514         << m_errorEventCurrentIter->m_moduleQueueName.c_str() << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
515     l_stream << "***************** HB Information Start *******************" << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
516     l_stream << "Entire State," << m_HBReport.eEntireState << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
517     l_stream << "Module Name,HB State,Retry Count" << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
518
519     for (UI_32 i = 0; i < m_HBReport.nNumOfModules; i++) {
520       if (0 != m_HBReport.tModuleList[i].HeartBeatRetryCount) {
521         l_stream << m_HBReport.tModuleList[i].ProcQueueName << ","  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
522             << m_HBReport.tModuleList[i].ProcHBState << ","  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
523             << m_HBReport.tModuleList[i].HeartBeatRetryCount  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
524             << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
525       }
526     }
527     l_stream << "***************** HB Information End *******************" << endl;
528     break;
529
530   case eErrorEventTypeSystemLowMemory:
531     l_stream << "Free Memory Available (Byte)," << m_FreeMemAvailable << endl;
532     break;
533
534   case eErrorEventTypeBootMicroReset:
535     l_stream << "Boot Micro Reset Reason," << m_BootMicroResetReason << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
536     break;
537
538   case eErrorEventTypeModConnFailed:
539     l_stream << "Failed Module Queue Name,"
540         << m_errorEventCurrentIter->m_moduleQueueName.c_str() << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
541     break;
542
543   case eErrorEventTypeStartRespFailed:
544     l_stream << "Failed Module Queue Name,"
545         << m_errorEventCurrentIter->m_moduleQueueName.c_str() << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
546     break;
547
548        // No additional event specific log information to add.
549   case eErrorEventTypeUserInvokedCollectAllLogs:
550   case eErrorEventTypeUserInvokedCollectScreenShot:
551   case eErrorEventTypeUserInvokedCollectInterfaceunifiedLogs:
552   case eErrorEventTypeUserInvokedUserForceReset:
553   case eErrorEventTypeUserInvokedCollectDevLogs:
554   default:
555     break;
556   }
557
558   {
559     std::ifstream finNum("/proc/sys/vm/nr_oom_kill_process");
560     std::string strNum;
561     if (finNum && std::getline(finNum, strNum)) {  // LCOV_EXCL_BR_LINE 200:will not be this case
562       // LCOV_EXCL_START 200:will not be this case
563       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
564       char *endptr = NULL;
565       long lNum = strtol(strNum.c_str(), &endptr, 10);  // NOLINT
566       if (('\0' != *endptr) || (lNum < 0)) {
567         SS_ASERT(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
568       } else {
569         l_stream << "nr_oom_kill_process," << strNum.c_str() << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
570         if (0 != lNum) {
571           std::ifstream finLast("/proc/sys/vm/last_oom_kill_victim");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
572           std::string strLast;
573           if (finLast && std::getline(finLast, strLast)) {
574             l_stream << "last_oom_kill_victim," << strLast.c_str() << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
575           }
576         }
577       }
578     }
579     // LCOV_EXCL_STOP
580   }
581
582   l_stream << "********** Error Description End ***********" << endl << endl;
583   FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", l_stream.str().c_str());
584
585   fprintf(stderr, "SS_SysManager/\n%s", l_stream.str().c_str());  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
586
587   l_stream.str("");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
588   l_stream.clear();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
589
590   l_stream << "********** Variant Code Start ***********" << endl;
591   if (NULL != m_pVarCodeStr) {
592     l_stream << m_pVarCodeStr << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
593   } else {
594     l_stream << "Variant coding not available." << endl;
595   }
596   l_stream << "********** Variant Code End ***********" << endl << endl;
597   FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", l_stream.str().c_str());
598   l_stream.str("");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
599   l_stream.clear();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
600
601   l_stream << "********** File System Information Start ***********" << endl;
602   l_stream << "== mounts info start==" << endl;
603   {
604     std::ifstream fin("/proc/mounts");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
605     std::string line;
606     while (fin && std::getline(fin, line)) {
607       l_stream << line << endl;
608     }
609   }
610   l_stream << "== mounts info end ==" << endl;
611   FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", l_stream.str().c_str());
612   l_stream.str("");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
613   l_stream.clear();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
614
615   l_stream << "== DF info start==" << endl;
616   {
617     char* const argv[] = { const_cast<char*>("/bin/df"), const_cast<char*>("-a"), static_cast<char*>(NULL), };
618     SS_ASERT(0 == getExecedString(argv, l_stream));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
619   }
620   l_stream << "== DF info end==" << endl;
621
622   FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", l_stream.str().c_str());
623   l_stream.str("");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
624   l_stream.clear();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
625
626 #if 0   // Need to install lsblk if requested so that it is not installed
627   l_stream << "== lsblk info start==" << endl;
628   {
629     char* const argv[] = {
630       const_cast<char*>("/usr/debug/bin/lsblk"),
631       const_cast<char*>("-o"),
632       const_cast<char*>("NAME,KNAME,MAJ:MIN,FSTYPE,PARTLABEL,MODEL,SERIAL,REV,VENDOR"),
633       const_cast<char*>(NULL),
634     };
635     SS_ASERT(0 == getExecedString(argv, l_stream));
636   }
637   l_stream << "== lsblk info end==" << endl;
638   FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", l_stream.str().c_str());
639   l_stream.str("");
640   l_stream.clear();
641 #endif
642
643   l_stream << "== proc info start==" << endl;
644   {
645     char* const argv[] = { const_cast<char*>("/bin/ps"), const_cast<char*>("auxc"),
646         const_cast<char*>("-L"), static_cast<char*>(NULL), };
647     SS_ASERT(0 == getExecedString(argv, l_stream));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
648   }
649   l_stream << "== proc info end==" << endl;
650   {
651     // Output is splitted so that the FRAMEWORKUNIFIEDLOG can not write data over 4K Bytes at a time
652     std::list<std::string> strList;
653     boost::split(strList, static_cast<const std::string>(l_stream.str()),
654         boost::is_any_of("\n"));  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
655
656     int ii = 0;
657     std::stringstream ss;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
658     for (std::list<std::string>::iterator ite = strList.begin();
659         ite != strList.end(); ite++) {
660       ss << *ite << endl;
661       ii++;
662       if (ii > 20) {
663         FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", ss.str().c_str());
664         ss.str("");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
665         ss.clear();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
666         ii = 0;
667       }
668     }
669     FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", ss.str().c_str());
670   }
671   l_stream.str("");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
672   l_stream.clear();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
673
674   l_eStatus = SendLogArtifactResponseToLogger(f_hApp, m_requestedArtifactId, "");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
675
676   if (l_eStatus != eFrameworkunifiedStatusOK) {
677     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
678         " Error: SendLogArtifactResponseToLogger(Artifact '%d') "
679             "errored: %d/'%s'", m_requestedArtifactId, l_eStatus,
680         GetStr(l_eStatus).c_str());
681   }
682
683   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
684   return (l_eStatus);
685 }
686
687 ///////////////////////////////////////////////////////////////////////////////
688 /// \ingroup OnObtainShowMemTxt
689 /// Obtain showmem content, write file to disk, and send filename to SL.
690 ///
691 /// \param [in] f_hApp - Application handle.
692 ///
693 /// \return EFrameworkunifiedStatus
694 /// Success ==> eFrameworkunifiedStatusOK
695 /// Failure ==> Other values
696 ///////////////////////////////////////////////////////////////////////////////
697 EFrameworkunifiedStatus CSystemManager::OnObtainShowMemTxt(HANDLE f_hApp) {
698   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
699   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
700   INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
701
702   std::string l_artifactFilePathAndName = "/tmp/showmem.txt";
703   {
704     std::ofstream fo(l_artifactFilePathAndName.c_str());  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
705     saveProcsMemInfo(fo);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
706   }
707
708   l_eStatus = SendLogArtifactResponseToLogger(f_hApp, m_requestedArtifactId,
709                                               l_artifactFilePathAndName);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
710
711   if (l_eStatus != eFrameworkunifiedStatusOK) {
712     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
713         " Error: SendLogArtifactResponseToLogger(Artifact '%d', '%s') "
714             "errored: %d/'%s'", m_requestedArtifactId,
715         l_artifactFilePathAndName.c_str(), l_eStatus,
716         GetStr(l_eStatus).c_str());
717   }
718
719   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
720   return (l_eStatus);
721 }
722
723 ///////////////////////////////////////////////////////////////////////////////
724 /// \ingroup OnErrorEventCoreFilePollTimeout
725 /// Called periodically to verify whether the process core file has completed
726 /// being written to disk. When complete, this function sends an artifact
727 /// response to SSL.
728 ///
729 /// \param [in] f_hApp - Application handle.
730 ///
731 /// \return EFrameworkunifiedStatus
732 /// Success ==> eFrameworkunifiedStatusOK
733 /// Failure ==> Other values
734 ///////////////////////////////////////////////////////////////////////////////
735 EFrameworkunifiedStatus CSystemManager::OnErrorEventCoreFilePollTimeout(HANDLE f_hApp) {  // LCOV_EXCL_START 8:dead code
736   AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
737   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
738   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
739   BOOL l_sendResponse = FALSE;
740   std::string l_artifactFilePathAndName = "";
741   std::ostringstream l_coreFilePathAndName;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
742
743 //  struct stat l_fileInfo;
744   struct stat64 l_fileInfo;
745   int l_result;
746   off_t l_coreFileSize;
747   INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
748
749   l_coreFilePathAndName << "/debug/"
750       << m_errorEventCurrentIter->m_loggingInfo.binaryFileName << ".core.gz";  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
751
752
753 //  l_result = stat(l_coreFilePathAndName.str().c_str(), &l_fileInfo);
754   l_result = stat64(l_coreFilePathAndName.str().c_str(), &l_fileInfo);
755   if (l_result == 0) {
756     l_coreFileSize = l_fileInfo.st_size;
757     if ((l_coreFileSize > m_coreFileSizeBytes) ||  // Core file grew from last read.
758         (l_coreFileSize == 0)) {  // Core file not yet updated externally.
759       m_coreFileSizeBytes = l_coreFileSize;  // Wait until file stops growing.
760       bool result =
761           m_errorEventTimers[eSM_ERROR_EVENT_TIMER_CORE_FILE_POLL].Start(  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
762               0, SS_ERROR_EVENT_CORE_FILE_POLL_TO_MS, 0, 0);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
763       if (FALSE == result) {
764         FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
765             " Error: Failed to start timer SS_ERROR_EVENT_CORE_FILE_POLL_TO_MS.");
766         l_sendResponse = TRUE;
767       } else {
768         FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
769             " Info. Core file: %s, size: %ld still growing.",
770             l_coreFilePathAndName.str().c_str(),
771             m_coreFileSizeBytes);
772
773         l_sendResponse = FALSE;
774       }
775     } else {  // File has stopped growing.
776       FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
777           " Info. Core file: %s, size: %ld write complete. Sending artifact response.",
778           l_coreFilePathAndName.str().c_str(), m_coreFileSizeBytes);
779
780       l_artifactFilePathAndName = l_coreFilePathAndName.str();
781       l_sendResponse = TRUE;
782     }
783   } else {
784     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
785         " Info. Core file: %s, unable to determine size.  Sending empty artifact response to SSL.",
786         l_coreFilePathAndName.str().c_str());
787
788     l_sendResponse = TRUE;
789   }
790
791   if (TRUE == l_sendResponse) {
792     l_eStatus = SendLogArtifactResponseToLogger(f_hApp,  // Error getting file size. Send empty path to SSL.
793     m_requestedArtifactId, l_artifactFilePathAndName);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
794
795     if (l_eStatus != eFrameworkunifiedStatusOK) {
796       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
797           " Error: SendLogArtifactResponseToLogger(Artifact '%d', '%s') "
798               "errored: %d/'%s'", m_requestedArtifactId,
799           l_artifactFilePathAndName.c_str(), l_eStatus,
800           GetStr(l_eStatus).c_str());
801     }
802   }
803
804   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
805   return (l_eStatus);
806 }
807 // LCOV_EXCL_STOP
808
809 ///////////////////////////////////////////////////////////////////////////////
810 /// \ingroup OnObtainDebugDumpLog
811 /// Obtain debug dump content, write file to disk, and send filename to SL.
812 /// See OnModuleDebugDumpResponse().
813 ///
814 /// \param [in] f_hApp - Application handle.
815 ///
816 /// \return EFrameworkunifiedStatus
817 /// Success ==> eFrameworkunifiedStatusOK
818 /// Failure ==> Other values
819 ///////////////////////////////////////////////////////////////////////////////
820 EFrameworkunifiedStatus CSystemManager::OnObtainDebugDumpLog(HANDLE f_hApp) {
821   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
822   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
823   INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
824
825   ModuleLaunchListIter l_moduleIter;
826
827   m_NbrDebugDumpRspnRecv = 0;
828
829   for (GroupLaunchMapIter l_GroupIter = m_MapProclaunchGrps.begin();
830       l_GroupIter != m_MapProclaunchGrps.end(); l_GroupIter++) {
831     for (l_moduleIter = l_GroupIter->second.modules.begin();
832         l_moduleIter != l_GroupIter->second.modules.end();
833         l_moduleIter++) {
834       const BOOL isModuleConnected = l_moduleIter->IsModuleConnected();  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
835       if ((SERVICE_NS_NPP != l_moduleIter->name) &&  // NPP is a special case and does NOT session connect with SM.
836           (TRUE == isModuleConnected)) {
837         l_eStatus = FrameworkunifiedSendMsg(l_moduleIter->hsession, SS_SM_DEBUG_DUMP,
838             0, NULL);
839
840         if (eFrameworkunifiedStatusOK == l_eStatus) {  // LCOV_EXCL_BR_LINE 200:NSFW error case
841           FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
842               " Info. FrameworkunifiedSendMsg(SS_SM_DEBUG_DUMP) to %s succeeded.", // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
843               l_moduleIter->name.c_str());  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
844         } else {
845           // LCOV_EXCL_START 200:NSFW error case
846           AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
847           FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
848               " Error: FrameworkunifiedSendMsg(%p, SS_SM_DEBUG_DUMP) to %s errored: %d/'%s'",
849               (void *) l_moduleIter->hsession,
850               l_moduleIter->name.c_str(), l_eStatus,
851               GetStr(l_eStatus).c_str());
852           // LCOV_EXCL_STOP
853         }
854       }
855     }
856   }
857
858   // Call debug dump handler for SM.
859   l_eStatus = OnSystemManagerDebugDump(f_hApp);
860   LOG_STATUS(l_eStatus, "OnSystemManagerDebugDump()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
861
862   // Refresh debug dump timeout timer after each debug dump response received.
863   // Non AGL framework modules will have the remaining time after the last
864   // received response to complete their debug dump.
865   bool result =
866       m_errorEventTimers[eSM_ERROR_EVENT_TIMER_DEBUG_DUMP_RSPN].Start(
867           SS_ERROR_EVENT_DEBUG_DUMP_RSPN_TO_SEC, 0, 0, 0);
868   if (FALSE == result) {  // LCOV_EXCL_BR_LINE 200:will not be this case
869     // LCOV_EXCL_START 200:will not be this case
870     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
871     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
872         " Error: Failed to start timer eSM_TIMER_DEBUG_DUMP_RSPN_MONITOR.");
873     // LCOV_EXCL_STOP
874   }
875
876   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
877   return (l_eStatus);
878 }
879
880 ///////////////////////////////////////////////////////////////////////////////
881 /// \ingroup OnDebugDumpResponseReceived
882 /// Debug Dump complete Response handler.
883 /// See OnDebugDumpCompleteTimeout().
884 ///
885 /// \param [in] f_hApp - Application handle.
886 ///
887 /// \return EFrameworkunifiedStatus
888 /// Success ==> eFrameworkunifiedStatusOK
889 /// Failure ==> Other values
890 ///////////////////////////////////////////////////////////////////////////////
891 EFrameworkunifiedStatus CSystemManager::OnDebugDumpResponseReceived(HANDLE f_hApp) {
892   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
893   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
894   ModuleLaunchListIter l_ModuleListIter;
895   UI_32 l_len;
896   INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
897
898   std::string l_moduleName = FrameworkunifiedGetMsgSrc(f_hApp);
899   FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", l_moduleName.c_str());
900
901   SetCmdHist("SS_SM_DEBUG_DUMP_RSPN", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(f_hApp));  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
902
903   // SM is not launched by SM and is therefore not in the process list.
904   // SM does however use the same debug dump mechanism as other processes.
905   if (l_moduleName != SERVICE_SYSMANAGER) {
906     l_eStatus = GetModuleIterator(l_moduleName.c_str(), l_ModuleListIter);
907     if (eFrameworkunifiedStatusOK != l_eStatus) {
908       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
909           " Error: Module %s not found in Group Launch Map", l_moduleName.c_str());
910     } else {
911       l_ModuleListIter->SetModuleDebugDumpState(MODULE_DEBUG_DUMP_STATE_RESPONSE_RECEIVED);
912     }
913   }
914
915   if (0 == (l_len = FrameworkunifiedGetMsgLength(f_hApp))) {  // LCOV_EXCL_BR_LINE 200:restricted by ss_sm_client
916     // LCOV_EXCL_START 200:restricted by ss_sm_client
917     AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
918     l_eStatus = eFrameworkunifiedStatusInvldBufSize;
919     LOG_ERROR("0 == FrameworkunifiedGetMsgLength(f_hApp)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
920     // LCOV_EXCL_STOP
921   } else {
922     FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
923         " Received debug dump response from %s, size: %d bytes. "
924             "Total number of responses received: %d",
925         l_moduleName.c_str(), l_len, m_NbrDebugDumpRspnRecv);
926
927     UI_8 l_buf[l_len];  // NOLINT
928     l_eStatus = FrameworkunifiedGetMsgDataOfSize(f_hApp, l_buf, static_cast<UI_32>(sizeof(l_buf)),
929         eSMRRelease);
930     if (eFrameworkunifiedStatusOK != l_eStatus) {
931       LOG_ERROR("FrameworkunifiedGetMsgDataOfSize()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
932     } else {
933       ios_base::openmode l_mode;
934       if (0 == m_NbrDebugDumpRspnRecv) {
935         // Create new file.
936         l_mode = std::ios_base::trunc;
937       } else {
938         // Append existing file.
939         l_mode = std::ios_base::app;
940       }
941
942       std::ofstream l_stream("/tmp/systemmanager_debugdump.log", l_mode);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
943       l_stream << l_buf << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
944       l_stream.close();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
945     }
946
947     m_NbrDebugDumpRspnRecv++;
948
949     // Refresh debug dump timeout timer after each debug dump response received.
950     // Non AGL framework modules will have the remaining time after the last
951     // received response to complete their debug dump.
952     bool result =
953         m_errorEventTimers[eSM_ERROR_EVENT_TIMER_DEBUG_DUMP_RSPN].Start(  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
954             SS_ERROR_EVENT_DEBUG_DUMP_RSPN_TO_SEC, 0, 0, 0);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
955     if (FALSE == result) {  // LCOV_EXCL_BR_LINE 200:will not be this case
956       // LCOV_EXCL_START 200:will not be this case
957       AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
958       FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
959           " Error: Failed to start timer eSM_TIMER_DEBUG_DUMP_RSPN_MONITOR.");
960       l_eStatus = OnDebugDumpCompleteTimeout(f_hApp);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
961       LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
962           "OnDebugDumpCompleteTimeout()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
963       // LCOV_EXCL_STOP
964     }
965   }
966
967   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
968   return l_eStatus;
969 }
970
971 ///////////////////////////////////////////////////////////////////////////////
972 /// \ingroup OnDebugDumpCompleteTimeout
973 /// Called after the last debug dump message is received, or when the debug
974 /// dump monitor timer expires.
975 ///
976 /// \param [in] f_hApp - Application handle.
977 ///
978 /// \return EFrameworkunifiedStatus
979 /// Success ==> eFrameworkunifiedStatusOK
980 /// Failure ==> Other values
981 ///////////////////////////////////////////////////////////////////////////////
982 EFrameworkunifiedStatus CSystemManager::OnDebugDumpCompleteTimeout(HANDLE f_hApp) {
983   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
984   EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
985   std::string l_artifactFilePathAndName = "/tmp/systemmanager_debugdump.log";
986   INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
987
988   m_errorEventTimers[eSM_ERROR_EVENT_TIMER_DEBUG_DUMP_RSPN].Stop();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
989
990   FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Received '%d' Debug Dump responses.",
991       m_NbrDebugDumpRspnRecv);
992
993   l_eStatus = SendLogArtifactResponseToLogger(f_hApp, m_requestedArtifactId,
994       l_artifactFilePathAndName);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
995
996   if (l_eStatus != eFrameworkunifiedStatusOK) {
997     FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
998         " Error: SendLogArtifactResponseToLogger(Artifact '%d', '%s') "
999             "errored: %d/'%s'", m_requestedArtifactId,
1000         l_artifactFilePathAndName.c_str(), l_eStatus,
1001         GetStr(l_eStatus).c_str());
1002   }
1003
1004   FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1005   return l_eStatus;
1006 }
1007