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 4536 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 4553 of file kernel.cpp.

4554 : p_command(cmd)
4555 , p_command_name(command_name)
4556{
4557 p_file_name = get_temporary_dir() + '/' + command_name + '.' + std::to_string(getpid()) + ':' +
4558 std::to_string(reinterpret_cast<std::uintptr_t>(k)) + ".txt";
4559
4560 p_command.append(" &>");
4561 p_command.append(p_file_name);
4562}

◆ ~CommandOutput()

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

Definition at line 4564 of file kernel.cpp.

4565{
4566 unlink(p_file_name.c_str());
4567}

Member Function Documentation

◆ cat2str()

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

Definition at line 4570 of file kernel.cpp.

4571{
4572 std::ifstream f(p_file_name.c_str());
4573 std::string out;
4574
4575 if (f) {
4576 std::filebuf* buf = f.rdbuf();
4577 while (true) {
4578 char c = buf->sbumpc();
4579 if (c == EOF)
4580 break;
4581 else
4582 out += c;
4583 }
4584 }
4585
4586 return out;
4587}
FELIX Initialization std::string initerror FELIX queue timed out

◆ check_command_status()

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

Definition at line 4614 of file kernel.cpp.

4615{
4616 if (status == -1) {
4617 std::ostringstream text;
4618 text << "cannot execute command \'" << p_command << "\': " << strerror(errno);
4619 throw RepositoryOperationFailed(p_command_name, text.str());
4620 } else if (int error_code = WEXITSTATUS(status)) {
4621 std::ostringstream text;
4622 text << p_command.substr(0, p_command.find_first_of(' ')) << " exit with error code " << error_code << ", output:\n"
4623 << cat2str();
4624 throw RepositoryOperationFailed(p_command_name, text.str());
4625 }
4626}
RepositoryOperationFailed(const char *op, const exception &reason) noexcept
Definition kernel.hpp:120
const std::string strerror(int error)
Convert C error number to string.
Definition kernel.cpp:111
std::string cat2str() const
Definition kernel.cpp:4570

◆ file_name()

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

Definition at line 4542 of file kernel.cpp.

4542{ return p_file_name; }

◆ last_str()

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

Definition at line 4590 of file kernel.cpp.

4591{
4592 std::ifstream f(p_file_name.c_str());
4593 std::string lastline;
4594
4595 if (f.is_open()) {
4596 f.seekg(-1, std::ios_base::end);
4597 if (f.peek() == '\n') {
4598 f.seekg(-1, std::ios_base::cur);
4599 for (int i = f.tellg(); i >= 0; i--) {
4600 if (f.peek() == '\n') {
4601 f.get();
4602 break;
4603 }
4604 f.seekg(i, std::ios_base::beg);
4605 }
4606 }
4607
4608 getline(f, lastline);
4609 }
4610 return lastline;
4611}

Member Data Documentation

◆ p_command

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

Definition at line 4549 of file kernel.cpp.

◆ p_command_name

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

Definition at line 4550 of file kernel.cpp.

◆ p_file_name

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

Definition at line 4548 of file kernel.cpp.


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