X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/loba.git/blobdiff_plain/72b259695914c93a27739cad3c186aefbe78a01b..75ce3cba194ed6afe0cf65799876b457da5bdb2b:/main.cpp diff --git a/main.cpp b/main.cpp index 8a1d5c8..9b0f8bf 100644 --- a/main.cpp +++ b/main.cpp @@ -4,6 +4,7 @@ #include // strchr #include #include +#include #include #include @@ -23,6 +24,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main); #include "misc.h" #include "options.h" #include "process.h" +#include "simgrid_features.h" #include "statistics.h" #include "synchro.h" #include "timer.h" @@ -149,6 +151,15 @@ static bool check_for_lost_load() return res; } +static void check_file_access(const std::string& name) +{ + if (access(name.c_str(), R_OK) != 0) { + std::cerr << "ERROR: cannot access to file \"" + << name << "\" for reading: " << strerror(errno) << "\n"; + exit(EXIT_FAILURE_ARGS); + } +} + static void signal_handler(int /*sig*/) { if (!opt::exit_request) { @@ -171,19 +182,19 @@ static void install_signal_handler() sigemptyset(&action.sa_mask); action.sa_flags = SA_RESTART; if (sigaction(SIGINT, &action, NULL) == -1) { - std::cerr << "sigaction: " << strerror(errno) << "\n"; + std::cerr << "ERROR: sigaction: " << strerror(errno) << "\n"; exit(EXIT_FAILURE_OTHER); } } #define PR_VALUE(descr, format, ...) \ XBT_INFO("| %.*s: " format, DATA_DESCR_WIDTH, \ - descr ".................................................", \ + descr " ................................................", \ __VA_ARGS__) #define PR_STATS(descr, st) \ XBT_INFO("| %.*s: %g / %g / %g", DATA_DESCR_WIDTH, \ - descr " (sum/avg/dev)...................................", \ + descr " (sum/avg/dev) ..................................", \ st.get_sum(), st.get_mean(), st.get_stddev()) int main(int argc, char* argv[]) @@ -192,7 +203,7 @@ int main(int argc, char* argv[]) double simulated_time = -1.0; timestamp elapsed_time(timestamp::wallclock_time); timestamp simulation_time(timestamp::cpu_time); - MSG_error_t res; + msg_error_t res; elapsed_time.start(); simulation_time.start(); @@ -209,7 +220,7 @@ int main(int argc, char* argv[]) } // Initialize some MSG internal data. - MSG_global_init(&argc, argv); + MSG_init(&argc, argv); install_signal_handler(); // Parse global parameters @@ -236,6 +247,7 @@ int main(int argc, char* argv[]) // Create the platform and the application. XBT_DEBUG("Loading platform file..."); + check_file_access(opt::platform_file); MSG_create_environment(opt::platform_file.c_str()); XBT_DEBUG("Creating hostdata..."); hostdata::create(); @@ -264,6 +276,7 @@ int main(int argc, char* argv[]) } MY_launch_application(); // it is already opt::* aware... } else { + check_file_access(opt::deployment_file); MSG_launch_application(opt::deployment_file.c_str()); } @@ -274,6 +287,7 @@ int main(int argc, char* argv[]) proc_mutex = new mutex_t(); proc_cond = new condition_t(); + process::set_proc_mutex(proc_mutex); // Launch the MSG simulation. XBT_INFO("Starting simulation at %f...", MSG_get_clock()); @@ -281,6 +295,7 @@ int main(int argc, char* argv[]) simulated_time = MSG_get_clock(); XBT_INFO("Simulation ended at %f.", simulated_time); + process::set_proc_mutex(NULL); delete proc_cond; delete proc_mutex;