From 4fff3fb509f60c96745fb5d3e1be1bd824185366 Mon Sep 17 00:00:00 2001 From: Arnaud Legrand Date: Wed, 21 Aug 2013 14:27:13 +0200 Subject: [PATCH] Allow to disable simgrid cleanups at exit from command line option. --- ChangeLog | 5 +++++ src/msg/msg_global.c | 2 +- src/simgrid/sg_config.c | 7 +++++++ src/simix/smx_global.c | 3 ++- src/xbt/xbt_main.c | 4 +++- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 409ae178ca..1f98654688 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,11 @@ SimGrid (3.10) NOT RELEASED; urgency=low used even if the OS provide a getline(). This should reduce the configuration complexity by using the same code on all platforms. * new xbt_cfg_elm_boolean type + * Allow to disable simgrid cleanups at exit from command line option. + There are situations where one may want a simulation to end with an exit. + Unfortunately, calling exit may cause SimGrid to segfault, which is quite + annoying when scripting around the simulator. Adding a + --cfg=clean_atexit:yes allows to circumvent this issue. Java: * Reintegrate Java to the main archive as desynchronizing these diff --git a/src/msg/msg_global.c b/src/msg/msg_global.c index 0a1f1d6bc1..8c891e914c 100644 --- a/src/msg/msg_global.c +++ b/src/msg/msg_global.c @@ -72,7 +72,7 @@ void MSG_init_nocheck(int *argc, char **argv) { XBT_DEBUG("ADD MSG LEVELS"); MSG_HOST_LEVEL = xbt_lib_add_level(host_lib, (void_f_pvoid_t) __MSG_host_destroy); - atexit(MSG_exit); + if(sg_cfg_get_boolean("clean_atexit")) atexit(MSG_exit); } #ifdef MSG_USE_DEPRECATED diff --git a/src/simgrid/sg_config.c b/src/simgrid/sg_config.c index 4dfa5d3762..f66e1bf2e7 100644 --- a/src/simgrid/sg_config.c +++ b/src/simgrid/sg_config.c @@ -834,6 +834,13 @@ void sg_config_init(int *argc, char **argv) NULL); #endif // HAVE_SMPI + default_value = xbt_strdup("yes"); + xbt_cfg_register(&_sg_cfg_set, "clean_atexit", + "\"yes\" or \"no\". \"yes\" enables all the cleanups of SimGrid (XBT,SIMIX,MSG) to be registered with atexit. \"no\" may be useful if your code segfaults when calling the exit function.", + xbt_cfgelm_boolean, &default_value, 1, 1, + NULL, NULL); + xbt_cfg_setdefault_boolean(_sg_cfg_set, "clean_atexit", default_value); + if (!surf_path) { /* retrieves the current directory of the current process */ const char *initial_path = __surf_get_initial_path(); diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index c578d5178e..79c866d399 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -10,6 +10,7 @@ #include "xbt/str.h" #include "xbt/ex.h" /* ex_backtrace_display */ #include "mc/mc.h" +#include "simgrid/sg_config.h" XBT_LOG_NEW_CATEGORY(simix, "All SIMIX categories"); XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_kernel, simix, @@ -108,7 +109,7 @@ void SIMIX_global_init(int *argc, char **argv) SIMIX_HOST_LEVEL = xbt_lib_add_level(host_lib,SIMIX_host_destroy); - atexit(SIMIX_clean); + if(sg_cfg_get_boolean("clean_atexit")) atexit(SIMIX_clean); } /** diff --git a/src/xbt/xbt_main.c b/src/xbt/xbt_main.c index 773e3c5b67..59b050c2a2 100644 --- a/src/xbt/xbt_main.c +++ b/src/xbt/xbt_main.c @@ -18,6 +18,8 @@ #include "xbt_modinter.h" /* prototype of other module's init/exit in XBT */ +#include "simgrid/sg_config.h" + XBT_LOG_NEW_CATEGORY(xbt, "All XBT categories (simgrid toolbox)"); XBT_LOG_NEW_DEFAULT_SUBCATEGORY(module, xbt, "module handling"); @@ -90,11 +92,11 @@ static void xbt_preinit(void) { srand(seed); srand48(seed); - atexit(xbt_postexit); } static void xbt_postexit(void) { + if(!sg_cfg_get_boolean("clean_atexit")) return; xbt_backtrace_postexit(); xbt_fifo_postexit(); xbt_dict_postexit(); -- 2.20.1