summaryrefslogtreecommitdiffstats
path: root/logger_service/server/src/ss_logger_error_event_responses.cpp
blob: ec8bbd483ec0eb6bc6ab50f753e5c1ab92fd5a08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
/*
 * @copyright Copyright (c) 2016-2019 TOYOTA MOTOR CORPORATION.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

///////////////////////////////////////////////////////////////////////////////
/// \ingroup  tag_SS_LoggerService
/// \brief    This file supports error event logging.
///
///////////////////////////////////////////////////////////////////////////////
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include <boost/bind.hpp>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/klog.h>
#include <native_service/frameworkunified_framework_if.h>
#include <native_service/frameworkunified_multithreading.h>
#include <native_service/ns_sharedmem.h>
#include <native_service/ns_sharedmem_reader.h>
#include <native_service/ns_ringbuffer.h>
#include <native_service/ns_logger_if.h>
#include <system_service/ss_sm_client_if.h>
#include <system_service/ss_logger_service_protocol.h>
#include <system_service/ss_services.h>
#include <system_service/ss_templates.h>
#include <native_service/cl_process.h>
#include <native_service/cl_lockid.h>
#include <sstream>
#include <string>
#include "loggerservicedebug_loggerservicelog.h"
#include "loggerservicedebug_thread_if.h"
#include "ss_logger_error_event.h"
#include "ss_logger_service_callbacks.h"
#include "ss_logger_scrshot.h"
#include "ss_logger_fs_directory.h"
#include "ss_logger_common.h"
#include "ss_logger_types.h"

EFrameworkunifiedStatus SSLogger_SendtoSM(HANDLE f_hApp, TLoggingArtifact f_artifact) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  l_eStatus = SendLogArtifactRequestToSystemManager(f_artifact.ArtifactId);
  if (eFrameworkunifiedStatusOK != l_eStatus) {
    FRAMEWORKUNIFIEDLOG(
        ZONE_ERR,
        __FUNCTION__,
        " Error. SendLogArtifactRequestToSystemManager returned: %d for artifact ID: %d",
        l_eStatus, f_artifact.ArtifactId);
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

EFrameworkunifiedStatus SSLogger_SendtoSelf(HANDLE f_hApp, TLoggingArtifact f_artifact) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusNullPointer;
  if (NULL != f_hApp) {  // LCOV_EXCL_BR_LINE 6: double check
    l_eStatus = FrameworkunifiedSendSelf(f_hApp, SS_LOGGER_ERROR_EVENT_ARTIFACT_REQ,
                            sizeof(f_artifact.ArtifactId),
                            &f_artifact.ArtifactId);

    if (eFrameworkunifiedStatusOK != l_eStatus) {  // LCOV_EXCL_BR_LINE 4: NSFW error case.
      // LCOV_EXCL_START 4: NSFW error case.
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      FRAMEWORKUNIFIEDLOG(
          ZONE_ERR,
          __FUNCTION__,
          " Error. FrameworkunifiedSendSelf(SS_LOGGER_ERROR_EVENT_ARTIFACT_REQ) returned error: %d for artifact ID: %d.",
          l_eStatus, f_artifact.ArtifactId);
      // LCOV_EXCL_STOP
    }
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}
///////////////////////////////////////////////////////////////////////////
//  Function : SendLogArtifactResponseToSelf
//  brief    : Collect frameworkunifiedlog artifact and return a response to
//             SS_Logger.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::SendLogArtifactResponseToSelf(
    HANDLE f_hApp, EArtifactId f_artifactId,
    std::string f_artifactFilePathAndName) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  ARTIFACT_RESPONSE l_artifactResponse;

  l_artifactResponse.ArtifactId = f_artifactId;

  strncpy(l_artifactResponse.FilePathAndName, f_artifactFilePathAndName.c_str(),
          sizeof(l_artifactResponse.FilePathAndName) - 1);

  l_eStatus = FrameworkunifiedSendSelf(f_hApp, SS_SM_ERROR_EVENT_ARTIFACT_RSPN,
                          sizeof(l_artifactResponse), &l_artifactResponse);

  LOG_STATUS_IF_ERRORED(l_eStatus,
                        "FrameworkunifiedSendSelf(SS_SM_ERROR_EVENT_ARTIFACT_RSPN)");

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

///////////////////////////////////////////////////////////////////////////
//  Function : OnObtainLoggerserviceLogRequest
//  brief    : Collect frameworkunifiedlog artifact and return a response to
//             SS_Logger.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnObtainLoggerserviceLogRequest(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  std::string dir_path = DEBUG_LOG_PATH_DIR;

  l_eStatus = CFSDirectory::CreateDirectory(dir_path);
  if (l_eStatus != eFrameworkunifiedStatusOK) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Create FRAMEWORKUNIFIEDLOG tmp directory %d",
           l_eStatus);
  } else {
    UI_32 l_DumpSize = 0;
    std::string src_file_path;
    std::string dst_file_path;
    PCSTR file_name;
    UI_32 num;
    bool log_clear = true;

    switch (m_errorEventNtfData.EventType) {
      // _DIAG
      case eErrorEventTypeUserInvokedUserForceReset:
      case eErrorEventTypeUserInvokedCollectAllLogs:
      case eErrorEventTypeUserInvokedCollectScreenShot:
      case eErrorEventTypeUserInvokedCollectInterfaceunifiedLogs:
      case eErrorEventTypeDiagEvent:
      case eErrorEventTypeCanEvent:
      case eErrorEventTypeDtcEvent:
      case eErrorEventTypeModuleInvokedCollectDebugLogs:
        // _DEBUG
      case eErrorEventTypeUserInvokedCollectDevLogs:
        log_clear = false;
        break;
      default:
        break;
    }

    num = NSLogGetFrameworkunifiedlogFileTotalNum();
    for (UI_32 cont = 0; cont < num; cont++) {
      file_name = NSLogGetFrameworkunifiedlogFileName(cont);
      if (file_name == NULL) {
        break;
      }
      src_file_path = FRAMEWORKUNIFIEDLOG_RAMDISC_PATH;
      src_file_path.append("/");
      src_file_path.append(file_name);
      dst_file_path = DEBUG_LOG_PATH_DIR;
      dst_file_path.append("/");
      dst_file_path.append(file_name);
      CNSRingBuffer* l_pLoggerservicelog;
      int index;
      index = NSLogGetFrameworkunifiedlogIndex(src_file_path.c_str());
      l_pLoggerservicelog = new (std::nothrow) CNSRingBuffer(
          src_file_path, 0, index + LOCK_NSLOG_ACCES_IF_1);
      if (l_pLoggerservicelog == NULL) {  // LCOV_EXCL_BR_LINE 5: new's error case
        // LCOV_EXCL_START 5: new's error case
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        l_eStatus = eFrameworkunifiedStatusInvldHandle;
        FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
               "Error: FRAMEWORKUNIFIEDLOG RingBuffer handle is NULL %s",
               src_file_path.c_str());
        // LCOV_EXCL_STOP
      } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pLoggerservicelog->Open())) {
        FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
               "Error: FRAMEWORKUNIFIEDLOG RingBuffer Open failed %s %d",
               src_file_path.c_str(), l_eStatus);
      } else if (eFrameworkunifiedStatusOK
          != (l_eStatus = l_pLoggerservicelog->DumpToFile(dst_file_path.c_str(),
                                                &l_DumpSize))) {
        FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
               "Error: FRAMEWORKUNIFIEDLOG RingBuffer DumpToFile failed %s %d",
               src_file_path.c_str(), l_eStatus);
      }
      if (NULL != l_pLoggerservicelog) {  // LCOV_EXCL_BR_LINE 5: new's error case
        if (log_clear) {
          if (eFrameworkunifiedStatusOK != (l_eStatus = l_pLoggerservicelog->ClearBuf())) {
            FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
                   "Error: FRAMEWORKUNIFIEDLOG RingBuffer ClearBuf failed %s %d",
                   src_file_path.c_str(), l_eStatus);
          }
        }
        (void) l_pLoggerservicelog->Close();
        delete l_pLoggerservicelog;
      }
    }
    l_eStatus = SendLogArtifactResponseToSelf(f_hApp, eArtifactIdInterfaceunifiedDebugLog,
                                              DEBUG_LOG_PATH_DIR);
    LOG_STATUS_IF_ERRORED(
        l_eStatus, "SendLogArtifactResponseToSelf(eArtifactIdInterfaceunifiedDebugLog)");
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

///////////////////////////////////////////////////////////////////////////
//  Function : OnObtainLoggerserviceLogRequest
//  brief    : Collect frameworkunifiedlog artifact and return a response to
//             SS_Logger.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnObtainTransmitLogRequest(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  std::string l_RootPath;

  l_eStatus = m_pReaderWriterControl->FlushCache(eReaderWriterLogTransmit);
  LOG_STATUS_IF_ERRORED(l_eStatus, "m_pReaderWriterControl->FlushCache(eReaderWriterLogTransmit)");
  l_RootPath = TRANSMIT_LOG_PATH_FN;
  if (access(l_RootPath.c_str(), R_OK) != 0) {
    l_RootPath = "";
  }
  l_eStatus = SendLogArtifactResponseToSelf(f_hApp, eArtifactIdTransmitLog,
                                            l_RootPath.c_str());

  LOG_STATUS_IF_ERRORED(l_eStatus,
                        "SendLogArtifactResponseToSelf(eArtifactIdTransmitLog)");

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

///////////////////////////////////////////////////////////////////////////
//  Function : OnObtainLoggerserviceLogRequest
//  brief    : Collect frameworkunifiedlog artifact and return a response to
//             SS_Logger.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnObtainPerformanceLogRequest(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;

  l_eStatus = m_pReaderWriterControl->FlushCache(eReaderWriterLogPerformance);
  LOG_STATUS_IF_ERRORED(
      l_eStatus,
      "m_pReaderWriterControl->FlushCache(eReaderWriterLogPerformance)");
  l_eStatus = SendLogArtifactResponseToSelf(f_hApp, eArtifactIdPerformanceLog,
                                            PERFORMANCE_LOG_PATH_FN);

  LOG_STATUS_IF_ERRORED(
      l_eStatus, "SendLogArtifactResponseToSelf(eArtifactIdPerformanceLog)");

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

#define SCREEN_SHOT_INTVAL 500000  // 500msec
#define SCRREN_SHOT_CAPTURE_RETRY_CNT 2

static EFrameworkunifiedStatus SaveScreenShot(char *chldexe, char **argv, int m_sfd,
                                 CL_ProcessAttr_t *attr) {
  int selection = -1;
  fd_set fds;
  struct timeval tv;
  pid_t childpid;
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
  int retry = 0;

  while (1) {
    childpid = CL_ProcessCreate(chldexe, argv, NULL, attr);
    if (childpid == -1) {  // LCOV_EXCL_BR_LINE 5: c code case
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "create process failed returned: %d",
             errno);
    } else {
      do {
        tv.tv_sec = 5;
        tv.tv_usec = 0;
        FD_ZERO(&fds);
        FD_SET(m_sfd, &fds);
        selection = select(m_sfd + 1, &fds, NULL, NULL, &tv);
      } while ((selection < 0) && (errno == EINTR));  // LCOV_EXCL_BR_LINE 5: c code case
      if (selection < 0) {
        FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "select failed %d", errno);
      } else {
        if (FD_ISSET(m_sfd, &fds)) {  // LCOV_EXCL_BR_LINE 5: FD_ISSET's error case
          CL_ProcessCleanupInfo_t cinfo;
          int ret;

          ret = CL_ProcessCleanup(m_sfd, &cinfo);
          if ((ret != -1) && (cinfo.code == CLD_EXITED)) {
            if (cinfo.status != 0) {
              FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Save Error! cinfo.status:%d",
                     cinfo.status);
            } else {
              l_eStatus = eFrameworkunifiedStatusOK;
            }
          }
        } else {
          // LCOV_EXCL_START 5: FD_ISSET's error case
          AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
          // (FD_ISSET() failed Error
          FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "fd Not Exist fd Error\n");
          // LCOV_EXCL_STOP
        }
      }
    }
    if ((l_eStatus == eFrameworkunifiedStatusOK)
        || (retry >= (SCRREN_SHOT_CAPTURE_RETRY_CNT - 1))) {
      break;
    }
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "retry!");
    usleep(SCREEN_SHOT_INTVAL);  // interval
    retry++;
  }
  return l_eStatus;
}

///////////////////////////////////////////////////////////////////////////
//  Function : OnObtainScreenShotRequest
//  brief    : Collect screen shot artifact from PLM and return a response
//             to SS_Logger.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnObtainScreenShotRequest(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  std::string dir_path = SCREEN_SHOT_PATH;
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;
  EFrameworkunifiedStatus l_eStatusCh0 = eFrameworkunifiedStatusFail;
  EFrameworkunifiedStatus l_eStatusCh1 = eFrameworkunifiedStatusFail;

  char *c_argv0[4] = { NULL, const_cast<char*>(JPEG_PATH_CH0), const_cast<char*>("0"), NULL };
  char *c_argv1[4] = { NULL, const_cast<char*>(JPEG_PATH_CH1), const_cast<char*>("1"), NULL };
  char *chldexe;

  /*check m_sfd vlue*/
  if (m_sfd == -1) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "SS_Logger_SaveScreenShot m_sfd error -1");
    return l_eStatus;
  }

  /*check chldexe value*/
  chldexe = realpath(SCRSHOT_EXE_PATH, NULL);
  if (chldexe == NULL) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
           "SS_Logger_SaveScreenShot realpath failed %d", errno);
    return l_eStatus;
  }

  c_argv0[0] = chldexe;
  c_argv1[0] = chldexe;
  l_eStatus = CFSDirectory::CreateDirectory(dir_path);
  if (l_eStatus != eFrameworkunifiedStatusOK) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
           "SS_Logger_SaveScreenShot tmp directory failed");
    free(chldexe);
    return l_eStatus;
  } else {
    CL_ProcessAttr_t attr;
    CL_ProcessCreateAttrInit(&attr);

    /* Save Picture Ch0(E2) */
    l_eStatusCh0 = SaveScreenShot(chldexe, c_argv0, m_sfd, &attr);
    if (l_eStatusCh0 == eFrameworkunifiedStatusOK) {  // LCOV_EXCL_BR_LINE 200:As there are no ScreenShot processes
      // LCOV_EXCL_START 200:As there are no ScreenShot processes
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      /* Start Save Picture Ch1(M2) */
      l_eStatusCh1 = SaveScreenShot(chldexe, c_argv1, m_sfd, &attr);
      if (l_eStatusCh1 != eFrameworkunifiedStatusOK) {
        FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
               "SS_Logger_SaveScreenShot Ch1(M2) failed");
      }
      // LCOV_EXCL_STOP
    } else {
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "SS_Logger_SaveScreenShot Ch0(E2) failed");
    }
  }

  // Send Artifact Responce.
  if ((l_eStatusCh0 == eFrameworkunifiedStatusOK) || (l_eStatusCh1 == eFrameworkunifiedStatusOK)) {  // LCOV_EXCL_BR_LINE 200:As there are no ScreenShot processes
    // LCOV_EXCL_START 200:As there are no ScreenShot processes
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    // Set "SCREEN_SHOT_PATH" to save two pictures(ch0(E2) and ch1(M2))
    l_eStatus = SendLogArtifactResponseToSelf(f_hApp, eArtifactIdScreenShot,
    SCREEN_SHOT_PATH);
    LOG_STATUS_IF_ERRORED(
        l_eStatus, "SendLogArtifactResponseToSelf(eArtifactIdScreenShot)");
    // LCOV_EXCL_STOP
  } else {
    // If both Ch0 and Ch1 is failed,
    // update l_eStatus to eFrameworkunifiedStatusFail and delete directory.
    l_eStatus = eFrameworkunifiedStatusFail;
    if (CFSDirectory::DoesDirectoryExist(dir_path)) {
      if (CFSDirectory::RemoveDirectory(dir_path)) {
        FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
               "SS_Logger_SaveScreenShot directory delete successful.");
      } else {
        FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
               "SS_Logger_SaveScreenShot directory delete unsuccessful");
      }
    }
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
           "SS_Logger_SaveScreenShot Save Failed returned:%d", l_eStatus);
  }
  free(chldexe);
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

