diff --git a/src/cart/crt_init.c b/src/cart/crt_init.c index 352163cd58b..d4e9b212978 100644 --- a/src/cart/crt_init.c +++ b/src/cart/crt_init.c @@ -53,6 +53,9 @@ crt_lib_init(void) crt_gdata.cg_rpcid = start_rpcid; crt_gdata.cg_num_cores = sysconf(_SC_NPROCESSORS_ONLN); crt_gdata.cg_iv_inline_limit = 19456; /* 19KB */ + + /* envs not inited until crt_init() time */ + memset(&g_envs, 0x0, sizeof(struct crt_envs_t)); } /* Library deinit */ @@ -560,7 +563,7 @@ crt_init_opt(crt_group_id_t grpid, uint32_t flags, crt_init_options_t *opt) crt_setup_log_fac(); - D_INFO("libcart version %s initializing\n", CART_VERSION); + D_INFO("libcart (%s) v%s initializing\n", server ? "server" : "client", CART_VERSION); crt_env_init(); if (opt) diff --git a/src/cart/crt_internal_types.h b/src/cart/crt_internal_types.h index 6776ab046e9..57c279c070d 100644 --- a/src/cart/crt_internal_types.h +++ b/src/cart/crt_internal_types.h @@ -231,6 +231,7 @@ struct crt_event_cb_priv { struct crt_envs_t { CRT_ENV_LIST; + bool inited; }; #undef ENV @@ -238,11 +239,15 @@ struct crt_envs_t { #undef ENV_STR_NO_PRINT extern struct crt_envs_t g_envs; +static inline void crt_env_fini(void); static inline void crt_env_init(void) { - memset(&g_envs, 0x0, sizeof(struct crt_envs_t)); + /* release strings if already inited previously */ + if (g_envs.inited) + crt_env_fini(); + #define ENV(x) \ do { \ g_envs._rc_##x = d_getenv_uint(#x, &g_envs._##x); \ @@ -265,6 +270,8 @@ crt_env_init(void) #undef ENV #undef ENV_STR #undef ENV_STR_NO_PRINT + + g_envs.inited = true; } static inline void @@ -279,10 +286,13 @@ crt_env_fini(void) #undef ENV #undef ENV_STR #undef ENV_STR_NO_PRINT + + g_envs.inited = false; } /* Returns value if env was present at load time */ #define crt_env_get(name, val) \ + D_ASSERT(g_envs.inited); \ if (g_envs._rc_##name == 0) \ *val = g_envs._##name; diff --git a/src/cart/utils/crt_utils.c b/src/cart/utils/crt_utils.c index a48d80f11bf..7e3ed2b80d8 100644 --- a/src/cart/utils/crt_utils.c +++ b/src/cart/utils/crt_utils.c @@ -652,9 +652,6 @@ crtu_srv_start_basic(char *srv_group_name, crt_context_t *crt_ctx, if (opts.assert_on_error) D_ASSERTF(opts.is_initialized == true, "crtu_test_init not called.\n"); - crt_env_get(CRT_L_RANK, &my_rank); - D_ASSERTF(rc == DER_SUCCESS, "Rank can not be retrieve: " DF_RC "\n", DP_RC(rc)); - rc = d_log_init(); if (rc != 0) D_GOTO(out, rc); @@ -670,6 +667,12 @@ crtu_srv_start_basic(char *srv_group_name, crt_context_t *crt_ctx, if (rc != 0) D_GOTO(out, rc); + crt_env_get(CRT_L_RANK, &my_rank); + if (my_rank == CRT_NO_RANK) { + D_ERROR("CRT_L_RANK environment variable should have been set by crt_launch\n"); + D_GOTO(out, rc = -DER_INVAL); + } + *grp = crt_group_lookup(NULL); if (!(*grp)) { D_ERROR("Group lookup failed\n");