summaryrefslogtreecommitdiffstats
path: root/logger_service/server/src/ss_logger_error_event_responses.cpp
blob: dc23d8ba2fdd074430802d85d0db1261c1db0627 (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
/*
 * @copyright Copyright (c) 2016-2020 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);
}

///////////////////////////////////////////////////////////////////////////
//  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__, "+");

  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusFail;

  l_eStatus = SendLogArtifactResponseToSelf(f_hApp, eArtifactIdScreenShot,
  SCREEN_SHOT_PATH);
  LOG_STATUS_IF_ERRORED(
      l_eStatus, "SendLogArtifactResponseToSelf(eArtifactIdScreenShot)");
  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());
  }

  clear_file_path = "/nv/BS/ss/logger_service/rwdata/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/BS/ss/logger_service/rwdata/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());
  }

  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;

  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);

  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);
}