diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/PrintMsg.cxx b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/PrintMsg.cxx index 2085e6a92a2111c591db8a85ccb4170bcca0edfc..77d64e14bef31bcff5f40ebb01420a6d04c2c911 100644 --- a/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/PrintMsg.cxx +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/PrintMsg.cxx @@ -14,7 +14,9 @@ #include <RootCoreUtils/PrintMsg.h> #include <TString.h> +#include <RootCoreUtils/Assert.h> #include <RootCoreUtils/Message.h> +#include <cstdlib> // // method implementations @@ -49,4 +51,36 @@ namespace RCU { send_message (package, file, line, type, msg.Data()); } + + + + void send_message_abort (const char *package, const char *file, unsigned line, + MessageType type, const char *msg) + { + Message message; + message.package = package; + message.file = file; + message.line = line; + message.type = type; + message.message = msg; + message.send (); + RCU_ASSERT0 ("shouldn't get here"); + std::abort (); + } + + + + void send_message_abort (const char *package, const char *file, unsigned line, + MessageType type, const std::string& msg) + { + send_message_abort (package, file, line, type, msg.c_str()); + } + + + + void send_message_abort (const char *package, const char *file, unsigned line, + MessageType type, const TString& msg) + { + send_message_abort (package, file, line, type, msg.Data()); + } } diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/ShellExec.cxx b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/ShellExec.cxx index 3e3eec5a65f17529af9fe3a33746601e8bd0cade..d487400d8ea920e92fdbd0200a155e3334d8b8b1 100644 --- a/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/ShellExec.cxx +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/ShellExec.cxx @@ -35,6 +35,17 @@ namespace RCU std::string exec_read (const std::string& cmd) + { + int rc = 0; + std::string result = exec_read (cmd, rc); + if (rc != 0) + RCU_THROW_MSG ("command failed: " + cmd + "\nwith output:\n" + result); + return result; + } + + + + std::string exec_read (const std::string& cmd, int& rc) { std::string result; FILE *pipe = 0; @@ -48,15 +59,15 @@ namespace RCU { result.append (&buffer[0], read); } + rc = pclose (pipe); + pipe = nullptr; + return result; } catch (...) { if (pipe) - pclose (pipe); + rc = pclose (pipe); throw; } - if (pclose (pipe) != 0) - RCU_THROW_MSG ("command failed: " + cmd + "\nwith output:\n" + result); - return result; } diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/PrintMsg.h b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/PrintMsg.h index d2ef773550b6aae35764bd63dd92790146bd3a74..d4349a8552b6749b05839aa7711a89dd68d0eb0f 100644 --- a/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/PrintMsg.h +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/PrintMsg.h @@ -31,6 +31,15 @@ namespace RCU MessageType type, const std::string& msg); void send_message (const char *package, const char *file, unsigned line, MessageType type, const TString& msg); + [[noreturn]] void + send_message_abort (const char *package, const char *file, unsigned line, + MessageType type, const char *msg); + [[noreturn]] void + send_message_abort (const char *package, const char *file, unsigned line, + MessageType type, const std::string& msg); + [[noreturn]] void + send_message_abort (const char *package, const char *file, unsigned line, + MessageType type, const TString& msg); } #ifndef ROOTCORE_PACKAGE @@ -47,6 +56,6 @@ namespace RCU ::RCU::send_message (ROOTCORE_PACKAGE, __FILE__, __LINE__, ::RCU::MESSAGE_ERROR, (message)); #define RCU_THROW_MSG(message) \ - ::RCU::send_message (ROOTCORE_PACKAGE, __FILE__, __LINE__, ::RCU::MESSAGE_EXCEPTION, (message)); + ::RCU::send_message_abort (ROOTCORE_PACKAGE, __FILE__, __LINE__, ::RCU::MESSAGE_EXCEPTION, (message)); #endif diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/ShellExec.h b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/ShellExec.h index b977dec847ebb4acdc19ec3b9f307a4ae3ba30bb..f40c72b9b0855000773f7c64f6e0391d11e00cf9 100644 --- a/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/ShellExec.h +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/ShellExec.h @@ -41,6 +41,15 @@ namespace RCU std::string exec_read (const std::string& cmd); + /// effects: execute the given command and return the output + /// returns: the output of the command + /// guarantee: strong + /// failures: out of memory III + /// failures: system failure + /// failures: command failure + std::string exec_read (const std::string& cmd, int& rc); + + /// effects: quote the given name to protect it from the shell /// returns: the quoted name /// guarantee: strong