///////////////////////////////////////////////////////////////////////////
//  Function : OnObtainScreenShotResponse
//  brief    : Callback from PLM when the screen shot file has been written
//             to storage.  The data received contains the file path and
//             name to the written screen shot file. See
//             SS_LOGGER_SCREENCAPTURE_EVT_ACK.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnObtainScreenShotResponse(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  STScreenCaptureEvt l_ScreenCaptureEvtAck;

  if (eFrameworkunifiedStatusOK != (l_eStatus = ReadMsg<STScreenCaptureEvt>(f_hApp, l_ScreenCaptureEvtAck))) {  // LCOV_EXCL_BR_LINE 200:To ensure success  // NOLINT[whitespace/line_length]
    // LCOV_EXCL_START 200:To ensure success
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    LOG_ERROR("ReadMsg()");
    // LCOV_EXCL_STOP
  } else {
    if (FALSE == l_ScreenCaptureEvtAck.fSucessful) {
      FRAMEWORKUNIFIEDLOG(
          ZONE_ERR,
          __FUNCTION__,
          " Error. Screen shot acquisition failed. l_ScreenCaptureEvtAck.fSucessful == FALSE.");
      l_ScreenCaptureEvtAck.strNameAndLocation[0] = '\0';
    }

    l_eStatus = SendLogArtifactResponseToSelf(
        f_hApp, eArtifactIdScreenShot,
        l_ScreenCaptureEvtAck.strNameAndLocation);  // LCOV_EXCL_BR_LINE 11:Unexpected branch

    LOG_STATUS_IF_ERRORED(  // LCOV_EXCL_BR_LINE 5:macro
        l_eStatus, "SendLogArtifactResponseToSelf(eArtifactIdScreenShot)");
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

///////////////////////////////////////////////////////////////////////////
//  Function : OnObtainKernelLogInfoRequest
//  brief    : Collect kernel log artifact and return a response to
//             SS_Logger.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnObtainKernelLogInfoRequest(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");

  EFrameworkunifiedStatus l_eStatus = CreateKernelLog(f_hApp, SS_LOGGER_KLOG_GET);

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

///////////////////////////////////////////////////////////////////////////
//  Function : OnObtainDRInitialLogRequest
//  brief    : Collect DRInitialLog artifact and return a response to
//             SS_Logger.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnObtainDRInitialLogRequest(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  UI_32 l_DumpSize = 0;

  CNSSharedMemReader* l_pDRInitial = new (std::nothrow) CNSSharedMemReader(
      SHMEM_DRINITIALLOG, FALSE);

  if (NULL == l_pDRInitial) {  // LCOV_EXCL_BR_LINE 5: new's error case
    l_eStatus = eFrameworkunifiedStatusInvldHandle;
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: DRInitial SharedMem handle is NULL");
  } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pDRInitial->Open())) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: DRInitial Open failed %d", l_eStatus);
  } else if (eFrameworkunifiedStatusOK
      != (l_eStatus = l_pDRInitial->DumpToFile(DRINITIAL_LOG_PATH_FN,
                                               &l_DumpSize))) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: DRInitial DumpToFile failed %d",
           l_eStatus);
  } else {
    l_eStatus = SendLogArtifactResponseToSelf(f_hApp, eArtifactIdDRInitialLog,
                                              DRINITIAL_LOG_PATH_FN);
    LOG_STATUS_IF_ERRORED(
        l_eStatus, "SendLogArtifactResponseToSelf(eArtifactIdDRInitialLog)");
  }

  if (NULL != l_pDRInitial) {  // LCOV_EXCL_BR_LINE 5: new's error case
    (void) l_pDRInitial->Close();
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

///////////////////////////////////////////////////////////////////////////
//  Function : OnObtainDRLocationLogRequest
//  brief    : Collect DRLocationLog artifact and return a response to
//             SS_Logger.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnObtainDRLocationLogRequest(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  UI_32 l_DumpSize = 0;

  CNSSharedMemReader* l_pDRLocation = new (std::nothrow) CNSSharedMemReader(
      SHMEM_DRLOCATIONLOG, FALSE);

  if (NULL == l_pDRLocation) {  // LCOV_EXCL_BR_LINE 5: new's error case
    l_eStatus = eFrameworkunifiedStatusInvldHandle;
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: DRInitial SharedMem handle is NULL");
  } else if (eFrameworkunifiedStatusOK != (l_eStatus = l_pDRLocation->Open())) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: DRLocation Open failed %d",
           l_eStatus);
  } else if (eFrameworkunifiedStatusOK
      != (l_eStatus = l_pDRLocation->DumpToFile(DRLOCATION_LOG_PATH_FN,
                                                &l_DumpSize))) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: DRLocation DumpToFile failed %d",
           l_eStatus);
  } else {
    l_eStatus = SendLogArtifactResponseToSelf(f_hApp, eArtifactIdDRLocationLog,
                                              DRLOCATION_LOG_PATH_FN);

    LOG_STATUS_IF_ERRORED(
        l_eStatus, "SendLogArtifactResponseToSelf(eArtifactIdDRLocationLog)");
  }

  if (NULL != l_pDRLocation) {  // LCOV_EXCL_BR_LINE 5: new's error case
    (void) l_pDRLocation->Close();
    delete l_pDRLocation;
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

///////////////////////////////////////////////////////////////////////////
//  Function : OnClearAllLogRequest
//  brief    : Callback from LoggerService when the event log file has been delete
//             from storage.  The data received contains the file path.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnClearAllLogRequest(HANDLE f_hApp) {
  std::string clear_file_path = CLEAR_LOG_PATH_FN;
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;

  if (CFSDirectory::RemoveSubDirectory(clear_file_path)) {
    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
           "SS_Logger Clear %s directory delete successful.",
           clear_file_path.c_str());
  } else {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
           "SS_Logger Clear %s directory delete failed.",
           clear_file_path.c_str());
  }

  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
  clear_file_path = "/nv/log2/awlog/";
  if (CFSDirectory::RemoveSubDirectory(clear_file_path)) {
    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
           "SS_Logger Clear %s directory delete successful.",
           clear_file_path.c_str());
  } else {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
           "SS_Logger Clear %s directory delete failed.",
           clear_file_path.c_str());
  }

  clear_file_path = "/nv/log2/core/";
  if (CFSDirectory::RemoveSubDirectory(clear_file_path)) {
    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
           "SS_Logger Clear %s directory delete successful.",
           clear_file_path.c_str());
  } else {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
           "SS_Logger Clear %s directory delete failed.",
           clear_file_path.c_str());
  }
  // LCOV_EXCL_STOP

  l_eStatus = SendLogArtifactResponseToSelf(f_hApp, eArtifactIdClearAllLog,
                                            clear_file_path.c_str());
  LOG_STATUS_IF_ERRORED(l_eStatus,
                        "SendLogArtifactResponseToSelf(eArtifactIdClearAllLog)");
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

