diff --git a/bshell.runtime/runtime/runtime.c b/bshell.runtime/runtime/runtime.c index 27eef01..a716ef5 100644 --- a/bshell.runtime/runtime/runtime.c +++ b/bshell.runtime/runtime/runtime.c @@ -1,9 +1,23 @@ #include "scope.h" #include +#include #include #include +static fx_once global_once = FX_ONCE_INIT; + +static void cleanup_globals(void) +{ + bshell_cleanup_all_verbs(); +} + +static void init_globals(void) +{ + bshell_init_all_verbs(); + bshell_table_init(); +} + struct bshell_runtime *bshell_runtime_create(void) { struct bshell_runtime *out = malloc(sizeof *out); @@ -16,6 +30,11 @@ struct bshell_runtime *bshell_runtime_create(void) out->rt_global = runtime_push_scope(out, RUNTIME_SCOPE_GLOBAL, NULL); out->rt_aliases = fx_hashtable_create(); + if (fx_init_once(&global_once)) { + init_globals(); + atexit(cleanup_globals); + } + return out; }