summaryrefslogtreecommitdiffstats
path: root/systemservice/system_manager/server/src/ss_system_manager_error_event_responses.cpp
blob: 28e8dbf8d02ab77ce9b5e023d387cb72bc56cfb1 (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
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
/*
 * @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  SS_SM_Logging
/// \brief    This file supports SM logging.
///
///////////////////////////////////////////////////////////////////////////////
#include <native_service/frameworkunified_types.h>
#include <native_service/ns_plogger_if.h>
#include <stub/ss_diag.h>
#include <system_service/ss_ver.h>
#include <system_service/ss_services.h>
#include <system_service/ss_templates.h>
#include <system_service/ss_client_names.h>
#include <system_service/ss_sm_client_if.h>

#include <stdint.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/statvfs.h>
#include <fcntl.h>
#include <dirent.h>
#include <errno.h>
#include <sys/wait.h>
#include <boost/algorithm/string.hpp>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <list>

#include "ss_system_manager.h"

///////////////////////////////////////////////////////////////////////////
//  Function : OnObtainLoggerserviceLogRequest
//  brief    : Collect frameworkunifiedlog artifact and return a response to
//             SS_Logger.
///////////////////////////////////////////////////////////////////////////
static int getExecedString(char* const argv[], std::stringstream &ss) {
  int ret;
  int pipeFd[2];  // 0:read, 1:write
  pid_t pid;
  ret = pipe(pipeFd);
  if (ret != 0) {  // LCOV_EXCL_BR_LINE 5:pipe's error case
    // LCOV_EXCL_START 5:pipe's error case
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
    SS_ASERT_ERRNO(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
    goto error_exit;
    // LCOV_EXCL_STOP
  }

  pid = fork();
  if (pid == -1) {  // LCOV_EXCL_BR_LINE 5:fork's error case
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
    SS_ASERT_ERRNO(0);  // LCOV_EXCL_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
  } else if (pid == 0) {
    close(pipeFd[0]);    // unnecessary pile (closing read)
    close(1);        // closing stdout
    dup2(pipeFd[1], 1);  // take stdout to pipe
    execve(argv[0], argv, environ);
    SS_ASERT_ERRNO(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
    exit(EXIT_FAILURE);
  } else {
    char readBuf[256];
    ssize_t rs;
    SS_ASERT_ERRNO(0 == close(pipeFd[1]));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

    fd_set rfds;
    FD_ZERO(&rfds);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
    FD_SET(pipeFd[0], &rfds);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
    struct timeval timeout;
    timeout.tv_sec = 2;
    timeout.tv_usec = 0;

    int selRet = select(pipeFd[0] + 1, &rfds, NULL, NULL, &timeout);
    switch (selRet) {
    case 1:
      if (FD_ISSET(pipeFd[0], &rfds)) {
        do {
          rs = read(pipeFd[0], readBuf, sizeof(readBuf) - 1);
          if (rs > 0) {
            readBuf[rs] = '\0';
            ss << readBuf;
          } else if (rs == -1) {  // LCOV_EXCL_BR_LINE 5:read's error case
            // LCOV_EXCL_START 5:read's error case
            AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
            if (errno != EINTR) {
              SS_ASERT_ERRNO(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
              ret = -1;
              break;
            }
            // LCOV_EXCL_STOP
          }
        } while (rs != 0);
      } else {
        SS_ASERT(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
      }
      break;
    case -1:
      SS_ASERT_ERRNO(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
      break;
    default:
      // LCOV_EXCL_START 5:never be this case
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
      if (0 == selRet) {
        ss << "timeout" << std::endl;
      } else {
        ss << "ERR:rslt=" << selRet << std::endl;
      }
      break;
      // LCOV_EXCL_STOP
    }

    // SM leaves processing to OnProcessExitDetected when using child process
    // SS_ASERT_ERRNO(-1 != waitpid(pid,&status,0));
  }
  SS_ASERT_ERRNO(0 == close(pipeFd[0]));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
error_exit:
  return ret;
}

static int saveProcsMemInfo(std::ofstream &fo) {
  DIR *dir = NULL;
  int ret = 0;

  try {
    struct dirent dent, *next;
    // LCOV_EXCL_BR_START 11:unexpected branch  // NOLINT(whitespace/line_length)
    {
      fo << "******** mem info **********" << std::endl;
      std::ifstream fin("/proc/meminfo");
      std::string line;
      while (fin && std::getline(fin, line)) {
        fo << line << endl;
      }
    }

    {
      fo << "******** slab info **********" << std::endl;
      std::ifstream fin("/proc/slabinfo");
      std::string line;
      while (fin && std::getline(fin, line)) {
        fo << line << endl;
      }
    }

    {
      fo << "******** zone info **********" << std::endl;
      std::ifstream fin("/proc/zoneinfo");
      std::string line;
      while (fin && std::getline(fin, line)) {
        fo << line << endl;
      }
    }
    // LCOV_EXCL_BR_STOP

    // Linux dependency codes
    dir = opendir("/proc");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    if (dir == NULL) {  // LCOV_EXCL_BR_LINE 5:opendir's error case
      // LCOV_EXCL_START 11:opendir's error case
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
      SS_ASERT_ERRNO(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
      throw eFrameworkunifiedStatusFail;
      // LCOV_EXCL_STOP
    }

    fo << "******** proc status **********" << std::endl;
    while (0 == readdir_r(dir, &dent, &next) && next) {
      if (DT_DIR == dent.d_type) {
        struct stat statbuf;
        std::string statPath("/proc/");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
        statPath += dent.d_name;
        statPath += "/status";

        if (stat(statPath.c_str(), &statbuf) == 0) {
          std::ifstream fin(statPath.c_str());  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
          std::string line;
          while (fin && std::getline(fin, line)) {
            if (strstr(line.c_str(), "Name") != NULL
                || strstr(line.c_str(), "Pid") != NULL
                || strstr(line.c_str(), "Vm") != NULL) {
              fo << line << endl;
            }
          }
          fo << "************************************" << std::endl;
        }
      }
    }
    SS_ASERT_ERRNO(0 == closedir(dir));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
  } catch (...) {
    if (dir) {  // LCOV_EXCL_BR_LINE 5:opendir's error case
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
      SS_ASERT_ERRNO(0 == closedir(dir));  // LCOV_EXCL_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
    }
    ret = -1;
  }
  return ret;
}

///////////////////////////////////////////////////////////////////////////
//  Function : OnObtainLoggerserviceLogRequest
//  brief    : Collect frameworkunifiedlog artifact and return a response to
//             SS_Logger.
///////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::SendLogArtifactResponseToLogger(HANDLE f_hApp,
        EArtifactId f_artifactId, std::string f_artifactFilePathAndName) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;
  HANDLE l_hLoggerServiceSession;
  ModuleLaunchListIter l_ModuleListIter;
  ARTIFACT_RESPONSE l_artifactResponse;

  l_artifactResponse.ArtifactId = f_artifactId;

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

  if (eFrameworkunifiedStatusOK
      != (l_eStatus = GetModuleIterator(SERVICE_LOGGER, l_ModuleListIter))) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
        " Error: GetModuleIterator(%s) errored: %d/'%s'",
        SERVICE_LOGGER, l_eStatus, GetStr(l_eStatus).c_str());
  } else {
    l_hLoggerServiceSession = l_ModuleListIter->hsession;

    l_eStatus = FrameworkunifiedSendMsg(l_hLoggerServiceSession,
        SS_SM_ERROR_EVENT_ARTIFACT_RSPN, sizeof(l_artifactResponse),
        &l_artifactResponse);

    LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
        "FrameworkunifiedSendMsg(SS_SM_ERROR_EVENT_ARTIFACT_RSPN)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
  }

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

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnErrorEventArtifactRequest
/// Dispatch logging requests to the various handlers.
///
/// \param f_hApp Framework application handle.
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnErrorEventArtifactRequest(HANDLE hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;
  INTERFACEUNIFIEDLOG_RECEIVED_FROM(hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

  if (eFrameworkunifiedStatusOK
      != (l_eStatus = ReadMsg < EArtifactId
          > (hApp, m_requestedArtifactId))) {  // LCOV_EXCL_BR_LINE 200:NSFW error case
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
    LOG_ERROR("ReadMsg()");  // LCOV_EXCL_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
  } else {
    switch (m_requestedArtifactId) {
    case eArtifactIdBootMicroLog:
      l_eStatus = OnObtainBootMicroLog(hApp);
      LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "OnObtainBootMicroLog()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
      break;

    case eArtifactIdSystemDataCsv:
      l_eStatus = OnObtainSystemmanagerSystemDataCsv(hApp);
      LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "OnObtainSystemmanagerSystemDataCsv()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
      break;

    case eArtifactIdShowMemTxt:
      l_eStatus = OnObtainShowMemTxt(hApp);
      LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "OnObtainShowMemTxt()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
      break;

    case eArtifactIdProcessCore:
      SS_ASERT(0);  // Never called in Linux PF // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
      break;

    case eArtifactIdDebugDumpLog:
      l_eStatus = OnObtainDebugDumpLog(hApp);
      LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "OnObtainDebugDumpLog()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
      break;

    default:
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
          " Error: Unsupported logging artifact requested: %d.",
          m_requestedArtifactId);
      break;
    }
  }

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

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnObtainBootMicroLog
/// Obtain the boot micro log content, write file to disk, and send filename to SL.
///
/// \param [in] f_hApp - Application handle.
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnObtainBootMicroLog(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus;
  INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
  FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(f_hApp));

  l_eStatus = RequestBootMicroLog(f_hApp);
  LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus, "RequestBootMicroLog");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)

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

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnBootMicroLogResponse
/// Boot micro log response sent from the logging shadow.
///
/// \param [in] f_hApp - Application handle.
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnBootMicroLogResponse(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  UI_32 l_len;
  std::string l_artifactFilePathAndName;

  m_errorEventTimers[eSM_ERROR_EVENT_TIMER_BOOT_MICRO_LOG_RSPN].Stop();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
  FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", FrameworkunifiedGetMsgSrc(f_hApp));

  if (0 == strcmp(TIMER_SERVICE_NAME, FrameworkunifiedGetMsgSrc(f_hApp))) {
    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
        " Info. Timer expired while waiting for the boot micro log.");
  } else if (0 == (l_len = FrameworkunifiedGetMsgLength(f_hApp))) {  // LCOV_EXCL_BR_LINE 200:restricted by ss_sm_client
    // LCOV_EXCL_START 200:restricted by ss_sm_client
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
        " Error: Invalid log response received.  Length cannot be 0.");
    // LCOV_EXCL_STOP
  } else {
    char l_buf[l_len];  // NOLINT
    l_eStatus = FrameworkunifiedGetMsgDataOfSize(f_hApp, l_buf, static_cast<UI_32>(sizeof(l_buf)), eSMRRelease);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    if (eFrameworkunifiedStatusOK != l_eStatus) {  // LCOV_EXCL_BR_LINE 200:NSFW error case
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
      LOG_ERROR("FrameworkunifiedGetMsgDataOfSize()");  // LCOV_EXCL_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
    } else {
      l_artifactFilePathAndName = "/tmp/bootmicro.log";
      l_len = static_cast<UI_32>(strlen((const char *) l_buf));
      std::ofstream l_stream(l_artifactFilePathAndName.c_str());  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
      l_stream.write(l_buf, l_len);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
      l_stream.close();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    }
  }

  l_eStatus = SendLogArtifactResponseToLogger(f_hApp, m_requestedArtifactId,
      l_artifactFilePathAndName);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  if (l_eStatus != eFrameworkunifiedStatusOK) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
        " Error: SendLogArtifactResponseToLogger(Artifact '%d', '%s') "
            "errored: %d/'%s'", m_requestedArtifactId,
        l_artifactFilePathAndName.c_str(), l_eStatus,
        GetStr(l_eStatus).c_str());
  }

  return (l_eStatus);
}

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnErrorEventBootMicroLogResponseTimeout
/// Called when the boot micro log request timer expires (e.g. no response).
///
/// \param [in] f_hApp - Application handle.
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnErrorEventBootMicroLogResponseTimeout(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  std::string l_artifactFilePathAndName = "";

  FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
      " Error: Boot micro log response timed out. Sending empty artifact response to SSL.");

  l_eStatus = SendLogArtifactResponseToLogger(f_hApp, m_requestedArtifactId,
      l_artifactFilePathAndName);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  if (l_eStatus != eFrameworkunifiedStatusOK) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
        " Error: SendLogArtifactResponseToLogger(Artifact '%d', '%s') "
            "errored: %d/'%s'", m_requestedArtifactId,
        l_artifactFilePathAndName.c_str(), l_eStatus,
        GetStr(l_eStatus).c_str());
  }

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

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnObtainSystemmanagerSystemDataCsv
/// Obtain system content, write file to disk, and send filename to SL.
///
/// \param [in] f_hApp - Application handle.
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnObtainSystemmanagerSystemDataCsv(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  // std::string   l_artifactFilePathAndName = "/tmp/frameworkunified_systemdata.csv";
  // std::ofstream   l_stream(l_artifactFilePathAndName.c_str());
  std::stringstream l_stream;
  char *l_pSignalName;
  INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

  // Output version info
  {
    // LCOV_EXCL_BR_START 11:unexpected branch  // NOLINT(whitespace/line_length)
    CSSVer ver;
    l_stream << "********** PACKAGE VERSIONS **********\n";
    l_stream << left;
    l_stream << setw(16) << "PACKAGE" << setw(24) << "VERSION" << setw(10)
        << "DATE" << endl;
    for (SSVerPkgListIter ite = ver.begin(); ite != ver.end(); ite++) {
      l_stream << setw(16) << ite->first;
      l_stream << setw(24) << ite->second.version;
      l_stream << setw(10) << ite->second.date << std::endl;
    }
    // LCOV_EXCL_BR_STOP
    FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", l_stream.str().c_str());
    l_stream.str("");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    l_stream.clear();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
  }

  // LCOV_EXCL_BR_START 11:unexpected branch  // NOLINT(whitespace/line_length)
  l_stream << "********** Error Description Start ***********" << endl;
  l_stream << "Error Event Type,"
      << GetStr(m_errorEventCurrentIter->m_eventType) << endl;
  l_stream << m_errorEventCurrentIter->m_eventEnqueueTimeStamp.c_str() << endl;
  l_stream << "MessageStr,"
      << m_errorEventCurrentIter->m_loggingInfo.messageStr.c_str() << endl;
  // LCOV_EXCL_BR_STOP

  {
    UI_32 l_ErrLogCount = 0;
    if (PowerHalGetResetInfo(AGL_ERRLOG_COUNTER, &l_ErrLogCount)) {  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
      FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__,
        "Could not get AGL_ERRLOG_COUNTER from power_hal.");
    }

    {
      l_stream << "ErrLogCount," << l_ErrLogCount << "/"
          << SS_SM_ERR_LOGGING_LIMIT << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    }
  }

  switch (m_errorEventCurrentIter->m_eventType) {
  case eErrorEventTypeProcessCrash:
    l_stream << "Crash Failure Binary Name,"
        << m_errorEventCurrentIter->m_loggingInfo.binaryFileName << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    l_stream << "Module PID," << m_errorEventCurrentIter->m_loggingInfo.pid << endl;
    l_stream << "Exit Value,"
        << m_errorEventCurrentIter->m_loggingInfo.exitValue << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

    l_pSignalName = strsignal(
        m_errorEventCurrentIter->m_loggingInfo.signalNumber);
    if (NULL != l_pSignalName) {
      l_stream << "Exit Signal,"
          << m_errorEventCurrentIter->m_loggingInfo.signalNumber  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
          << "," << l_pSignalName << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    }

    break;

  case eErrorEventTypeProcessExit:
    l_stream << "Exit Binary Name,"
        << m_errorEventCurrentIter->m_loggingInfo.binaryFileName << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    l_stream << "Module PID," << m_errorEventCurrentIter->m_loggingInfo.pid << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    l_stream << "Exit Value,"
        << m_errorEventCurrentIter->m_loggingInfo.exitValue << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    break;

  case eErrorEventTypeHeartBeatFailure:
    l_stream << "HB Failure Module Queue Name,"
        << m_errorEventCurrentIter->m_moduleQueueName.c_str() << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    l_stream << "***************** HB Information Start *******************" << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    l_stream << "Entire State," << m_HBReport.eEntireState << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    l_stream << "Module Name,HB State,Retry Count" << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

    for (UI_32 i = 0; i < m_HBReport.nNumOfModules; i++) {
      if (0 != m_HBReport.tModuleList[i].HeartBeatRetryCount) {
        l_stream << m_HBReport.tModuleList[i].ProcQueueName << ","  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
            << m_HBReport.tModuleList[i].ProcHBState << ","  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
            << m_HBReport.tModuleList[i].HeartBeatRetryCount  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
            << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
      }
    }
    l_stream << "***************** HB Information End *******************" << endl;
    break;

  case eErrorEventTypeSystemLowMemory:
    l_stream << "Free Memory Available (Byte)," << m_FreeMemAvailable << endl;
    break;

  case eErrorEventTypeBootMicroReset:
    l_stream << "Boot Micro Reset Reason," << m_BootMicroResetReason << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    break;

  case eErrorEventTypeModConnFailed:
    l_stream << "Failed Module Queue Name,"
        << m_errorEventCurrentIter->m_moduleQueueName.c_str() << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    break;

  case eErrorEventTypeStartRespFailed:
    l_stream << "Failed Module Queue Name,"
        << m_errorEventCurrentIter->m_moduleQueueName.c_str() << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    break;

       // No additional event specific log information to add.
  case eErrorEventTypeUserInvokedCollectAllLogs:
  case eErrorEventTypeUserInvokedCollectScreenShot:
  case eErrorEventTypeUserInvokedCollectInterfaceunifiedLogs:
  case eErrorEventTypeUserInvokedUserForceReset:
  case eErrorEventTypeUserInvokedCollectDevLogs:
  default:
    break;
  }

  {
    std::ifstream finNum("/proc/sys/vm/nr_oom_kill_process");
    std::string strNum;
    if (finNum && std::getline(finNum, strNum)) {  // LCOV_EXCL_BR_LINE 200:will not be this case
      // LCOV_EXCL_START 200:will not be this case
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
      char *endptr = NULL;
      long lNum = strtol(strNum.c_str(), &endptr, 10);  // NOLINT
      if (('\0' != *endptr) || (lNum < 0)) {
        SS_ASERT(0);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
      } else {
        l_stream << "nr_oom_kill_process," << strNum.c_str() << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
        if (0 != lNum) {
          std::ifstream finLast("/proc/sys/vm/last_oom_kill_victim");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
          std::string strLast;
          if (finLast && std::getline(finLast, strLast)) {
            l_stream << "last_oom_kill_victim," << strLast.c_str() << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
          }
        }
      }
    }
    // LCOV_EXCL_STOP
  }

  l_stream << "********** Error Description End ***********" << endl << endl;
  FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", l_stream.str().c_str());

  fprintf(stderr, "SS_SysManager/\n%s", l_stream.str().c_str());  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  l_stream.str("");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
  l_stream.clear();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  l_stream << "********** Variant Code Start ***********" << endl;
  if (NULL != m_pVarCodeStr) {
    l_stream << m_pVarCodeStr << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
  } else {
    l_stream << "Variant coding not available." << endl;
  }
  l_stream << "********** Variant Code End ***********" << endl << endl;
  FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", l_stream.str().c_str());
  l_stream.str("");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
  l_stream.clear();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  l_stream << "********** File System Information Start ***********" << endl;
  l_stream << "== mounts info start==" << endl;
  {
    std::ifstream fin("/proc/mounts");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    std::string line;
    while (fin && std::getline(fin, line)) {
      l_stream << line << endl;
    }
  }
  l_stream << "== mounts info end ==" << endl;
  FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", l_stream.str().c_str());
  l_stream.str("");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
  l_stream.clear();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  l_stream << "== DF info start==" << endl;
  {
    char* const argv[] = { const_cast<char*>("/bin/df"), const_cast<char*>("-a"), static_cast<char*>(NULL), };
    SS_ASERT(0 == getExecedString(argv, l_stream));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
  }
  l_stream << "== DF info end==" << endl;

  FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", l_stream.str().c_str());
  l_stream.str("");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
  l_stream.clear();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

#if 0   // Need to install lsblk if requested so that it is not installed
  l_stream << "== lsblk info start==" << endl;
  {
    char* const argv[] = {
      const_cast<char*>("/usr/debug/bin/lsblk"),
      const_cast<char*>("-o"),
      const_cast<char*>("NAME,KNAME,MAJ:MIN,FSTYPE,PARTLABEL,MODEL,SERIAL,REV,VENDOR"),
      const_cast<char*>(NULL),
    };
    SS_ASERT(0 == getExecedString(argv, l_stream));
  }
  l_stream << "== lsblk info end==" << endl;
  FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", l_stream.str().c_str());
  l_stream.str("");
  l_stream.clear();
#endif

  l_stream << "== proc info start==" << endl;
  {
    char* const argv[] = { const_cast<char*>("/bin/ps"), const_cast<char*>("auxc"),
        const_cast<char*>("-L"), static_cast<char*>(NULL), };
    SS_ASERT(0 == getExecedString(argv, l_stream));  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
  }
  l_stream << "== proc info end==" << endl;
  {
    // Output is splitted so that the FRAMEWORKUNIFIEDLOG can not write data over 4K Bytes at a time
    std::list<std::string> strList;
    boost::split(strList, static_cast<const std::string>(l_stream.str()),
        boost::is_any_of("\n"));  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

    int ii = 0;
    std::stringstream ss;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    for (std::list<std::string>::iterator ite = strList.begin();
        ite != strList.end(); ite++) {
      ss << *ite << endl;
      ii++;
      if (ii > 20) {
        FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", ss.str().c_str());
        ss.str("");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
        ss.clear();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
        ii = 0;
      }
    }
    FRAMEWORKUNIFIEDLOG(ZONE_SYSLOG, __FUNCTION__, "\n%s", ss.str().c_str());
  }
  l_stream.str("");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
  l_stream.clear();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  l_eStatus = SendLogArtifactResponseToLogger(f_hApp, m_requestedArtifactId, "");  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  if (l_eStatus != eFrameworkunifiedStatusOK) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
        " Error: SendLogArtifactResponseToLogger(Artifact '%d') "
            "errored: %d/'%s'", m_requestedArtifactId, l_eStatus,
        GetStr(l_eStatus).c_str());
  }

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

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnObtainShowMemTxt
/// Obtain showmem content, write file to disk, and send filename to SL.
///
/// \param [in] f_hApp - Application handle.
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnObtainShowMemTxt(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)

  std::string l_artifactFilePathAndName = "/tmp/showmem.txt";
  {
    std::ofstream fo(l_artifactFilePathAndName.c_str());  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    saveProcsMemInfo(fo);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
  }

  l_eStatus = SendLogArtifactResponseToLogger(f_hApp, m_requestedArtifactId,
                                              l_artifactFilePathAndName);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  if (l_eStatus != eFrameworkunifiedStatusOK) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
        " Error: SendLogArtifactResponseToLogger(Artifact '%d', '%s') "
            "errored: %d/'%s'", m_requestedArtifactId,
        l_artifactFilePathAndName.c_str(), l_eStatus,
        GetStr(l_eStatus).c_str());
  }

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

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnErrorEventCoreFilePollTimeout
/// Called periodically to verify whether the process core file has completed
/// being written to disk. When complete, this function sends an artifact
/// response to SSL.
///
/// \param [in] f_hApp - Application handle.
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnErrorEventCoreFilePollTimeout(HANDLE f_hApp) {  // LCOV_EXCL_START 8:dead code
  AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  BOOL l_sendResponse = FALSE;
  std::string l_artifactFilePathAndName = "";
  std::ostringstream l_coreFilePathAndName;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

//  struct stat l_fileInfo;
  struct stat64 l_fileInfo;
  int l_result;
  off_t l_coreFileSize;
  INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

  l_coreFilePathAndName << "/debug/"
      << m_errorEventCurrentIter->m_loggingInfo.binaryFileName << ".core.gz";  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)


//  l_result = stat(l_coreFilePathAndName.str().c_str(), &l_fileInfo);
  l_result = stat64(l_coreFilePathAndName.str().c_str(), &l_fileInfo);
  if (l_result == 0) {
    l_coreFileSize = l_fileInfo.st_size;
    if ((l_coreFileSize > m_coreFileSizeBytes) ||  // Core file grew from last read.
        (l_coreFileSize == 0)) {  // Core file not yet updated externally.
      m_coreFileSizeBytes = l_coreFileSize;  // Wait until file stops growing.
      bool result =
          m_errorEventTimers[eSM_ERROR_EVENT_TIMER_CORE_FILE_POLL].Start(  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
              0, SS_ERROR_EVENT_CORE_FILE_POLL_TO_MS, 0, 0);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
      if (FALSE == result) {
        FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
            " Error: Failed to start timer SS_ERROR_EVENT_CORE_FILE_POLL_TO_MS.");
        l_sendResponse = TRUE;
      } else {
        FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
            " Info. Core file: %s, size: %ld still growing.",
            l_coreFilePathAndName.str().c_str(),
            m_coreFileSizeBytes);

        l_sendResponse = FALSE;
      }
    } else {  // File has stopped growing.
      FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
          " Info. Core file: %s, size: %ld write complete. Sending artifact response.",
          l_coreFilePathAndName.str().c_str(), m_coreFileSizeBytes);

      l_artifactFilePathAndName = l_coreFilePathAndName.str();
      l_sendResponse = TRUE;
    }
  } else {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
        " Info. Core file: %s, unable to determine size.  Sending empty artifact response to SSL.",
        l_coreFilePathAndName.str().c_str());

    l_sendResponse = TRUE;
  }

  if (TRUE == l_sendResponse) {
    l_eStatus = SendLogArtifactResponseToLogger(f_hApp,  // Error getting file size. Send empty path to SSL.
    m_requestedArtifactId, l_artifactFilePathAndName);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

    if (l_eStatus != eFrameworkunifiedStatusOK) {
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
          " Error: SendLogArtifactResponseToLogger(Artifact '%d', '%s') "
              "errored: %d/'%s'", m_requestedArtifactId,
          l_artifactFilePathAndName.c_str(), l_eStatus,
          GetStr(l_eStatus).c_str());
    }
  }

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

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnObtainDebugDumpLog
/// Obtain debug dump content, write file to disk, and send filename to SL.
/// See OnModuleDebugDumpResponse().
///
/// \param [in] f_hApp - Application handle.
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnObtainDebugDumpLog(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

  ModuleLaunchListIter l_moduleIter;

  m_NbrDebugDumpRspnRecv = 0;

  for (GroupLaunchMapIter l_GroupIter = m_MapProclaunchGrps.begin();
      l_GroupIter != m_MapProclaunchGrps.end(); l_GroupIter++) {
    for (l_moduleIter = l_GroupIter->second.modules.begin();
        l_moduleIter != l_GroupIter->second.modules.end();
        l_moduleIter++) {
      const BOOL isModuleConnected = l_moduleIter->IsModuleConnected();  // LCOV_EXCL_BR_LINE 11:Gcov constraints (because exception-handling routes are automatically generated)
      if ((SERVICE_NS_NPP != l_moduleIter->name) &&  // NPP is a special case and does NOT session connect with SM.
          (TRUE == isModuleConnected)) {
        l_eStatus = FrameworkunifiedSendMsg(l_moduleIter->hsession, SS_SM_DEBUG_DUMP,
            0, NULL);

        if (eFrameworkunifiedStatusOK == l_eStatus) {  // LCOV_EXCL_BR_LINE 200:NSFW error case
          FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
              " Info. FrameworkunifiedSendMsg(SS_SM_DEBUG_DUMP) to %s succeeded.", // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
              l_moduleIter->name.c_str());  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)
        } else {
          // LCOV_EXCL_START 200:NSFW error case
          AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
          FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
              " Error: FrameworkunifiedSendMsg(%p, SS_SM_DEBUG_DUMP) to %s errored: %d/'%s'",
              (void *) l_moduleIter->hsession,
              l_moduleIter->name.c_str(), l_eStatus,
              GetStr(l_eStatus).c_str());
          // LCOV_EXCL_STOP
        }
      }
    }
  }

  // Call debug dump handler for SM.
  l_eStatus = OnSystemManagerDebugDump(f_hApp);
  LOG_STATUS(l_eStatus, "OnSystemManagerDebugDump()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

  // Refresh debug dump timeout timer after each debug dump response received.
  // Non AGL framework modules will have the remaining time after the last
  // received response to complete their debug dump.
  bool result =
      m_errorEventTimers[eSM_ERROR_EVENT_TIMER_DEBUG_DUMP_RSPN].Start(
          SS_ERROR_EVENT_DEBUG_DUMP_RSPN_TO_SEC, 0, 0, 0);
  if (FALSE == result) {  // LCOV_EXCL_BR_LINE 200:will not be this case
    // LCOV_EXCL_START 200:will not be this case
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
        " Error: Failed to start timer eSM_TIMER_DEBUG_DUMP_RSPN_MONITOR.");
    // LCOV_EXCL_STOP
  }

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

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnDebugDumpResponseReceived
/// Debug Dump complete Response handler.
/// See OnDebugDumpCompleteTimeout().
///
/// \param [in] f_hApp - Application handle.
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnDebugDumpResponseReceived(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  ModuleLaunchListIter l_ModuleListIter;
  UI_32 l_len;
  INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ns_logger_if.h  // NOLINT(whitespace/line_length)

  std::string l_moduleName = FrameworkunifiedGetMsgSrc(f_hApp);
  FRAMEWORKUNIFIEDLOG(ZONE_STATE, __FUNCTION__, "from %s", l_moduleName.c_str());

  SetCmdHist("SS_SM_DEBUG_DUMP_RSPN", m_SMCmdHist, m_SMHistIter, FrameworkunifiedGetMsgSrc(f_hApp));  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  // SM is not launched by SM and is therefore not in the process list.
  // SM does however use the same debug dump mechanism as other processes.
  if (l_moduleName != SERVICE_SYSMANAGER) {
    l_eStatus = GetModuleIterator(l_moduleName.c_str(), l_ModuleListIter);
    if (eFrameworkunifiedStatusOK != l_eStatus) {
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
          " Error: Module %s not found in Group Launch Map", l_moduleName.c_str());
    } else {
      l_ModuleListIter->SetModuleDebugDumpState(MODULE_DEBUG_DUMP_STATE_RESPONSE_RECEIVED);
    }
  }

  if (0 == (l_len = FrameworkunifiedGetMsgLength(f_hApp))) {  // LCOV_EXCL_BR_LINE 200:restricted by ss_sm_client
    // LCOV_EXCL_START 200:restricted by ss_sm_client
    AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
    l_eStatus = eFrameworkunifiedStatusInvldBufSize;
    LOG_ERROR("0 == FrameworkunifiedGetMsgLength(f_hApp)");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
    // LCOV_EXCL_STOP
  } else {
    FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__,
        " Received debug dump response from %s, size: %d bytes. "
            "Total number of responses received: %d",
        l_moduleName.c_str(), l_len, m_NbrDebugDumpRspnRecv);

    UI_8 l_buf[l_len];  // NOLINT
    l_eStatus = FrameworkunifiedGetMsgDataOfSize(f_hApp, l_buf, static_cast<UI_32>(sizeof(l_buf)),
        eSMRRelease);
    if (eFrameworkunifiedStatusOK != l_eStatus) {
      LOG_ERROR("FrameworkunifiedGetMsgDataOfSize()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)
    } else {
      ios_base::openmode l_mode;
      if (0 == m_NbrDebugDumpRspnRecv) {
        // Create new file.
        l_mode = std::ios_base::trunc;
      } else {
        // Append existing file.
        l_mode = std::ios_base::app;
      }

      std::ofstream l_stream("/tmp/systemmanager_debugdump.log", l_mode);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
      l_stream << l_buf << endl;  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
      l_stream.close();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    }

    m_NbrDebugDumpRspnRecv++;

    // Refresh debug dump timeout timer after each debug dump response received.
    // Non AGL framework modules will have the remaining time after the last
    // received response to complete their debug dump.
    bool result =
        m_errorEventTimers[eSM_ERROR_EVENT_TIMER_DEBUG_DUMP_RSPN].Start(  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
            SS_ERROR_EVENT_DEBUG_DUMP_RSPN_TO_SEC, 0, 0, 0);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
    if (FALSE == result) {  // LCOV_EXCL_BR_LINE 200:will not be this case
      // LCOV_EXCL_START 200:will not be this case
      AGL_ASSERT_NOT_TESTED();  // LCOV_EXCL_LINE 200:test assert
      FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
          " Error: Failed to start timer eSM_TIMER_DEBUG_DUMP_RSPN_MONITOR.");
      l_eStatus = OnDebugDumpCompleteTimeout(f_hApp);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)
      LOG_ERROR_REC_HIST_IF_ERRORED(l_eStatus,  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
          "OnDebugDumpCompleteTimeout()");  // LCOV_EXCL_BR_LINE 15: marco defined in ss_system_manager.h  // NOLINT(whitespace/line_length)
      // LCOV_EXCL_STOP
    }
  }

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

///////////////////////////////////////////////////////////////////////////////
/// \ingroup OnDebugDumpCompleteTimeout
/// Called after the last debug dump message is received, or when the debug
/// dump monitor timer expires.
///
/// \param [in] f_hApp - Application handle.
///
/// \return EFrameworkunifiedStatus
/// Success ==> eFrameworkunifiedStatusOK
/// Failure ==> Other values
///////////////////////////////////////////////////////////////////////////////
EFrameworkunifiedStatus CSystemManager::OnDebugDumpCompleteTimeout(HANDLE f_hApp) {
  FRAMEWORKUNIFIEDLOG(ZONE_FUNC, __FUNCTION__, "+");
  EFrameworkunifiedStatus l_eStatus = eFrameworkunifiedStatusOK;
  std::string l_artifactFilePathAndName = "/tmp/systemmanager_debugdump.log";
  INTERFACEUNIFIEDLOG_RECEIVED_FROM(f_hApp);  // LCOV_EXCL_BR_LINE 15: marco defined in ss_templates.h  // NOLINT(whitespace/line_length)

  m_errorEventTimers[eSM_ERROR_EVENT_TIMER_DEBUG_DUMP_RSPN].Stop();  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  FRAMEWORKUNIFIEDLOG(ZONE_INFO, __FUNCTION__, "Received '%d' Debug Dump responses.",
      m_NbrDebugDumpRspnRecv);

  l_eStatus = SendLogArtifactResponseToLogger(f_hApp, m_requestedArtifactId,
      l_artifactFilePathAndName);  // LCOV_EXCL_BR_LINE 11:unexpected branch  // NOLINT(whitespace/line_length)

  if (l_eStatus != eFrameworkunifiedStatusOK) {
    FRAMEWORKUNIFIEDLOG(ZONE_ERR, __FUNCTION__,
        " Error: SendLogArtifactResponseToLogger(Artifact '%d', '%s') "
            "errored: %d/'%s'", m_requestedArtifactId,
        l_artifactFilePathAndName.c_str(), l_eStatus,
        GetStr(l_eStatus).c_str());
  }

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