Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Fix unitialized variable
[simgrid.git] / src / mc / simgrid_mc.cpp
index 982bd8e..f06240e 100644 (file)
@@ -4,6 +4,8 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
+#include <exception>
+
 #include <cstdlib>
 #include <cstdio>
 #include <cstring>
@@ -16,6 +18,7 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/wait.h>
+#include <sys/prctl.h>
 
 #include <xbt/log.h>
 
@@ -26,7 +29,9 @@
 #include "mc_private.h"
 #include "mc_protocol.h"
 #include "mc_server.h"
-#include "mc_model_checker.h"
+#include "mc_safety.h"
+#include "mc_comm_pattern.h"
+#include "mc_liveness.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_main, mc, "Entry point for simgrid-mc");
 
@@ -35,6 +40,10 @@ static const bool trace = true;
 static int do_child(int socket, char** argv)
 {
   XBT_DEBUG("Inside the child process PID=%i", (int) getpid());
+  if (prctl(PR_SET_PDEATHSIG, SIGHUP) != 0) {
+    std::perror("simgrid-mc");
+    return MC_SERVER_ERROR;
+  }
   int res;
 
   // Remove CLOEXEC in order to pass the socket to the exec-ed program:
@@ -67,11 +76,26 @@ static int do_child(int socket, char** argv)
 static int do_parent(int socket, pid_t child)
 {
   XBT_DEBUG("Inside the parent process");
-  if (MC_server_init(child, socket))
-    return MC_SERVER_ERROR;
-  XBT_DEBUG("Server initialized");
-  MC_server_run();
-  return 0;
+  if (mc_server)
+    xbt_die("MC server already present");
+  try {
+    mc_mode = MC_MODE_SERVER;
+    mc_server = new s_mc_server(child, socket);
+    mc_server->start();
+    MC_init_model_checker(child, socket);
+    if (_sg_mc_comms_determinism || _sg_mc_send_determinism)
+      MC_modelcheck_comm_determinism();
+    else if (!_sg_mc_property_file || _sg_mc_property_file[0] == '\0')
+      MC_modelcheck_safety();
+    else
+      MC_modelcheck_liveness();
+    mc_server->shutdown();
+    mc_server->exit();
+  }
+  catch(std::exception& e) {
+    XBT_ERROR(e.what());
+  }
+  exit(MC_SERVER_ERROR);
 }
 
 static char** argvdup(int argc, char** argv)
@@ -94,7 +118,7 @@ int main(int argc, char** argv)
   if (argc < 2)
     xbt_die("Missing arguments.\n");
 
-  bool server_mode = false;
+  bool server_mode = true;
   char* env = std::getenv("SIMGRID_MC_MODE");
   if (env) {
     if (std::strcmp(env, "server") == 0)
@@ -102,7 +126,7 @@ int main(int argc, char** argv)
     else if (std::strcmp(env, "standalone") == 0)
       server_mode = false;
     else
-      XBT_WARN("Unrecognised value for SIMGRID_MC_MODE (server/standalone)");
+      xbt_die("Unrecognised value for SIMGRID_MC_MODE (server/standalone)");
   }
 
   if (!server_mode) {