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
21 ///////////////////////////////////////////////////////////////////////////////
22 ///////////////////////////////////////////////////////////////////////////////
24 ///////////////////////////////////////////////////////////////////////////////
25 #include "ss_logger_error_event_storage.h"
33 #include "ss_logger_util.h"
34 #include "ss_logger_error_event_archive.h"
35 #include "ss_logger_fs_directory.h"
36 #include "ss_logger_common.h"
38 CLoggerErrorEventStorage::CLoggerErrorEventStorage()
39 : m_parentMcQueue(NULL),
47 m_responseVec.clear();
48 m_mqattr.mq_flags = 0;
49 m_mqattr.mq_maxmsg = 1;
50 m_mqattr.mq_msgsize = 32;
51 m_mqattr.mq_curmsgs = 0;
54 CLoggerErrorEventStorage::~CLoggerErrorEventStorage() { // LCOV_EXCL_START 14:globle instance
55 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
60 EFrameworkunifiedStatus CLoggerErrorEventStorage::Initialize(HANDLE f_hApp,
61 std::string f_ParentName,
62 CLoggerCfg *f_pLoggerCfg) {
63 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
64 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
65 pthread_attr_t l_attr;
66 struct sched_param l_params;
69 if (NULL == (m_pLoggerCfg = f_pLoggerCfg)) { // LCOV_EXCL_BR_LINE 200:As it is not always NULL
70 // LCOV_EXCL_START 200:As it is not always NULL
71 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
72 l_eStatus = eFrameworkunifiedStatusNullPointer;
73 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. Parameter f_pLoggerCfg is NULL.");
75 } else if (eFrameworkunifiedStatusOK != (l_eStatus = m_pLoggerCfg->GetLoggerStorageInfo(m_loggerStorageInfo))) { // LCOV_EXCL_BR_LINE 200:To ensure success // NOLINT[whitespace/line_length]
76 // LCOV_EXCL_START 200:To ensure success
77 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
78 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
79 " Error. GetLoggerStorageInfo(m_loggerStorageInfo)");
81 } else if (NULL == (m_parentMcQueue = McOpenSender(f_ParentName.c_str()))) { // LCOV_EXCL_BR_LINE 4:NSFW
82 // LCOV_EXCL_START 4:NSFW
83 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
84 l_eStatus = eFrameworkunifiedStatusErrOther;
85 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. McOpenSender(f_ParentName)");
87 } else if (-1 == (this->m_sendQueue = mq_open(m_loggerStorageInfo.Name.c_str(), O_CREAT | O_WRONLY, 0666, &m_mqattr))) { // LCOV_EXCL_BR_LINE 5:C code eror // NOLINT[whitespace/line_length]
88 // LCOV_EXCL_START 5:C code eror
89 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
90 l_eStatus = eFrameworkunifiedStatusErrOther;
94 " Error. mq_open(ERROR_EVENT_STORAGE_QUEUE_NAME,O_CREAT | O_WRONLY, 0666, NULL)");
96 } else if (-1 == (this->m_receiveQueue = mq_open(m_loggerStorageInfo.Name.c_str(), O_RDONLY))) { // LCOV_EXCL_BR_LINE 5:C code eror // NOLINT[whitespace/line_length]
97 // LCOV_EXCL_START 5:C code eror
98 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
99 l_eStatus = eFrameworkunifiedStatusSessionLimitMaxedOut;
100 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
101 " Error. mq_open(ERROR_EVENT_STORAGE_QUEUE_NAME,O_RDONLY)");
103 } else if (EOK != (m_mutexInit = pthread_mutex_init(&this->m_mutex, NULL))) { // LCOV_EXCL_BR_LINE 5:C code eror
104 // LCOV_EXCL_START 5:C code eror
105 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
106 l_eStatus = eFrameworkunifiedStatusFail;
107 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
108 " Error. pthread_mutex_init(&this->m_mutex, NULL)");
110 } else if (EOK != pthread_attr_init(&l_attr)) { // LCOV_EXCL_BR_LINE 5:C code eror
111 // LCOV_EXCL_START 5:C code eror
112 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
113 l_eStatus = eFrameworkunifiedStatusSemUnlockFail;
114 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. pthread_attr_init()");
116 } else if (EOK != pthread_attr_getschedparam(&l_attr, &l_params)) { // LCOV_EXCL_BR_LINE 5:C code eror
117 // LCOV_EXCL_START 5:C code eror
118 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
119 l_eStatus = eFrameworkunifiedStatusSemCloseFail;
120 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. pthread_attr_getschedparam()");
123 l_params.sched_priority = m_loggerStorageInfo.Priority;
124 if (EOK != pthread_attr_setinheritsched(&l_attr, PTHREAD_EXPLICIT_SCHED)) { // LCOV_EXCL_BR_LINE 5:C code eror
125 // LCOV_EXCL_START 5:C code eror
126 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
127 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. pthread_attr_setinheritsched()");
129 } else if (EOK != pthread_attr_setschedparam(&l_attr, &l_params)) { // LCOV_EXCL_BR_LINE 5:C code eror
130 l_eStatus = eFrameworkunifiedStatusDbResultError;
134 " Error but continue. pthread_attr_setschedparam(), priority = %d: %s",
135 m_loggerStorageInfo.Priority, strerror(errno)); // LCOV_EXCL_BR_LINE 11:Unexpected branch
136 l_eStatus = eFrameworkunifiedStatusOK;
138 if (EOK != pthread_create(&this->m_thread, &l_attr, &CLoggerErrorEventStorage::ThreadFunctionWrapper, this)) { // LCOV_EXCL_BR_LINE 5:C code eror // NOLINT[whitespace/line_length]
139 // LCOV_EXCL_START 5:C code eror
140 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
141 l_eStatus = eFrameworkunifiedStatusDbRecNotFound;
142 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. pthread_create()");
145 l_eStatus = eFrameworkunifiedStatusOK;
148 if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 200:To ensure success
149 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
150 this->Cleanup(); // LCOV_EXCL_LINE 200:To ensure success
153 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %d", l_eStatus);
157 EFrameworkunifiedStatus CLoggerErrorEventStorage::Start(
158 std::string f_target, TArtifactResponseVec f_responseVector,
160 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
161 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
162 /* Start the thread*/
163 if (EOK == pthread_mutex_lock(&this->m_mutex)) { // LCOV_EXCL_BR_LINE 200:To ensure success
164 this->m_destination = f_target;
165 this->m_responseVec = f_responseVector;
166 this->m_logTime = f_time;
167 (void) pthread_mutex_unlock(&this->m_mutex);
169 UI_8 l_cmd[MAX_QUEUE_MSG_SIZE];
171 if (-1 == mq_send(this->m_sendQueue, reinterpret_cast<CHAR*>(l_cmd), m_mqattr.mq_msgsize, 0)) {
172 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
173 " Error. mq_send(this->m_sendQueue %d) return %s", m_sendQueue,
175 l_eStatus = eFrameworkunifiedStatusFail;
178 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-: %d", l_eStatus);
182 void CLoggerErrorEventStorage::ThreadFunction(void) {
183 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
184 char l_data[MAX_QUEUE_MSG_SIZE] = { };
185 SI_32 l_bytesRead = -1;
187 ELoggerStorageThreadCommands l_cmdId = eLoggerStorageThreadCmdWriteFailed;
188 EFrameworkunifiedStatus l_eStatus;
190 (void) pthread_setname_np(pthread_self(), ERROR_EVENT_STORAGE_QUEUE_NAME);
192 pthread_cleanup_push(&CLoggerErrorEventStorage::CleanupWrapper, this);
193 while (-1 // LCOV_EXCL_BR_LINE 200: mq_send can not send size of -1
195 static_cast<SI_32>(mq_receive(this->m_receiveQueue, reinterpret_cast<char *>(l_data),
196 (size_t) m_mqattr.mq_msgsize, NULL)))) {
197 std::string l_target;
198 TArtifactResponseVec l_responseVec;
201 Clock_getSystemTimeY2K38(&l_logTime, &status);
202 (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &l_oldState);
203 if (EOK == pthread_mutex_lock(&this->m_mutex)) { // LCOV_EXCL_BR_LINE 5: pthread_mutex_lock's error case.
204 l_target = this->m_destination;
205 l_responseVec = this->m_responseVec;
206 l_logTime = this->m_logTime;
207 this->m_responseVec.clear();
208 this->m_destination = "";
210 (void) pthread_mutex_unlock(&this->m_mutex);
212 (void) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &l_oldState);
213 if (access(l_target.c_str(), F_OK) == 0) {
214 if (CFSDirectory::IsDirectory(l_target)) { // LCOV_EXCL_BR_LINE 6: can not be a dir
215 // LCOV_EXCL_START 6: new file create, it can not be find
216 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
217 BOOL isDeleteFiles = FALSE;
218 SI_32 l_filesCopied = this->CopyFiles(l_target, l_responseVec,
221 switch (l_filesCopied) {
223 /*Error while moving files*/
224 l_cmdId = eLoggerStorageThreadCmdWriteFailed;
227 /*No files where moved*/
228 l_cmdId = eLoggerStorageThreadCmdNoWritten;
231 if (l_filesCopied > 0) {
232 l_cmdId = eLoggerStorageThreadCmdOK;
233 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
234 " Info. %d files successfully copied.", l_filesCopied);
241 if (eFrameworkunifiedStatusOK
242 != (l_eStatus = this->PackageAndPlaceArtifacts(l_target,
246 l_cmdId = eLoggerStorageThreadCmdWriteFailed;
248 l_cmdId = eLoggerStorageThreadCmdOK;
249 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
250 " Info. Archive successfully written.");
252 if (eFrameworkunifiedStatusOK != RemoveDeprecatedArtifacts(l_responseVec)) {
254 ZONE_WARN, __FUNCTION__,
255 " Warning. Wasn't able to delete all deprecated log artifacts.");
259 std::string l_usb_path;
260 size_t l_usb_path_length = 0;
261 if (m_pLoggerCfg != NULL) { // LCOV_EXCL_BR_LINE 6: m_pLoggerCfg can not be null
262 l_usb_path = m_pLoggerCfg->getUsb0MountPath();
263 l_usb_path_length = l_usb_path.length();
264 if ((l_usb_path_length > 1)
265 && (l_usb_path[l_usb_path.length() - 1] == '/')) {
269 if ((l_usb_path_length > 0)
270 && (l_target.compare(0, l_usb_path_length, l_usb_path, 0,
271 l_usb_path_length) != 0)) {
272 l_usb_path_length = 0;
274 if ((l_usb_path_length == 0)
275 && (l_target.compare(0, sizeof(DEBUG_USB_PATH) - 1, DEBUG_USB_PATH, 0,
276 sizeof(DEBUG_USB_PATH) - 1) == 0)) {
277 l_usb_path = DEBUG_USB_PATH;
278 l_usb_path_length = sizeof(DEBUG_USB_PATH) - 1;
280 if (l_usb_path_length > 1) { // if USB path is '/' only, length is 1.
281 // So conditions to be syncfs is greater than 1
283 DIR* l_dirp = opendir(l_usb_path.c_str());
284 if (l_dirp != NULL) { // LCOV_EXCL_BR_LINE 5: c code error case
285 int fd = dirfd(l_dirp);
286 if (fd != -1) { // LCOV_EXCL_BR_LINE 5: c code error case
287 if (syncfs(fd) == -1) {
288 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
289 " Error. syncfs failed path=%s [%s]", l_usb_path.c_str(),
293 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
294 " Error. syncfs get fd failed path=%s, [%s]",
295 l_usb_path.c_str(), strerror(errno));
299 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
300 " Error. syncfs opendir failed path=%s, [%s]",
301 l_usb_path.c_str(), strerror(errno));
304 #define USB_MEMORY_SYNC_WAITTIME 8 // 8 sec
305 const struct timespec intval = { USB_MEMORY_SYNC_WAITTIME, 0 };
306 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
307 "%d sec:Waiting for USB Memory Synchronization.(%s)",
308 USB_MEMORY_SYNC_WAITTIME, l_usb_path.c_str());
309 nanosleep(&intval, NULL);
312 if (eFrameworkunifiedStatusOK
313 != McSend(this->m_parentMcQueue, m_loggerStorageInfo.Name.c_str(),
315 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. McSend(this->m_parentMcQueue)");
318 pthread_cleanup_pop(1);
319 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
322 void CLoggerErrorEventStorage::Cleanup(void) {
323 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
324 if (-1 != this->m_receiveQueue) { // LCOV_EXCL_BR_LINE 200: m_receiveQueue cam not be -1
325 if (-1 == mq_close(this->m_receiveQueue)) {
326 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. mq_close()");
328 this->m_receiveQueue = -1;
330 if (-1 != this->m_sendQueue) { // LCOV_EXCL_BR_LINE 200: m_sendQueue cam not be -1
331 if (-1 == mq_close(this->m_sendQueue)) {
332 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. mq_close()");
334 this->m_sendQueue = -1;
335 if (-1 == mq_unlink(m_loggerStorageInfo.Name.c_str())) {
336 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. mq_unlink()");
340 if (-1 != m_mutexInit) { // LCOV_EXCL_BR_LINE 200: m_mutexInit cam not be -1
341 if (EOK != pthread_mutex_destroy(&this->m_mutex)) { // LCOV_EXCL_BR_LINE 5: c code error case
342 // LCOV_EXCL_START 5: c code error case
343 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
344 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. mq_unlink()");
350 if (NULL != m_parentMcQueue) { // LCOV_EXCL_BR_LINE 200: m_parentMcQueue cam not be null
351 if (eFrameworkunifiedStatusOK != McClose(m_parentMcQueue)) {
352 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. McClose()");
354 this->m_parentMcQueue = NULL;
356 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
359 void* CLoggerErrorEventStorage::ThreadFunctionWrapper(void* param) {
360 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
361 CLoggerErrorEventStorage* l_pObj =
362 reinterpret_cast<CLoggerErrorEventStorage *>(param);
364 l_pObj->ThreadFunction();
365 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
369 void CLoggerErrorEventStorage::CleanupWrapper(void* param) {
370 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
371 CLoggerErrorEventStorage* l_pObj =
372 reinterpret_cast<CLoggerErrorEventStorage *>(param);
375 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
378 ///////////////////////////////////////////////////////////////////////////
379 // Function : PackageAndPlaceArtifacts
380 // brief : This function creates an archive for all collected artifacts
381 // and places the archive in the required location depending
382 // on the event type and required naming criteria.
383 ///////////////////////////////////////////////////////////////////////////
384 EFrameworkunifiedStatus CLoggerErrorEventStorage::PackageAndPlaceArtifacts(
385 std::string f_archiveDestination, TArtifactResponseVec &f_responseVector,
386 uint32_t f_logTime) {
387 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
388 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
389 std::string l_coreFileName = "";
392 if (f_archiveDestination.size() == 0) {
396 " Error. Unknown package file path and name. Logging artifacts not stored!");
397 l_eStatus = eFrameworkunifiedStatusFail;
399 CErrorEventArchive l_archiver;
400 l_eStatus = l_archiver.openArchive(f_archiveDestination);
401 if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 6: it can not be fail
402 // LCOV_EXCL_START 6: it can not be fail
403 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
407 " Error. Failed to create logging archive: %s. Log archive will not be stored!",
408 f_archiveDestination.c_str());
411 for (UI_32 i = 0; (i < f_responseVector.size()); i++) {
412 if (f_responseVector[i].Filepath != std::string("")) {
413 std::string l_destName = f_responseVector[i].Filepath;
415 if ((f_responseVector[i].Filepath.find(".bmp") // LCOV_EXCL_BR_LINE 200: no bmp file be set
416 == f_responseVector[i].Filepath.find_last_of('.'))
417 && (f_responseVector[i].Filepath.find(".bmp")
418 != std::string::npos)) {
419 // LCOV_EXCL_START 200: no bmp file be set
420 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
422 struct tm local_time;
423 Clock_getLocalTimeY2K38(&f_logTime, &local_time);
425 != strftime(buffer, sizeof(buffer), "%Y%m%d%H%M%S.bmp",
431 l_destName = f_responseVector[i].Filepath.substr(
432 f_responseVector[i].Filepath.find_last_of('/') + 1);
434 if (f_responseVector[i].ArtifactId == eArtifactIdPstoreLog) { // LCOV_EXCL_BR_LINE 200: can not be eArtifactIdPstoreLog // NOLINT[whitespace/line_length]
435 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
436 l_destName = KERNEL_LOG_PATH_DIR; // LCOV_EXCL_LINE 200: can not be eArtifactIdPstoreLog
438 l_eStatus = l_archiver.addToArchive(f_responseVector[i].Filepath,
440 if (eFrameworkunifiedStatusOK != l_eStatus) { // LCOV_EXCL_BR_LINE 200: can not be fail
441 // LCOV_EXCL_START 200: can not be fail
442 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
446 " Error. Failed to add artifact: %s to archive %s. Continuing with next artifact.",
447 f_responseVector[i].Filepath.c_str(),
448 f_archiveDestination.c_str());
452 if ((l_ret % m_loggerStorageInfo.TimeoutAfter) == 0) {
453 usleep(m_loggerStorageInfo.Timeout);
458 if (eFrameworkunifiedStatusOK != l_archiver.closeArchive()) { // LCOV_EXCL_BR_LINE 200: closeArchive can not be fail
459 // LCOV_EXCL_START 200: closeArchive can not be fail
460 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
461 l_eStatus = eFrameworkunifiedStatusFail;
462 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, " Error. l_archiver.closeArchive()");
465 // Cleanup artifacts that are no longer required.
466 int rc = access(f_archiveDestination.c_str(), F_OK);
467 if (0 != rc) { // LCOV_EXCL_BR_LINE 5: f_archiveDestination is aways exist
468 // LCOV_EXCL_START 5: f_archiveDestination is aways exist
469 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
470 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
471 " Error. Archive verification failed. Errno: %d, %s.", errno,
473 l_eStatus = eFrameworkunifiedStatusFail;
477 " Error Event: A archive successfully written to: %s.",
478 f_archiveDestination.c_str());
479 l_eStatus = eFrameworkunifiedStatusOK;
485 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
489 ///////////////////////////////////////////////////////////////////////////////////////////
490 ///////////////////////////////////////////////////////////////////////////////////////////
493 /// isDeleteFiles : TRUE - delete original files after copy.
494 /// FALSE - not delete after copy.
496 /// -1: error while writing
497 /// else, number of files written
498 ///////////////////////////////////////////////////////////////////////////////////////////
499 ///////////////////////////////////////////////////////////////////////////////////////////
500 // LCOV_EXCL_START 8: can not be called
501 SI_32 CLoggerErrorEventStorage::CopyFiles(
502 std::string f_destination, TArtifactResponseVec &f_responseVector,
503 BOOL isDeleteFiles) {
504 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
505 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
507 BOOL l_isFaile = FALSE;
508 for (UI_32 i = 0; i < f_responseVector.size(); i++) {
509 if (f_responseVector[i].Filepath != "") {
510 if (CFSDirectory::IsDirectory(f_responseVector[i].Filepath)) {
511 DIR * l_pDir = opendir(f_responseVector[i].Filepath.c_str());
512 if (l_pDir == NULL) {
513 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Could not open directory: %s",
514 f_responseVector[i].Filepath.c_str());
516 struct dirent l_pDirent;
518 while (0 == readdir_r(l_pDir, &l_pDirent, &next) && next != NULL) {
519 if ((0 != strcmp(l_pDirent.d_name, ".")) && /* Ignore special . directory. */
520 (0 != strcmp(l_pDirent.d_name, "..")) && /* Ignore special .. directory. */
521 (0 != strcmp(l_pDirent.d_name, "lost+found")) && /* Ignore lost+found. */
522 ('.' != l_pDirent.d_name[0])) { /* Ignore hidden files */
523 std::string l_fileSource = f_responseVector[i].Filepath;
524 std::string l_fileDestination = f_destination;
525 l_fileSource.append("/");
526 l_fileSource.append(l_pDirent.d_name);
527 l_fileDestination.append("/");
528 l_fileDestination.append(l_pDirent.d_name);
529 EFrameworkunifiedStatus loggerserviceRet = eFrameworkunifiedStatusOK;
530 if (isDeleteFiles == TRUE) {
531 loggerserviceRet = CLoggerUtil::MoveUntyped(l_fileSource,
534 loggerserviceRet = CLoggerUtil::CopyUntyped(l_fileSource,
538 if (eFrameworkunifiedStatusOK == loggerserviceRet) {
540 if ((l_ret % m_loggerStorageInfo.TimeoutAfter) == 0) {
541 usleep(m_loggerStorageInfo.Timeout);
545 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Could not move: %s",
546 l_fileSource.c_str());
550 (void) closedir(l_pDir);
553 std::string l_filename = f_responseVector[i].Filepath.substr(
554 f_responseVector[i].Filepath.find_last_of('/'));
555 std::string l_destination = std::string(f_destination).append(
557 if (eFrameworkunifiedStatusOK
558 == CLoggerUtil::MoveUntyped(f_responseVector[i].Filepath,
561 if ((l_ret % m_loggerStorageInfo.TimeoutAfter) == 0) {
562 usleep(m_loggerStorageInfo.Timeout);
565 FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Could not move: %s",
566 f_responseVector[i].Filepath.c_str());
574 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
579 EFrameworkunifiedStatus CLoggerErrorEventStorage::RemoveDeprecatedArtifacts(
580 TArtifactResponseVec &f_responseVector) {
581 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
582 EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
583 BOOL l_success = TRUE;
584 for (UI_32 i = 0; i < f_responseVector.size(); i++) {
585 if ((f_responseVector[i].Filepath != "")
586 && (TRUE == f_responseVector[i].Remove)) {
587 if (CFSDirectory::IsDirectory(f_responseVector[i].Filepath)) {
589 != CFSDirectory::RemoveDirectory(f_responseVector[i].Filepath)) {
590 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
591 " Warning. Directory %s failed to be deleted.",
592 f_responseVector[i].Filepath.c_str());
595 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
596 " Info. Directory %s has been successfully deleted.",
597 f_responseVector[i].Filepath.c_str());
602 if (0 != remove(f_responseVector[i].Filepath.c_str())) { // LCOV_EXCL_BR_LINE 5: c code error case
603 // LCOV_EXCL_START 5: c code error case
604 AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert
605 if (errno == ENOENT) {
606 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
607 " Info. %s not available. Skipping file deletion.",
608 f_responseVector[i].Filepath.c_str());
610 FRAMEWORKUNIFIEDLOG(ZONE_WARN, __FUNCTION__,
611 " Warning. File %s failed to be deleted.",
612 f_responseVector[i].Filepath.c_str());
618 FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
619 " Info. File %s has been successfully deleted.",
620 f_responseVector[i].Filepath.c_str());
625 l_eStatus = (l_success == TRUE) ? eFrameworkunifiedStatusOK : eFrameworkunifiedStatusFail;
626 FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");