X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/7207080bb744f50a6d8c418f25d82ad69e9b4f44..7f5e78a43b4bed7bae8304ad12de6e2e555b34db:/src/mc/Session.cpp diff --git a/src/mc/Session.cpp b/src/mc/Session.cpp index 87ed0f5073..4d73338e5f 100644 --- a/src/mc/Session.cpp +++ b/src/mc/Session.cpp @@ -77,16 +77,35 @@ pid_t do_fork(F code) } } -Session::Session(pid_t pid, int socket) +Session::Session(const std::function& code) { - std::unique_ptr process(new simgrid::mc::RemoteClient(pid, socket)); - #if HAVE_SMPI xbt_assert(smpi_privatize_global_variables != SmpiPrivStrategies::MMAP, "Please use the dlopen privatization schema when model-checking SMPI code"); #endif + // Create a AF_LOCAL socketpair used for exchanging messages + // between the model-checker process (ourselves) and the model-checked + // process: + int res; + int sockets[2]; + res = socketpair(AF_LOCAL, SOCK_SEQPACKET | SOCK_CLOEXEC, 0, sockets); + if (res == -1) + throw simgrid::xbt::errno_error("Could not create socketpair"); + + pid_t pid = do_fork([sockets, &code] { + ::close(sockets[1]); + setup_child_environment(sockets[0]); + code(); + xbt_die("The model-checked process failed to exec()"); + }); + + // Parent (model-checker): + ::close(sockets[0]); + + std::unique_ptr process(new simgrid::mc::RemoteClient(pid, sockets[1])); model_checker_.reset(new simgrid::mc::ModelChecker(std::move(process))); + xbt_assert(mc_model_checker == nullptr); mc_model_checker = model_checker_.get(); mc_model_checker->start(); @@ -129,47 +148,6 @@ void Session::log_state() } } -// static -Session* Session::fork(const std::function& code) -{ - // Create a AF_LOCAL socketpair used for exchanging messages - // between the model-checker process (ourselves) and the model-checked - // process: - int res; - int sockets[2]; - res = socketpair(AF_LOCAL, SOCK_SEQPACKET | SOCK_CLOEXEC, 0, sockets); - if (res == -1) - throw simgrid::xbt::errno_error("Could not create socketpair"); - - pid_t pid = do_fork([sockets, &code] { - ::close(sockets[1]); - setup_child_environment(sockets[0]); - code(); - xbt_die("The model-checked process failed to exec()"); - }); - - // Parent (model-checker): - ::close(sockets[0]); - - return new Session(pid, sockets[1]); -} - -// static -Session* Session::spawnv(const char *path, char *const argv[]) -{ - return Session::fork([path, argv] { - execv(path, argv); - }); -} - -// static -Session* Session::spawnvp(const char *file, char *const argv[]) -{ - return Session::fork([file, argv] { - execvp(file, argv); - }); -} - void Session::close() { initial_snapshot_ = nullptr;