Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Allow to disable simgrid cleanups at exit from command line option.
authorArnaud Legrand <arnaud.legrand@imag.fr>
Wed, 21 Aug 2013 12:27:13 +0000 (14:27 +0200)
committerArnaud Legrand <arnaud.legrand@imag.fr>
Wed, 21 Aug 2013 12:27:13 +0000 (14:27 +0200)
ChangeLog
src/msg/msg_global.c
src/simgrid/sg_config.c
src/simix/smx_global.c
src/xbt/xbt_main.c

index 409ae17..1f98654 100644 (file)
--- 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
    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
 
  Java:
  * Reintegrate Java to the main archive as desynchronizing these
index 0a1f1d6..8c891e9 100644 (file)
@@ -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);
 
   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
 }
 
 #ifdef MSG_USE_DEPRECATED
index 4dfa5d3..f66e1bf 100644 (file)
@@ -834,6 +834,13 @@ void sg_config_init(int *argc, char **argv)
                     NULL);
 #endif // HAVE_SMPI
 
                     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();
     if (!surf_path) {
       /* retrieves the current directory of the        current process */
       const char *initial_path = __surf_get_initial_path();
index c578d51..79c866d 100644 (file)
@@ -10,6 +10,7 @@
 #include "xbt/str.h"
 #include "xbt/ex.h"             /* ex_backtrace_display */
 #include "mc/mc.h"
 #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,
 
 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);
 
 
   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);
 }
 
 /**
 }
 
 /**
index 773e3c5..59b050c 100644 (file)
@@ -18,6 +18,8 @@
 
 #include "xbt_modinter.h"       /* prototype of other module's init/exit in XBT */
 
 
 #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");
 
 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);
 
   srand(seed);
   srand48(seed);
 
-  atexit(xbt_postexit);   
 }
 
 static void xbt_postexit(void)
 {
 }
 
 static void xbt_postexit(void)
 {
+  if(!sg_cfg_get_boolean("clean_atexit")) return;
   xbt_backtrace_postexit();
   xbt_fifo_postexit();
   xbt_dict_postexit();
   xbt_backtrace_postexit();
   xbt_fifo_postexit();
   xbt_dict_postexit();