X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/11ca718deb6ce1b2e4eb6978fd5a953b187ad511..8bf3a516fdf97bea1405fb0d2499ecc446ae61e2:/src/mc/simgrid_mc.cpp diff --git a/src/mc/simgrid_mc.cpp b/src/mc/simgrid_mc.cpp index f6e998d825..0c3a6f481e 100644 --- a/src/mc/simgrid_mc.cpp +++ b/src/mc/simgrid_mc.cpp @@ -12,6 +12,7 @@ #include +#include #include #include @@ -27,6 +28,8 @@ #endif #include +#include +#include #include "simgrid/sg_config.h" #include "src/xbt_modinter.h" @@ -48,14 +51,14 @@ pid_t do_fork(F f) { pid_t pid = fork(); if (pid < 0) - throw new std::system_error(errno, std::generic_category()); + throw simgrid::xbt::errno_error(errno, "Could not fork model-checked process"); if (pid != 0) return pid; // Child-process: try { f(); - std::exit(EXIT_SUCCESS); + _exit(EXIT_SUCCESS); } catch(...) { // The callback should catch exceptions: @@ -73,19 +76,17 @@ int exec_model_checked(int socket, char** argv) sigset_t mask; sigemptyset (&mask); if (sigprocmask(SIG_SETMASK, &mask, nullptr) < 0) - throw new std::system_error(errno, std::generic_category(), "sigprocmask"); + throw simgrid::xbt::errno_error(errno, "Could not unblock signals"); if (prctl(PR_SET_PDEATHSIG, SIGHUP) != 0) - throw new std::system_error(errno, std::generic_category(), "PR_SET_PDEATHSIG"); + throw simgrid::xbt::errno_error(errno, "Could not PR_SET_PDEATHSIG"); #endif int res; // Remove CLOEXEC in order to pass the socket to the exec-ed program: int fdflags = fcntl(socket, F_GETFD, 0); - if (fdflags == -1) - throw new std::system_error(errno, std::generic_category(), "F_GETFD"); - if (fcntl(socket, F_SETFD, fdflags & ~FD_CLOEXEC) == -1) - throw new std::system_error(errno, std::generic_category(), "Remove FD_CLOEXEC"); + if (fdflags == -1 || fcntl(socket, F_SETFD, fdflags & ~FD_CLOEXEC) == -1) + throw simgrid::xbt::errno_error(errno, "Could not remove CLOEXEC for socket"); // Set environment: setenv(MC_ENV_VARIABLE, "1", 1); @@ -118,13 +119,13 @@ std::pair create_model_checked(char** argv) int sockets[2]; res = socketpair(AF_LOCAL, SOCK_DGRAM | SOCK_CLOEXEC, 0, sockets); if (res == -1) - throw new std::system_error(errno, std::generic_category(), "socketpair"); + throw simgrid::xbt::errno_error(errno, "Could not create socketpair"); pid_t pid = do_fork([&] { close(sockets[1]); int res = exec_model_checked(sockets[0], argv); XBT_DEBUG("Error in the child process creation"); - exit(res); + _exit(res); }); // Parent (model-checker): @@ -137,7 +138,7 @@ char** argvdup(int argc, char** argv) { char** argv_copy = xbt_new(char*, argc+1); std::memcpy(argv_copy, argv, sizeof(char*) * argc); - argv_copy[argc] = NULL; + argv_copy[argc] = nullptr; return argv_copy; } @@ -173,9 +174,9 @@ int main(int argc, char** argv) if (_sg_mc_comms_determinism || _sg_mc_send_determinism) res = MC_modelcheck_comm_determinism(); else if (!_sg_mc_property_file || _sg_mc_property_file[0] == '\0') - res = MC_modelcheck_safety(); + res = simgrid::mc::modelcheck_safety(); else - res = MC_modelcheck_liveness(); + res = simgrid::mc::modelcheck_liveness(); mc_model_checker->shutdown(); return res; }