///////////////////////////////////////////////////////////////////////////
//  Function : OnNaviLogRequest
//  brief    : Callback from LoggerService when the event log file has been xxxxxx BUGBUG
//             from storage.  The data received contains the file path.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CErrorEvent::OnNaviLogRequest(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;

  // LCOV_EXCL_START 13:
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
  EFrameworkunifiedStatus naviLog_status;
  switch (m_errorEventNtfData.EventType) {
    case eErrorEventTypeProcessCrash:
    case eErrorEventTypeProcessExit:
    case eErrorEventTypeHeartBeatFailure:
    case eErrorEventTypeSystemLowMemory:
    case eErrorEventTypeBootMicroReset:
    case eErrorEventTypeModConnFailed:
    case eErrorEventTypeStartRespFailed:
    case eErrorEventTypeModuleInvokedResetRequest:
    case eErrorEventTypeGroupRelaunch:
      naviLog_status = SaveNaviLog(epssdmsdtGENERIC_ERROR_RESET);
      break;
    default:
      naviLog_status = SaveNaviLog(epssdmsdtNORMAL_RESET);
      break;
  }
  FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Error: Fail to save Navi Log %d",
         naviLog_status);
  // LCOV_EXCL_STOP

  l_eStatus = SendLogArtifactResponseToSelf(f_hApp, eArtifactIdNaviLog, "");
  LOG_STATUS_IF_ERRORED(l_eStatus,
                        "SendLogArtifactResponseToSelf(eArtifactIdNaviLog)");
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

EFrameworkunifiedStatus CErrorEvent::CheckPathForArtifact(HANDLE f_hApp,
                                             TLoggingArtifact f_artifact) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusInvldParam;
  std::string l_Path;

  if (f_artifact.Information.Cb.Type == eCbTypePath) {
    l_Path = f_artifact.Information.Cb.Path;
    if (access(l_Path.c_str(), R_OK) != 0) {
      FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
             "File/Directory %s not found. Returning empty string.",
             l_Path.c_str());
      l_Path = "";
    }
    l_eStatus = SendLogArtifactResponseToSelf(f_hApp, f_artifact.ArtifactId,
                                              l_Path.c_str());

    LOG_STATUS_IF_ERRORED(l_eStatus, "SendLogArtifactResponseToSelf()");
  }

  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}

/* Read all messages remaining in the ring buffer. (allowed for non-root) */
#define SYSLOG_ACTION_READ_ALL       3
/* Return size of the log buffer */
#define SYSLOG_ACTION_SIZE_BUFFER   10

EFrameworkunifiedStatus CErrorEvent::CreateKernelLog(HANDLE f_hApp,
                                        SS_LOGGER_KLOG_OPE_TYPE type) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  int len;
  int fd;
  char* buf;
  ssize_t wr_len;

  len = klogctl(SYSLOG_ACTION_SIZE_BUFFER, NULL, 0);
  if (len < 0) {  // LCOV_EXCL_BR_LINE 5: klogctl's error case
    // LCOV_EXCL_START 5: klogctl's error case
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
    l_eStatus = eFrameworkunifiedStatusFail;
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
           "Error. Failed to get syslog buffer size: %d, %s", errno,
           strerror(errno));
    // LCOV_EXCL_STOP
  } else {
    buf = reinterpret_cast<char*>(malloc(len));
    if (buf != NULL) {  // LCOV_EXCL_BR_LINE 5: new's error case
      len = klogctl(SYSLOG_ACTION_READ_ALL, buf, len);
      if ((len < 0) || (len == 0)) {  // LCOV_EXCL_BR_LINE 5: klogctl's error case
        // LCOV_EXCL_START 5: klogctl's error case
        AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
        l_eStatus = eFrameworkunifiedStatusFail;
        FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
               "Error. Failed to read syslog buffer: %d, %s", errno,
               strerror(errno));
        // LCOV_EXCL_STOP
      } else {
        std::string file_put_path = "";
        EArtifactId artifact_id = eArtifactIdMaxValue;
        switch (type) {
          case SS_LOGGER_KLOG_GET:
            file_put_path = KERNEL_LOG_PATH_FN;
            artifact_id = eArtifactIdKernelLog;
            fd = open(file_put_path.c_str(),
                      O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
            break;
          case SS_LOGGER_KBOOTLOG_CREATE:
            file_put_path = KERNEL_BOOT_LOG_PATH_FN;
            artifact_id = eArtifactIdKernelBootLog;
            fd = open(file_put_path.c_str(),
                      O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
            break;
          default:
            fd = -1;
            break;
        }

        if (fd == -1) {
          l_eStatus = eFrameworkunifiedStatusFail;
          FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
                 "Error. Failed to open file: %s: %d, %s",
                 file_put_path.c_str(), errno, strerror(errno));
        } else {
          wr_len = write(fd, buf, len);
          if (wr_len == -1) {  // LCOV_EXCL_BR_LINE 5: write's error case
            // LCOV_EXCL_START 5: write's error case
            AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
            FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
                   " Error. File write failed. errno: %d, %s", errno,
                   strerror(errno));
            // LCOV_EXCL_STOP
          }
          fsync(fd);
          close(fd);

          if (SS_LOGGER_KLOG_GET == type) {
            l_eStatus = SendLogArtifactResponseToSelf(f_hApp, artifact_id,
                                                      file_put_path.c_str());
            if (eFrameworkunifiedStatusOK != l_eStatus) {  // LCOV_EXCL_BR_LINE 4: NSFW error case.
              // LCOV_EXCL_START 4: NSFW error case.
              AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
              FRAMEWORKUNIFIEDLOG(
                  ZONE_ERR,
                  __FUNCTION__,
                  "SendLogArtifactResponseToSelf failed. EFrameworkunifiedStatus:%d, ArtifactID:%d, Path:%s",
                  l_eStatus, artifact_id, file_put_path.c_str());
              // LCOV_EXCL_STOP
            }
          }
        }
      }
      free(buf);
    } else {
      // LCOV_EXCL_START 5: new's error case
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200: test assert
      l_eStatus = eFrameworkunifiedStatusFail;
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__, "Memory allocation Failed %s",
             strerror(errno));
      // LCOV_EXCL_STOP
    }
  }
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "-");
  return (l_eStatus);
}