DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::oks::CommandOutput Struct Reference

Public Member Functions

 CommandOutput (const char *command_name, const OksKernel *k, std::string &cmd)
 
 ~CommandOutput ()
 
const std::string & file_name () const
 
std::string cat2str () const
 
std::string last_str () const
 
void check_command_status (int status)
 

Public Attributes

std::string p_file_name
 
std::string & p_command
 
const char * p_command_name
 

Detailed Description

Definition at line 4765 of file kernel.cpp.

Constructor & Destructor Documentation

◆ CommandOutput()

dunedaq::oks::CommandOutput::CommandOutput ( const char * command_name,
const OksKernel * k,
std::string & cmd )

Definition at line 4782 of file kernel.cpp.

4782 :
4783p_command(cmd), p_command_name(command_name)
4784{
4785 p_file_name = get_temporary_dir() + '/' + command_name + '.' + std::to_string(getpid()) + ':' + std::to_string(reinterpret_cast<std::uintptr_t>(k)) + ".txt";
4786
4787 p_command.append(" &>");
4788 p_command.append(p_file_name);
4789}

◆ ~CommandOutput()

dunedaq::oks::CommandOutput::~CommandOutput ( )

Definition at line 4791 of file kernel.cpp.

4792{
4793 unlink(p_file_name.c_str());
4794}

Member Function Documentation

◆ cat2str()

std::string dunedaq::oks::CommandOutput::cat2str ( ) const

Definition at line 4797 of file kernel.cpp.

4798{
4799 std::ifstream f(p_file_name.c_str());
4800 std::string out;
4801
4802 if(f) {
4803 std::filebuf * buf = f.rdbuf();
4804 while(true) {
4805 char c = buf->sbumpc();
4806 if(c == EOF) break;
4807 else out += c;
4808 }
4809 }
4810
4811 return out;
4812}
FELIX Initialization std::string initerror FELIX queue timed out

◆ check_command_status()

void dunedaq::oks::CommandOutput::check_command_status ( int status)

Definition at line 4844 of file kernel.cpp.

4845{
4846 if (status == -1)
4847 {
4848 std::ostringstream text;
4849 text << "cannot execute command \'" << p_command << "\': " << strerror(errno);
4850 throw RepositoryOperationFailed(p_command_name, text.str());
4851 }
4852 else if (int error_code = WEXITSTATUS(status))
4853 {
4854 std::ostringstream text;
4855 text << p_command.substr(0, p_command.find_first_of(' ')) << " exit with error code " << error_code << ", output:\n" << cat2str();
4856 throw RepositoryOperationFailed(p_command_name, text.str());
4857 }
4858}
const std::string strerror(int error)
Convert C error number to string.
Definition kernel.cpp:114
std::string cat2str() const
Definition kernel.cpp:4797

◆ file_name()

const std::string & dunedaq::oks::CommandOutput::file_name ( ) const
inline

Definition at line 4770 of file kernel.cpp.

4770{return p_file_name;}

◆ last_str()

std::string dunedaq::oks::CommandOutput::last_str ( ) const

Definition at line 4815 of file kernel.cpp.

4816{
4817 std::ifstream f(p_file_name.c_str());
4818 std::string lastline;
4819
4820 if (f.is_open())
4821 {
4822 f.seekg(-1, std::ios_base::end);
4823 if (f.peek() == '\n')
4824 {
4825 f.seekg(-1, std::ios_base::cur);
4826 for (int i = f.tellg(); i >= 0; i--)
4827 {
4828 if (f.peek() == '\n')
4829 {
4830 f.get();
4831 break;
4832 }
4833 f.seekg(i, std::ios_base::beg);
4834 }
4835 }
4836
4837 getline(f, lastline);
4838 }
4839 return lastline;
4840}

Member Data Documentation

◆ p_command

std::string& dunedaq::oks::CommandOutput::p_command

Definition at line 4777 of file kernel.cpp.

◆ p_command_name

const char* dunedaq::oks::CommandOutput::p_command_name

Definition at line 4778 of file kernel.cpp.

◆ p_file_name

std::string dunedaq::oks::CommandOutput::p_file_name

Definition at line 4776 of file kernel.cpp.


The documentation for this struct was generated from the following file: