Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Move mc_liveness code in simgrid::mc
[simgrid.git] / src / mc / simgrid_mc.cpp
index f6e998d..04112ca 100644 (file)
@@ -27,6 +27,8 @@
 #endif
 
 #include <xbt/log.h>
+#include <xbt/sysdep.h>
+#include <xbt/system_error.hpp>
 
 #include "simgrid/sg_config.h"
 #include "src/xbt_modinter.h"
@@ -48,7 +50,7 @@ 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;
 
@@ -73,19 +75,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,7 +118,7 @@ std::pair<pid_t, int> 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]);
@@ -137,7 +137,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;
 }
 
@@ -175,7 +175,7 @@ int main(int argc, char** argv)
     else if (!_sg_mc_property_file || _sg_mc_property_file[0] == '\0')
       res = MC_modelcheck_safety();
     else
-      res = MC_modelcheck_liveness();
+      res = simgrid::mc::modelcheck_liveness();
     mc_model_checker->shutdown();
     return res;
   }