* src/misc/satsolver.cc: Report when SAT-solver terminate by signal.

This commit is contained in:
Alexandre Duret-Lutz 2013-09-04 16:20:51 +02:00
parent 22f944ad56
commit 88cd81c547

View file

@ -25,6 +25,7 @@
#include "satsolver.hh" #include "satsolver.hh"
#include <fstream> #include <fstream>
#include <limits> #include <limits>
#include <sys/wait.h>
namespace spot namespace spot
{ {
@ -58,7 +59,26 @@ namespace spot
declare('O', out); declare('O', out);
std::ostringstream s; std::ostringstream s;
format(s, satsolver); format(s, satsolver);
return system(s.str().c_str()); int res = system(s.str().c_str());
if (res < 0 || (WIFEXITED(res) && WEXITSTATUS(res) == 127))
{
s << ": failed to execute";
throw std::runtime_error(s.str());
}
// For POSIX shells, "The exit status of a command that
// terminated because it received a signal shall be reported
// as greater than 128."
if (WIFEXITED(res) && WEXITSTATUS(res) >= 128)
{
s << ": terminated by signal";
throw std::runtime_error(s.str());
}
if (WIFSIGNALED(res))
{
s << ": terminated by signal " << WTERMSIG(res);
throw std::runtime_error(s.str());
}
return res;
} }
}; };
} }