#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
+
+#ifdef __linux__
#include <sys/prctl.h>
+#endif
#include <xbt/log.h>
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_main, mc, "Entry point for simgrid-mc");
-static const bool trace = true;
-
static int do_child(int socket, char** argv)
{
XBT_DEBUG("Inside the child process PID=%i", (int) getpid());
+
+#ifdef __linux__
+ // Make sure we do not outlive our parent:
if (prctl(PR_SET_PDEATHSIG, SIGHUP) != 0) {
std::perror("simgrid-mc");
return MC_SERVER_ERROR;
}
+#endif
+
int res;
// Remove CLOEXEC in order to pass the socket to the exec-ed program:
// Set environment:
setenv(MC_ENV_VARIABLE, "1", 1);
+ // Disable lazy relocation in the model-ched process.
+ // We don't want the model-checked process to modify its .got.plt during
+ // snapshot.
+ setenv("LC_BIND_NOW", "1", 1);
+
char buffer[64];
res = std::snprintf(buffer, sizeof(buffer), "%i", socket);
if ((size_t) res >= sizeof(buffer) || res == -1)
mc_server->exit();
}
catch(std::exception& e) {
- XBT_ERROR(e.what());
+ XBT_ERROR("Exception: %s", e.what());
}
exit(MC_SERVER_ERROR);
}
int main(int argc, char** argv)
{
+ _sg_do_model_check = 1;
+
// We need to keep the original parameters in order to pass them to the
// model-checked process:
int argc_copy = argc;
if (argc < 2)
xbt_die("Missing arguments.\n");
- bool server_mode = true;
- char* env = std::getenv("SIMGRID_MC_MODE");
- if (env) {
- if (std::strcmp(env, "server") == 0)
- server_mode = true;
- else if (std::strcmp(env, "standalone") == 0)
- server_mode = false;
- else
- xbt_die("Unrecognised value for SIMGRID_MC_MODE (server/standalone)");
- }
-
- if (!server_mode) {
- setenv(MC_ENV_VARIABLE, "1", 1);
- execvp(argv[1], argv+1);
-
- std::perror("simgrid-mc");
- return 127;
- }
-
// Create a AF_LOCAL socketpair:
int res;