LCOV - code coverage report
Current view: top level - /opt/artdaq/srcs/artdaq-mfextensions/ErrorHandler/MessageAnalyzer - ma_action_mail.cpp (source / functions) Coverage Total Hit
Test: artdaq.info.cleaned Lines: 0.0 % 32 0
Test Date: 2025-09-04 00:45:34 Functions: 0.0 % 4 0

            Line data    Source code
       1              : #include "ErrorHandler/MessageAnalyzer/ma_action_mail.h"
       2              : 
       3              : #include <stdio.h>
       4              : #include <unistd.h>
       5              : #include <iostream>
       6              : #include <sstream>
       7              : // #include <sys/types.h>
       8              : // #include <sys/wait.h>
       9              : 
      10              : using namespace novadaq::errorhandler;
      11              : 
      12            0 : REG_MA_ACTION(mail, ma_action_mail)
      13              : 
      14              : namespace {
      15              : 
      16            0 : int RunCommand(std::string const& strCmd, std::string const& strParam)
      17              : {
      18              :         int iForkId, iStatus;
      19            0 :         iForkId = vfork();
      20            0 :         if (iForkId == 0)  // This is the child
      21              :         {
      22            0 :                 std::string command = strCmd + " " + strParam;
      23              : 
      24            0 :                 iStatus = execl("/bin/sh", "sh", "-c", command.c_str(), (char*)NULL);
      25            0 :                 exit(iStatus);  // We must exit here,
      26              :                                 // or we will have multiple
      27              :                                 // mainlines running...
      28              :         }
      29            0 :         else if (iForkId > 0)  // Parent, no error
      30              :         {
      31            0 :                 iStatus = 0;
      32              :         }
      33              :         else  // Parent, with error (iForkId == -1)
      34              :         {
      35            0 :                 iStatus = -1;
      36              :         }
      37            0 :         return (iStatus);
      38              : }
      39              : 
      40              : }  // namespace
      41              : 
      42            0 : ma_action_mail::ma_action_mail(ma_rule const* rule, pset_t const& pset)
      43            0 :     : ma_action(rule, pset)
      44              : {
      45            0 :         std::stringstream ss;
      46              :         // ss << (std::string)getenv("FHICL_FILE_PATH");
      47            0 :         ss << (std::string)getenv("SRT_PRIVATE_CONTEXT") << ":"
      48            0 :            << (std::string)getenv("SRT_PUBLIC_CONTEXT") << ":.";
      49            0 :         std::string token;
      50            0 :         std::stringstream mail_file;
      51              : 
      52              :         // search for mail bash file using FHICL_FILE_PATH
      53            0 :         while (std::getline(ss, token, ':'))
      54              :         {
      55            0 :                 mail_file.str("");
      56            0 :                 mail_file << token << "/ErrorHandler/cxx/config/send_mail.sh";
      57            0 :                 std::stringstream sys_check;
      58            0 :                 sys_check << "-f " << mail_file.str();
      59              :                 // exit loop if file exists
      60            0 :                 if (system(&sys_check.str()[0])) break;
      61            0 :         }
      62              : 
      63            0 :         script_name = mail_file.str();  // pset.get<std::string>("name");
      64            0 :         script_para = pset.get<std::string>("param", std::string());
      65              : 
      66            0 :         param.init(rule, script_para);
      67            0 : }
      68              : 
      69            0 : bool ma_action_mail::exec()
      70              : {
      71            0 :         RunCommand(script_name, param.message());
      72            0 :         return true;
      73              : }
        

Generated by: LCOV version 2.0-1