2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup tag_SS_LoggerService
19 /// \brief Provide support for SS Logger module utility functions.
21 ///////////////////////////////////////////////////////////////////////////////
22 ///////////////////////////////////////////////////////////////////////////////
24 ///////////////////////////////////////////////////////////////////////////////
25 #include "ss_logger_util.h"
26 #include <sys/types.h>
34 #include <stub/Clock_API.h>
40 #include "ss_logger_common.h"
42 #include <system_service/ss_logger_store_logs.h>
44 #define SS_STORE_FILENAME_SYSILG_TERM "_SYS_ILG_RESET.tar.gz"
45 #define SS_STORE_FILENAME__CWORD52__TERM "__CWORD52_.log"
48 char CLoggerUtil::m_usbpath[USB_PATH_SIZE];
50 ///////////////////////////////////////////////////////////////////////////////
52 ///////////////////////////////////////////////////////////////////////////////
53 CLoggerUtil::CLoggerUtil(void)
57 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
59 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
62 CLoggerUtil::~CLoggerUtil(void) { // LCOV_EXCL_START 14:globle instance
63 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
64 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
65 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
69 EFrameworkunifiedStatus CLoggerUtil::Initialize(CLoggerCfg *f_pLoggerCfg) {
70 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
71 EFrameworkunifiedStatus l_eStatus;
73 m_pCfg = f_pLoggerCfg;
74 l_eStatus = (NULL != f_pLoggerCfg) ? eFrameworkunifiedStatusOK : eFrameworkunifiedStatusInvldParam;
76 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
80 std::string CLoggerUtil::getDestination(TLoggerErrorEvent &f_eventNtfData) {
81 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+: %d ", f_eventNtfData.EventType);
82 std::string l_path = "";
83 EFrameworkunifiedStatus l_eStatus;
85 switch (f_eventNtfData.EventType) {
86 case eErrorEventTypeProcessCrash:
87 case eErrorEventTypeHeartBeatFailure:
88 case eErrorEventTypeSystemLowMemory:
89 case eErrorEventTypeBootMicroReset:
90 case eErrorEventTypeProcessExit:
91 case eErrorEventTypeUserInvokedUserForceReset:
92 case eErrorEventTypeModConnFailed:
93 case eErrorEventTypeStartRespFailed:
94 case eErrorEventTypeUserInvokedCollectDevLogs:
95 case eErrorEventTypeModuleInvokedResetRequest:
96 case eErrorEventTypeModuleInvokedCollectDebugLogs:
97 case eErrorEventTypeDtcEvent:
98 case eErrorEventTypeUserInvokedClearLogs:
99 case eErrorEventTypeGroupRelaunch:
100 l_eStatus = m_pCfg->GetEmmcDestination(l_path);
103 case eErrorEventTypeUserInvokedCollectNaviLog:
104 l_eStatus = m_pCfg->GetEmmcNaviLogDestination(l_path);
107 case eErrorEventTypeEelExport:
108 l_path = f_eventNtfData.ModuleName;
109 l_eStatus = eFrameworkunifiedStatusOK;
112 case eErrorEventTypeInterfaceunifiedEmmcLogs:
113 l_path = f_eventNtfData.ModuleName;
114 l_eStatus = eFrameworkunifiedStatusOK;
117 case eErrorEventTypeUserInvokedCollectAllLogs:
118 case eErrorEventTypeUserInvokedCollectScreenShot:
119 case eErrorEventTypeUserInvokedCollectInterfaceunifiedLogs:
120 case eErrorEventTypeCanEvent:
121 l_eStatus = m_pCfg->GetUserInvokedDestination(l_path);
124 case eErrorEventTypeDiagEvent:
125 l_path = f_eventNtfData.ModuleName;
126 l_eStatus = eFrameworkunifiedStatusOK;
130 l_eStatus = eFrameworkunifiedStatusFail;
133 if (eFrameworkunifiedStatusOK != l_eStatus) {
134 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Could not get filepath ");
136 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %s", l_path.c_str());
139 EFrameworkunifiedStatus CLoggerUtil::checkDestinationAvailable(
140 TLoggerErrorEvent &f_eventNtfData) {
141 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
142 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
143 std::string l_path = CLoggerUtil::getDestination(f_eventNtfData);
144 std::string::size_type ret;
146 if (l_path.length() > 0) {
147 ret = l_path.find(DEBUG_USB_PATH);
148 if (ret != std::string::npos && ret == 0) {
149 if (0 == access(m_usbpath, W_OK)) { // LCOV_EXCL_BR_LINE 5:C code
150 // LCOV_EXCL_START 5:C code
151 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
152 std::string path = l_path.substr(sizeof(DEBUG_USB_PATH) - 1);
153 f_eventNtfData.ModuleName = m_usbpath;
154 f_eventNtfData.ModuleName.append(path);
155 l_eStatus = eFrameworkunifiedStatusOK;
159 if (0 == access(l_path.c_str(), W_OK)) { // LCOV_EXCL_BR_LINE 5:C code
160 l_eStatus = eFrameworkunifiedStatusOK;
165 if (eFrameworkunifiedStatusOK != l_eStatus) {
166 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
167 " Error. Failed the check path: l_eStatus(%d), l_path(%s)",
168 l_eStatus, l_path.c_str()); // LCOV_EXCL_BR_LINE 11:except,C++ STL
170 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
174 static void SetSuffixFromType(std::string &pathAndName, EErrorEventType type) { // NOLINT (runtime/references)
176 case eErrorEventTypeProcessCrash:
177 case eErrorEventTypeHeartBeatFailure:
178 case eErrorEventTypeSystemLowMemory:
179 case eErrorEventTypeBootMicroReset:
180 case eErrorEventTypeProcessExit:
181 case eErrorEventTypeModConnFailed:
182 case eErrorEventTypeStartRespFailed:
183 case eErrorEventTypeModuleInvokedResetRequest:
184 pathAndName.insert(pathAndName.find(".tar.gz"), "_ERR");
186 case eErrorEventTypeUserInvokedUserForceReset:
187 case eErrorEventTypeUserInvokedCollectAllLogs:
188 case eErrorEventTypeUserInvokedCollectScreenShot:
189 case eErrorEventTypeUserInvokedCollectInterfaceunifiedLogs:
190 case eErrorEventTypeDiagEvent:
191 case eErrorEventTypeCanEvent:
192 case eErrorEventTypeDtcEvent:
193 case eErrorEventTypeModuleInvokedCollectDebugLogs:
194 pathAndName.insert(pathAndName.find(".tar.gz"), "_DIAG");
196 case eErrorEventTypeUserInvokedCollectDevLogs:
197 pathAndName.insert(pathAndName.find(".tar.gz"), "_DEBUG");
199 case eErrorEventTypeGroupRelaunch:
200 pathAndName.insert(pathAndName.find(".tar.gz"), "_GRP_RELAUNCH");
207 EFrameworkunifiedStatus CLoggerUtil::getFilePathAndName(HANDLE f_hApp,
208 TLoggerErrorEvent &f_eventNtfData,
210 std::string &f_pathAndName) {
211 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
212 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
215 switch (f_eventNtfData.EventType) { // LCOV_EXCL_BR_LINE 200: eErrorEventTypeEelExport ex. can not be run
216 case eErrorEventTypeProcessCrash:
217 case eErrorEventTypeProcessExit:
218 case eErrorEventTypeHeartBeatFailure:
219 case eErrorEventTypeSystemLowMemory:
220 case eErrorEventTypeBootMicroReset:
221 case eErrorEventTypeModConnFailed:
222 case eErrorEventTypeStartRespFailed:
223 case eErrorEventTypeGroupRelaunch:
224 l_eStatus = m_pCfg->GetEmmcDestination(f_pathAndName);
225 if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 6:it will aways return ok
226 // LCOV_EXCL_START 6:it will aways return ok
227 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
228 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
229 " Error. GetEmmcDestination() returned %d.",
233 f_pathAndName.append("/");
234 f_pathAndName.append(GetEmmcFilename(f_time));
238 case eErrorEventTypeUserInvokedUserForceReset:
239 case eErrorEventTypeUserInvokedCollectDevLogs:
240 l_eStatus = m_pCfg->GetEmmcDestination(f_pathAndName);
241 if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 6:it will aways return ok
242 // LCOV_EXCL_START 6:it will aways return ok
243 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
244 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
245 " Error. GetEmmcDestination() returned %d.",
249 f_pathAndName.append("/");
250 f_pathAndName.append(GetEmmcFilename(f_time));
253 case eErrorEventTypeModuleInvokedResetRequest:
254 case eErrorEventTypeModuleInvokedCollectDebugLogs:
255 case eErrorEventTypeDtcEvent:
256 l_eStatus = m_pCfg->GetEmmcDestination(f_pathAndName);
257 if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 6:it will aways return ok
258 // LCOV_EXCL_START 6:it will aways return ok
259 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
260 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
261 " Error. GetEmmcDestination() returned %d.",
265 f_pathAndName.append("/");
266 f_pathAndName.append(GetEmmcFilename(f_time));
267 if (!f_eventNtfData.ModuleName.empty()) { // LCOV_EXCL_BR_LINE 6: ModuleName can not be empty
268 size_t l_pos = f_pathAndName.find(".tar.gz");
269 if (l_pos != std::string::npos) { // LCOV_EXCL_BR_LINE 6: ".tar.gz" is aways exist
270 f_pathAndName.insert(l_pos, f_eventNtfData.ModuleName);
275 case eErrorEventTypeEelExport: // LCOV_EXCL_START 6: impossible to confirm because it can not get in
276 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
277 f_pathAndName = f_eventNtfData.ModuleName;
278 f_pathAndName.append("/");
279 f_pathAndName.append("loggerservicelogs_export_");
280 f_pathAndName.append(GetTimeString(f_time));
281 f_pathAndName.append(".tar.gz");
284 case eErrorEventTypeInterfaceunifiedEmmcLogs: // LCOV_EXCL_START 6: impossible to confirm because it can not get in
285 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
286 // store the target location on event trigger
287 f_pathAndName = f_eventNtfData.ModuleName;
290 case eErrorEventTypeUserInvokedCollectAllLogs:
291 l_eStatus = m_pCfg->GetUserInvokedDestination(f_pathAndName);
292 if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 6: impossible to confirm because it can not be fail
293 // LCOV_EXCL_START 6: impossible to confirm because it can not be fail
294 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
295 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
296 " Error. GetUserInvokedDestination() returned %d.",
300 std::string l_emmc_path = m_pCfg->getEmmcOutputPath();
301 f_pathAndName.append(l_emmc_path);
302 f_pathAndName.append("/");
303 f_pathAndName.append(GetUserInvokedFilename(f_hApp, f_time));
304 if (!f_eventNtfData.ModuleName.empty()) { // LCOV_EXCL_BR_LINE 6: it can not be empty
305 size_t l_pos = f_pathAndName.find(".tar.gz");
306 if (l_pos != std::string::npos) { // LCOV_EXCL_BR_LINE 6: ".tar.gz" is aways exist
307 f_pathAndName.insert(l_pos, f_eventNtfData.ModuleName);
313 case eErrorEventTypeUserInvokedCollectScreenShot:
314 case eErrorEventTypeUserInvokedCollectInterfaceunifiedLogs:
315 case eErrorEventTypeCanEvent:
316 l_eStatus = m_pCfg->GetUserInvokedDestination(f_pathAndName);
317 if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 6: impossible to confirm because it can not be fail
318 // LCOV_EXCL_START 6: impossible to confirm because it can not be fail
319 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
320 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
321 " Error. GetUserInvokedDestination() returned %d.",
325 f_pathAndName.append("/");
326 f_pathAndName.append(GetUserInvokedFilename(f_hApp, f_time));
330 case eErrorEventTypeDiagEvent: // LCOV_EXCL_START 6: impossible to confirm because it can not get in
331 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
332 f_pathAndName = f_eventNtfData.ModuleName;
333 f_pathAndName.append("/");
334 f_pathAndName.append(GetUserInvokedFilename(f_hApp, f_time));
335 l_eStatus = eFrameworkunifiedStatusOK;
338 case eErrorEventTypeUserInvokedClearLogs:
339 case eErrorEventTypeUserInvokedCollectNaviLog:
340 l_eStatus = eFrameworkunifiedStatusOK;
344 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Unknown event type: %d.",
345 f_eventNtfData.EventType);
346 l_eStatus = eFrameworkunifiedStatusFail;
350 SetSuffixFromType(f_pathAndName, f_eventNtfData.EventType);
352 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
356 // LCOV_EXCL_START 13:
357 EFrameworkunifiedStatus CLoggerUtil::getNaviLogFilePathAndName(std::string &f_prefix,
359 std::string &f_pathAndName) { // LCOV_EXCL_BR_LINE 13:
360 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
361 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
362 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
364 l_eStatus = m_pCfg->GetEmmcNaviLogDestination(f_pathAndName);
365 if (eFrameworkunifiedStatusOK != l_eStatus) {
366 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
367 " Error. GetEmmNaviLogDestination() returned %d.",
370 f_pathAndName.append("/");
371 f_pathAndName.append(f_prefix);
372 f_pathAndName.append(GetEmmcNaviLogFilename(f_time));
375 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
380 // LCOV_EXCL_START 200:
381 EFrameworkunifiedStatus CLoggerUtil::getEmmcNaviLogParams(
382 uint32_t f_time, EPWR_SHUTDOWN_TRIGGER_TYPE errorType,
383 std::string &f_pathName, UI_32 &f_logMax) {
384 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
385 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
387 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
388 std::string l_prefix = "";
390 std::vector<std::string> l_vector;
391 std::string l_path = m_pCfg->getEmmcOutputNaviLogPath();
393 if ((errorType == epssdmsdtGENERIC_ERROR_RESET)
394 || (errorType == epssdmsdtFATAL_ERROR_RESET)) {
395 /*When reset occured !!*/
396 f_logMax = m_pCfg->m_emmcOutputNaviLogErrMax;
400 f_logMax = m_pCfg->m_emmcOutputNaviLogNmlMax;
405 l_eStatus = eFrameworkunifiedStatusOK;
409 l_dirp = opendir(l_path.c_str());
410 if (l_dirp != NULL) {
411 struct dirent l_dirent;
414 while (0 == readdir_r(l_dirp, &l_dirent, &next) && next != NULL) {
415 std::string l_findFileName = l_dirent.d_name;
416 size_t l_find_pos_top = l_findFileName.find(l_prefix.c_str());
417 size_t l_find_pos = l_findFileName.find(".log");
418 if (std::string::npos != l_find_pos
419 && std::string::npos != l_find_pos_top) {
420 l_vector.push_back(l_findFileName);
425 std::sort(l_vector.begin(), l_vector.end());
427 for (UI_32 i = static_cast<UI_32>(l_vector.size()); i != 0; i--) {
428 std::string l_FilePath = l_path;
429 std::string l_FileName = l_vector.at(i - 1);
430 l_FilePath.append("/");
431 l_FilePath.append(l_FileName.c_str());
434 size_t l_pos = l_FileName.find("_", l_prefix.size());
435 if (std::string::npos != l_pos) {
436 std::string l_renameFilePath = l_path;
437 std::stringstream l_numStream;
438 l_numStream << std::setw(5) << std::setfill('0') << std::right << std::dec << (i + 1);
439 l_renameFilePath.append("/");
440 l_renameFilePath.append(l_prefix);
441 l_renameFilePath.append(l_numStream.str());
442 l_renameFilePath.append(l_FileName, l_pos, (l_FileName.size() - l_pos));
443 if (0 != rename(l_FilePath.c_str(), l_renameFilePath.c_str())) {
444 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. rename navilog file %s:%d.",
445 l_FilePath.c_str(), errno);
449 if (0 != unlink(l_FilePath.c_str())) {
450 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. delete navilog file %s:%d.",
451 l_FilePath.c_str(), errno);
455 // sync parent directory
458 l_eStatus = getNaviLogFilePathAndName(l_prefix, f_time, f_pathName);
459 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
464 // LCOV_EXCL_START 200: can not be called
465 size_t CLoggerUtil::deleteRequestLogs(std::string f_emmcpath,
466 ELOGGERSERVICELOGTYPE f_reqtype, size_t f_reqsize,
467 ELOGGERSERVICELOGTYPE f_deltype) {
468 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
469 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
471 std::vector<std::string> vect;
472 std::vector<std::string>::iterator it;
474 size_t l_totalsize = 0;
476 // create saved file list on eMMC
477 l_dirp = opendir(f_emmcpath.c_str());
478 if (l_dirp != NULL) {
479 struct dirent l_dirent;
481 while (0 == readdir_r(l_dirp, &l_dirent, &next) && next != NULL) {
482 std::string l_filename = l_dirent.d_name;
483 if (CLoggerUtil::QueryLoggerservicelogType(l_filename) == f_deltype) {
484 vect.push_back(l_filename);
489 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " open failed eMMC path: %s",
491 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
495 // get num of delete logs
496 std::sort(vect.begin(), vect.end());
497 for (it = vect.begin(); it != vect.end(); it++) {
500 std::string l_filename = *it;
502 std::string l_tmpstr = f_emmcpath;
503 l_tmpstr.append(l_filename.c_str());
504 if (stat(l_tmpstr.c_str(), &st_buf) != -1) {
505 l_totalsize += st_buf.st_size;
508 if (l_totalsize > f_reqsize) {
514 if ((l_totalsize > f_reqsize) || (f_reqtype == eLoggerservicelogTypeAbnormal)
515 || (f_reqtype == eLoggerservicelogTypeGrpRelaunch)) {
516 for (it = vect.begin(); it != vect.end() && l_count > 0; it++) {
519 std::string l_filename = *it;
520 std::string l_tmpstr = f_emmcpath;
521 l_tmpstr.append(l_filename.c_str());
522 if (unlink(l_tmpstr.c_str()) != 0) {
523 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " unlink failed %s:%d.",
524 l_tmpstr.c_str(), errno);
526 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, " del-file=%s total=%d", l_tmpstr.c_str(),
535 " nothing to delete logs req-type=%d del-logtype=%d total=%d, log_count=%d",
536 f_reqtype, f_deltype, l_totalsize, l_count);
539 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
544 // LCOV_EXCL_START 200: can not be called
545 EFrameworkunifiedStatus CLoggerUtil::forceDeleteOldLog(std::string f_archive_destination,
547 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
548 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
549 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
550 std::string l_emmc_path;
551 size_t l_delsize = 0;
552 ELOGGERSERVICELOGTYPE l_logtype = eLoggerservicelogTypeOther;
554 size_t l_pos = f_archive_destination.find_last_of('/');
555 if (std::string::npos != l_pos) {
556 l_emmc_path = f_archive_destination.substr(0, l_pos);
557 l_emmc_path.append("/");
558 l_logtype = CLoggerUtil::QueryLoggerservicelogType(
559 f_archive_destination.substr(l_pos + 1,
560 f_archive_destination.size() - l_pos + 1));
563 if (l_logtype == eLoggerservicelogTypeOther) {
565 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Invalid Parameter. dest=%s",
566 f_archive_destination.c_str());
567 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
568 return eFrameworkunifiedStatusFail;
571 // remove dirty-file if exist
572 if (unlink(f_archive_destination.c_str()) != 0) {
573 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " unlink failed %s:%d.",
574 f_archive_destination.c_str(), errno);
578 l_delsize = deleteRequestLogs(l_emmc_path, l_logtype, f_req_size,
579 eLoggerservicelogTypeNormal);
580 if (l_delsize >= f_req_size) {
581 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
582 " delete normal logs success: req-size=%d, del-size=%d", f_req_size,
584 l_eStatus = eFrameworkunifiedStatusOK;
585 } else if (l_logtype == eLoggerservicelogTypeAbnormal) {
586 // delete abnormal log if request type is abnormal
587 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
588 " continue delete abnormal logs: req-size=%d, del-size=%d",
589 f_req_size, l_delsize);
590 size_t l_tmpsize = f_req_size;
591 l_tmpsize -= l_delsize;
592 l_delsize = deleteRequestLogs(l_emmc_path, l_logtype, l_tmpsize,
593 eLoggerservicelogTypeAbnormal);
594 if (l_delsize >= l_tmpsize) {
595 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
596 " delete abnormal logs success: req-size=%d, del-size=%d",
597 f_req_size, l_delsize);
598 l_eStatus = eFrameworkunifiedStatusOK;
600 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
601 " abnormal log delete not complete. req-size=%d, del-size=%d",
602 f_req_size, l_delsize);
604 } else if (l_logtype == eLoggerservicelogTypeGrpRelaunch) {
605 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
606 " continue delete group relaunch logs: req-size=%d, del-size=%d",
607 f_req_size, l_delsize);
608 size_t l_tmpsize = f_req_size;
609 l_tmpsize -= l_delsize;
610 l_delsize = deleteRequestLogs(l_emmc_path, l_logtype, l_tmpsize,
611 eLoggerservicelogTypeGrpRelaunch);
612 if (l_delsize >= l_tmpsize) {
613 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
614 " delete group relaunch logs success: req-size=%d, del-size=%d",
615 f_req_size, l_delsize);
616 l_eStatus = eFrameworkunifiedStatusOK;
619 ZONE_ERR, __FUNCTION__,
620 " group relaunch log delete not complete. req-size=%d, del-size=%d",
621 f_req_size, l_delsize);
624 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
625 " normal log del not complete. req-size=%d, del-size=%d", f_req_size,
629 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
634 EFrameworkunifiedStatus CLoggerUtil::deleteOldLog(std::string log_path,
635 std::vector<std::string>& l_vector,
636 std::string& f_archive_destination,
638 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
639 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
640 size_t l_pos = f_archive_destination.find_last_of('/');
641 if (std::string::npos != l_pos) { // LCOV_EXCL_BR_LINE 200: there is always '/' in f_destination
642 std::sort(l_vector.begin(), l_vector.end());
643 std::vector<std::string>::iterator itr = l_vector.begin();
644 for (UI_32 i = static_cast<UI_32>(l_vector.size()); (max_num - 1) < i; i--, itr++) {
645 if (itr == l_vector.end()) { // LCOV_EXCL_BR_LINE 200: (max_num - 1) can not be -1.
648 std::string l_FilePath = log_path;
649 std::string l_FileName = *itr;
650 l_FilePath.append("/");
651 l_FilePath.append(l_FileName.c_str());
652 if (0 != unlink(l_FilePath.c_str())) {
653 l_eStatus = eFrameworkunifiedStatusAccessError;
654 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. delete old log file %s:%d.",
655 l_FilePath.c_str(), errno);
660 // LCOV_EXCL_START 200: there is always '/' in f_destination
661 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
662 l_eStatus = eFrameworkunifiedStatusFail;
663 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. delete target not found. %s",
664 f_archive_destination.c_str());
667 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
671 EFrameworkunifiedStatus CLoggerUtil::deleteOldEmmcLog(std::string& f_archive_destination,
672 EErrorEventType type) {
673 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
675 std::vector<std::string> vect_abnrm; /* ILLEGAL RESET LOG INFO or ERROR EXIT LOG INFO */
676 std::vector<std::string> vect_nrm; /* NORMAL LOG INFO */
677 std::vector<std::string> vect_rlnc; /* RELAUNCH LOG INFO */
678 std::string l_emmc_path = m_pCfg->getEmmcOutputPath();
679 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
681 UI_32 abnrm_count = 0;
683 l_dirp = opendir(l_emmc_path.c_str());
684 if (l_dirp != NULL) { // LCOV_EXCL_BR_LINE 5: opendir's error case.
685 struct dirent l_dirent;
687 while (0 == readdir_r(l_dirp, &l_dirent, &next) && next != NULL) {
688 std::string l_findFileName = l_dirent.d_name;
690 // if ((std::string::npos != l_findFileName.find("_ILG_RESET.tar.gz"))
691 // || (std::string::npos != l_findFileName.find("_ERR.tar.gz"))) {
692 // vect_abnrm.push_back(l_findFileName);
693 if ((l_findFileName == ".") || (l_findFileName == "..")) {
695 } else if (std::string::npos != l_findFileName.find(SS_STORE_FILENAME_SYSILG_TERM)) {
696 vect_abnrm.push_back(l_findFileName);
697 } else if(std::string::npos != l_findFileName.find(SS_STORE_FILENAME__CWORD52__TERM)) { // LCOV_EXCL_BR_LINE 8: SS_STORE_FILENAME__CWORD52__TERM can not be set // NOLINT[whitespace/line_length]
698 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
699 vect_abnrm.push_back(l_findFileName); // LCOV_EXCL_LINE 8: SS_STORE_FILENAME_SYSILG_TERM can not be set // NOLINT[whitespace/line_length]
700 } else if((std::string::npos != l_findFileName.find("_ILG_RESET.tar.gz")) ||
701 (std::string::npos != l_findFileName.find("_ERR.tar.gz"))) {
702 vect_abnrm.push_back(l_findFileName);
705 } else if (std::string::npos
706 != l_findFileName.find("_GRP_RELAUNCH.tar.gz")) {
707 vect_rlnc.push_back(l_findFileName);
708 } else if (std::string::npos != l_findFileName.find(".tar.gz")) {
709 vect_nrm.push_back(l_findFileName);
716 case eErrorEventTypeProcessCrash:
717 case eErrorEventTypeProcessExit:
718 case eErrorEventTypeHeartBeatFailure:
719 case eErrorEventTypeSystemLowMemory:
720 case eErrorEventTypeBootMicroReset:
721 case eErrorEventTypeModConnFailed:
722 case eErrorEventTypeStartRespFailed:
723 case eErrorEventTypeModuleInvokedResetRequest:
725 // if ((UI_32) m_pCfg->m_emmcOutputErrMax <= vect_abnrm.size()) {
726 // l_eStatus = deleteOldLog(l_emmc_path, vect_abnrm, f_archive_destination,
727 // (UI_32) m_pCfg->m_emmcOutputErrMax);
728 if ((UI_32)m_pCfg->m_emmcOutputErrMax <= abnrm_count) {
729 l_eStatus = SS_LoggerStoreLogs_deleteOldLogAbnrm(l_emmc_path, vect_abnrm, f_archive_destination,
730 (UI_32)m_pCfg->m_emmcOutputErrMax, abnrm_count);
734 case eErrorEventTypeGroupRelaunch:
735 if ((UI_32) m_pCfg->m_emmcOutputGrpRelaunchMax <= vect_rlnc.size()) {
736 l_eStatus = deleteOldLog(l_emmc_path, vect_rlnc, f_archive_destination,
737 (UI_32) m_pCfg->m_emmcOutputGrpRelaunchMax);
741 if ((UI_32) m_pCfg->m_emmcOutputMax <= vect_nrm.size()) {
742 l_eStatus = deleteOldLog(l_emmc_path, vect_nrm, f_archive_destination,
743 (UI_32) m_pCfg->m_emmcOutputMax);
748 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
752 void CLoggerUtil::SetMilage(UI_32 f_Milage) {
756 std::string CLoggerUtil::GetUserInvokedFilename(HANDLE f_hApp, uint32_t f_time) {
757 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
758 std::string l_ret = "";
759 std::stringstream l_nameStream;
760 UI_32 l_seqNumber = 0;
762 EFrameworkunifiedStatus l_eStatus = m_pCfg->GetIncrementAndPersistUserInvokedCounter(
763 f_hApp, l_seqNumber);
764 LOG_STATUS_IF_ERRORED(
766 "GetIncrementAndPersistUserInvokedCounter()");
768 /* new counter value was not persisted if l_eStatus != eFrameworkunifiedStatusOK */
770 l_nameStream << std::setw(5) << std::setfill('0') << std::right << std::dec << l_seqNumber << '_';
771 l_nameStream << std::setw(8) << std::setfill('0') << std::right << std::dec << m_Milage << '_';
772 l_nameStream << std::setw(5) << std::setfill('0') << std::right << std::dec << m_bootCount << '_';
773 l_nameStream << std::setw(15) << GetTimeString(f_time) << ".tar.gz";
775 l_ret = l_nameStream.str();
777 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
781 std::string CLoggerUtil::GetEmmcFilename(uint32_t f_time) {
782 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
783 std::string l_ret = "";
784 std::stringstream l_nameStream;
787 m_pCfg->GetAndIncrementEmmcCounter(l_counter);
788 l_nameStream << std::setw(5) << std::setfill('0') << std::right << std::dec << l_counter << '_';
789 l_nameStream << std::setw(15) << this->GetTimeString(f_time) << ".tar.gz";
791 l_ret = l_nameStream.str();
793 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
797 // LCOV_EXCL_START 8: dead code
798 std::string CLoggerUtil::GetEmmcErrorFilename(uint32_t f_time) {
799 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
800 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
801 std::string l_ret = "";
802 std::stringstream l_nameStream;
805 m_pCfg->GetAndIncrementEmmcCounter(l_counter);
806 l_nameStream << std::setw(5) << std::setfill('0') << std::right << std::dec << l_counter << '_';
807 l_nameStream << std::setw(15) << this->GetTimeString(f_time) << "_ERR.tar.gz";
809 l_ret = l_nameStream.str();
811 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
816 // LCOV_EXCL_START 13:
817 std::string CLoggerUtil::GetEmmcNaviLogFilename(uint32_t f_time) {
818 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
819 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
820 std::string l_ret = "";
821 std::stringstream l_nameStream;
824 l_nameStream << std::setw(5) << std::setfill('0') << std::right << std::dec << l_counter << '_';
825 l_nameStream << std::setw(15) << this->GetTimeString(f_time) << ".log";
827 l_ret = l_nameStream.str();
829 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
834 std::string CLoggerUtil::GetTimeString(uint32_t f_time) {
835 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
836 std::string l_ret = "00000000_000000";
837 struct tm local_time;
838 Clock_getLocalTimeY2K38(&f_time, &local_time);
841 != strftime(buffer, sizeof(buffer), "%Y%m%d_%H%M%S", // LCOV_EXCL_BR_LINE 5: c code
846 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
850 void CLoggerUtil::SetUsbMountPath(std::string usbpath) {
851 strncpy(m_usbpath, usbpath.c_str(), USB_PATH_SIZE - 1);
852 m_usbpath[USB_PATH_SIZE - 1] = '\0';
855 EFrameworkunifiedStatus CLoggerUtil::PathCheckAndCopyFile(std::string f_source,
856 std::string f_destination) {
857 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
858 std::string::size_type ret;
860 ret = f_destination.find(m_usbpath);
861 l_eStatus = CopyFile(f_source, f_destination);
865 #endif // RELEASE_BUILD
866 /////////////////////////////////////////////////////////////////////////
867 ///// Static Functions
868 /////////////////////////////////////////////////////////////////////////
870 EFrameworkunifiedStatus CLoggerUtil::CopyFile(std::string f_source,
871 std::string f_destination) {
872 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
873 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
876 char l_buf[BUF_MAX_SIZE];
878 int l_if = open(f_source.c_str(), O_RDONLY | O_CLOEXEC, 0);
879 if (-1 == l_if) { // LCOV_EXCL_BR_LINE 5: open's error case.
880 // LCOV_EXCL_START 5: open's error case.
881 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
882 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "src open fail:%s,errno:%d,msg:%s",
883 f_source.c_str(), errno, strerror(errno));
884 l_eStatus = eFrameworkunifiedStatusFail;
887 bool isWebdav = false;
888 std::string l_tmpDest;
889 size_t l_pos = f_destination.find_last_of('/');
891 l_tmpDest = f_destination;
892 if (f_destination.find("/mnt/import") != std::string::npos) { // LCOV_EXCL_BR_LINE 13:
893 // if output to webdav's directory, don't create temporary file.
894 // because of being unable to rename the file on it.
898 int l_of = open(l_tmpDest.c_str(), O_WRONLY | O_CREAT | O_CLOEXEC, 0640);
899 if (-1 == l_of) { // LCOV_EXCL_BR_LINE 5: open's error case.
900 // LCOV_EXCL_START 5: open's error case.
901 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
902 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "dest open fail:%s,errno:%d,msg:%s",
903 l_tmpDest.c_str(), errno, strerror(errno));
904 l_eStatus = eFrameworkunifiedStatusFail;
908 l_nrd = read(l_if, l_buf, sizeof(l_buf));
909 if (l_nrd == -1) { // LCOV_EXCL_BR_LINE 5: read's error case.
910 // LCOV_EXCL_START 5: read's error case.
911 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
912 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "read fail:%s,errno:%d,msg:%s",
913 f_source.c_str(), errno, strerror(errno));
914 l_eStatus = eFrameworkunifiedStatusAccessError;
919 l_nwr = write(l_of, l_buf, l_nrd);
920 if (l_nwr == -1) { // LCOV_EXCL_BR_LINE 5: write's error case.
921 // LCOV_EXCL_START 5: write's error case.
922 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
923 if (ENOSPC == errno) {
924 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
925 "write fail(ENOSPC):%s,errno:%d,msg:%s", l_tmpDest.c_str(),
926 errno, strerror(errno));
927 l_eStatus = eFrameworkunifiedStatusErrNoEAGAIN;
929 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "write fail:%s,errno:%d,msg%s",
930 l_tmpDest.c_str(), errno, strerror(errno));
931 l_eStatus = eFrameworkunifiedStatusAccessError;
941 if (l_eStatus != eFrameworkunifiedStatusOK) { // LCOV_EXCL_BR_LINE 6: can not be fail
942 // LCOV_EXCL_START 6: can not be fail
943 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
950 struct stat istat_buf, ostat_buf;
952 ret = fstat(l_if, &istat_buf);
953 if (ret < 0) { // LCOV_EXCL_BR_LINE 5: fstat's error case.
954 // LCOV_EXCL_START 5: fstat's error case.
955 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
956 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. stat(%s). errno: %d, %s",
957 f_source.c_str(), errno, strerror(errno));
961 ret = stat(l_tmpDest.c_str(), &ostat_buf);
962 if (ret < 0) { // LCOV_EXCL_BR_LINE 5: stat's error case.
963 // LCOV_EXCL_START 5: stat's error case.
964 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
965 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. stat(%s). errno: %d, %s",
966 l_tmpDest.c_str(), errno, strerror(errno));
970 if (ostat_buf.st_size >= istat_buf.st_size) { // LCOV_EXCL_BR_LINE 5: read and write can not fail, so the size is same // NOLINT[whitespace/line_length]
973 usleep(10000); // interval
980 if (!isWebdav) { // LCOV_EXCL_BR_LINE 6: isWebdav is aways false
981 if (rename(l_tmpDest.c_str(), f_destination.c_str()) != 0) { // LCOV_EXCL_BR_LINE 5: rename's error case.
982 // LCOV_EXCL_START 5: rename's error case.
983 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
984 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "rename %s to %s fail,errno:%d,msg:%s",
985 l_tmpDest.c_str(), f_destination.c_str(), errno, strerror(errno));
990 if (std::string::npos != l_pos) { // LCOV_EXCL_BR_LINE 200: there is always '/' in f_destination
991 std::string l_destPath = f_destination.substr(0, l_pos);
994 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
995 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "dest invalid:%s", f_destination.c_str()); // LCOV_EXCL_LINE 200: there is always '/' in f_destination // NOLINT[whitespace/line_length]
999 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1003 // LCOV_EXCL_START 8: can not be called
1004 EFrameworkunifiedStatus CLoggerUtil::CopyUntyped(std::string f_source,
1005 std::string f_destination) {
1006 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1007 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1008 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1011 if (0 != access(f_source.c_str(), F_OK)) {
1012 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1013 " Error. The specified file path and name does not exist: %s",
1015 } else if (0 != (l_statRetVal = lstat(f_source.c_str(), &l_stat))) {
1016 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1017 " Error. stat() for file or directory returned error: %s -> %d",
1018 f_source.c_str(), l_statRetVal);
1019 } else if (0 != S_ISDIR(l_stat.st_mode)) {
1020 l_eStatus = CopyDirectory(f_source, f_destination);
1021 } else if (0 != S_ISLNK(l_stat.st_mode)) {
1022 // avoid duplicate copy for eErrorEventTypeInterfaceunifiedEmmcLogs: /nv/log/awlog -> /nv/BS/ss/logger_service/rwdata/log2/awlog
1023 if (f_source.find("/nv/BS/ss/logger_service/rwdata/awlog") == std::string::npos) {
1024 l_eStatus = CopyDirectory(f_source, f_destination);
1026 } else if (0 != S_ISREG(l_stat.st_mode)) {
1027 #ifdef RELEASE_BUILD
1028 l_eStatus = PathCheckAndCopyFile(f_source, f_destination);
1030 l_eStatus = CopyFile(f_source, f_destination);
1031 #endif // RELEASE_BUILD
1033 FRAMEWORKUNIFIEDLOG(
1036 " Error. specified file may be a symbolic link or other non 'regular' type. File: %s, mode: 0x%04X.",
1037 f_source.c_str(), l_stat.st_mode);
1039 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1044 // LCOV_EXCL_START 8: can not be called
1045 EFrameworkunifiedStatus CLoggerUtil::CopyDirectory(std::string f_source,
1046 std::string f_destination) {
1047 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1048 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1049 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1050 DIR * l_pDir = opendir(f_source.c_str());
1052 if (l_pDir == NULL) {
1053 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Could not open directory: %s",
1056 if (mkdir(f_destination.c_str(), 0775) == -1) {
1057 if (errno == EEXIST) {
1058 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Directory: %s already exists.",
1059 f_destination.c_str());
1061 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1062 "Could not create directory: %s. Errno: %s",
1063 f_destination.c_str(), strerror(errno));
1064 l_eStatus = eFrameworkunifiedStatusFail;
1067 SyncDir(f_destination);
1068 size_t l_pos = f_destination.find_last_of('/');
1069 if (l_pos != std::string::npos) {
1070 std::string l_destPath = f_destination.substr(0, l_pos);
1071 SyncDir(l_destPath);
1075 struct dirent l_pDirent;
1076 struct dirent* next;
1077 while (0 == readdir_r(l_pDir, &l_pDirent, &next) && next != NULL) {
1078 if ((0 != strcmp(l_pDirent.d_name, ".")) && /* Ignore special . directory. */
1079 (0 != strcmp(l_pDirent.d_name, "..")) && /* Ignore special .. directory. */
1080 (0 != strcmp(l_pDirent.d_name, "lost+found")) && /* Ignore lost+found. */
1081 ('.' != l_pDirent.d_name[0])) { /* Ignore hidden files */
1082 std::string l_fileSource = f_source;
1083 std::string l_fileDestination = f_destination;
1084 l_fileSource.append("/");
1085 l_fileSource.append(l_pDirent.d_name);
1086 l_fileDestination.append("/");
1087 l_fileDestination.append(l_pDirent.d_name);
1088 l_eStatus = CopyUntyped(l_fileSource, l_fileDestination);
1094 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1099 // LCOV_EXCL_START 8: can not be called
1100 EFrameworkunifiedStatus CLoggerUtil::MoveFile(std::string f_source,
1101 std::string f_destination) {
1102 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1103 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1104 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1105 #ifdef RELEASE_BUILD
1106 l_eStatus = CLoggerUtil::PathCheckAndCopyFile(f_source, f_destination);
1107 LOG_STATUS_IF_ERRORED(l_eStatus, "CLoggerUtil::PathCheckAndCopyFile()");
1109 l_eStatus = CLoggerUtil::CopyFile(f_source, f_destination);
1110 LOG_STATUS_IF_ERRORED(l_eStatus, "CLoggerUtil::CopyFile()");
1111 #endif // RELEASE_BUILD
1112 if (eFrameworkunifiedStatusOK == l_eStatus) {
1113 l_eStatus = (0 == remove(f_source.c_str())) ? eFrameworkunifiedStatusOK : eFrameworkunifiedStatusFail;
1114 if (l_eStatus == eFrameworkunifiedStatusOK) {
1115 size_t l_pos = f_source.find_last_of('/');
1116 if (std::string::npos != l_pos) {
1117 std::string l_emmc_path = f_source.substr(0, l_pos);
1118 SyncDir(l_emmc_path);
1122 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1127 // LCOV_EXCL_START 8: can not be called
1128 EFrameworkunifiedStatus CLoggerUtil::MoveUntyped(std::string f_source,
1129 std::string f_destination) {
1130 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1131 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1132 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
1135 if (0 != access(f_source.c_str(), F_OK)) {
1136 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1137 " Error. The specified file path and name does not exist: %s",
1139 } else if (0 != (l_statRetVal = stat(f_source.c_str(), &l_stat))) {
1140 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1141 " Error. stat() for file or directory returned error: %s -> %d",
1142 f_source.c_str(), l_statRetVal);
1143 } else if (0 != S_ISDIR(l_stat.st_mode)) {
1144 l_eStatus = CLoggerUtil::MoveDirectory(f_source, f_destination);
1145 LOG_STATUS_IF_ERRORED(
1146 l_eStatus, "CLoggerUtil::MoveDirectory(f_source, f_destination);");
1147 } else if (0 != S_ISREG(l_stat.st_mode)) {
1148 l_eStatus = CLoggerUtil::MoveFile(f_source, f_destination);
1149 LOG_STATUS_IF_ERRORED(l_eStatus,
1150 "CLoggerUtil::MoveFile(f_source, f_destination)");
1152 FRAMEWORKUNIFIEDLOG(
1155 " Error. specified file may be a symbolic link or other non 'regular' type. File: %s, mode: 0x%04X.",
1156 f_source.c_str(), l_stat.st_mode);
1158 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1163 // LCOV_EXCL_START 8: can not be called
1164 EFrameworkunifiedStatus CLoggerUtil::MoveDirectory(std::string f_source,
1165 std::string f_destination) {
1166 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1167 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
1168 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
1169 DIR * l_pDir = opendir(f_source.c_str());
1171 if (l_pDir == NULL) {
1172 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Could not open directory: %s",
1174 l_eStatus = eFrameworkunifiedStatusFail;
1177 if (mkdir(f_destination.c_str(), 0666) == -1) {
1178 if (errno == EEXIST) {
1179 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "Directory: %s already exists.",
1180 f_destination.c_str());
1182 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
1183 "Could not create directory: %s. Errno: %s",
1184 f_destination.c_str(), strerror(errno));
1185 l_eStatus = eFrameworkunifiedStatusFail;
1189 SyncDir(f_destination);
1190 size_t l_pos = f_destination.find_last_of('/');
1191 if (l_pos != std::string::npos) {
1192 std::string l_destPath = f_destination.substr(0, l_pos);
1193 SyncDir(l_destPath);
1197 if (eFrameworkunifiedStatusOK == l_eStatus) { /* if directory already exists or has been newly created */
1198 struct dirent l_pDirent;
1199 struct dirent* next;
1201 while (0 == readdir_r(l_pDir, &l_pDirent, &next) && next != NULL) {
1202 if ((0 != strcmp(l_pDirent.d_name, ".")) && /* Ignore special . directory. */
1203 (0 != strcmp(l_pDirent.d_name, "..")) && /* Ignore special .. directory. */
1204 (0 != strcmp(l_pDirent.d_name, "lost+found")) && /* Ignore lost+found. */
1205 ('.' != l_pDirent.d_name[0])) { /* Ignore hidden files */
1206 std::string l_fileSource = f_source;
1207 std::string l_fileDestination = f_destination;
1208 l_fileSource.append("/");
1209 l_fileSource.append(l_pDirent.d_name);
1210 l_fileDestination.append("/");
1211 l_fileDestination.append(l_pDirent.d_name);
1212 l_eStatus = MoveUntyped(l_fileSource, l_fileDestination);
1219 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
1224 // LCOV_EXCL_START 200: can not be called
1225 ELOGGERSERVICELOGTYPE CLoggerUtil::QueryLoggerservicelogType(std::string f_logname) {
1226 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1227 // if (f_logname.find("_ILG_RESET.tar.gz") != std::string::npos
1228 if (f_logname.find(SS_STORE_FILENAME_SYSILG_TERM) != std::string::npos) {
1229 return eLoggerservicelogTypeAbnormal;
1230 } else if (f_logname.find(SS_STORE_FILENAME__CWORD52__TERM) != std::string::npos) {
1231 return eLoggerservicelogTypeAbnormal;
1232 } else if (f_logname.find("_ILG_RESET.tar.gz") != std::string::npos
1234 || f_logname.find("_ERR.tar.gz") != std::string::npos) {
1235 return eLoggerservicelogTypeAbnormal;
1236 } else if (f_logname.find("_GRP_RELAUNCH.tar.gz") != std::string::npos) {
1237 return eLoggerservicelogTypeGrpRelaunch;
1238 } else if (f_logname.find(".tar.gz") != std::string::npos) {
1239 return eLoggerservicelogTypeNormal;
1241 return eLoggerservicelogTypeOther;
1246 void CLoggerUtil::SyncDir(std::string f_dir_path) {
1247 int fd = open(f_dir_path.c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC);
1248 #define OPE_ERR_MSG "%s %s failed. errno:%d,msg:%s"
1249 if (fd == -1) { // LCOV_EXCL_BR_LINE 5: open's error case.
1250 // LCOV_EXCL_START 5: open's error case.
1251 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1252 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, OPE_ERR_MSG, f_dir_path.c_str(), "open",
1253 errno, strerror(errno));
1256 if (fsync(fd) == -1) { // LCOV_EXCL_BR_LINE 5: open's error case.
1257 // LCOV_EXCL_START 5: open's error case.
1258 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1259 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, OPE_ERR_MSG, f_dir_path.c_str(), "fsync",
1260 errno, strerror(errno));
1263 if (close(fd) == -1) { // LCOV_EXCL_BR_LINE 5: open's error case.
1264 // LCOV_EXCL_START 5: open's error case.
1265 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
1266 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, OPE_ERR_MSG, f_dir_path.c_str(), "close",
1267 errno, strerror(errno));