extern struct lytype_plugin_list frr_user_types[];
#endif
+struct ly_ctx *yang_ctx_new_setup(void)
+{
+ struct ly_ctx *ctx;
+ const char *yang_models_path = YANG_MODELS_PATH;
+
+ if (access(yang_models_path, R_OK | X_OK)) {
+ yang_models_path = NULL;
+ if (errno == ENOENT)
+ zlog_info("yang model directory \"%s\" does not exist",
+ YANG_MODELS_PATH);
+ else
+ flog_err_sys(EC_LIB_LIBYANG,
+ "cannot access yang model directory \"%s\"",
+ YANG_MODELS_PATH);
+ }
+
+ ctx = ly_ctx_new(yang_models_path, LY_CTX_DISABLE_SEARCHDIR_CWD);
+ if (!ctx)
+ return NULL;
+ ly_ctx_set_module_imp_clb(ctx, yang_module_imp_clb, NULL);
+ return ctx;
+}
+
void yang_init(void)
{
#ifndef LIBYANG_EXT_BUILTIN
#endif
/* Initialize libyang container for native models. */
- ly_native_ctx =
- ly_ctx_new(YANG_MODELS_PATH, LY_CTX_DISABLE_SEARCHDIR_CWD);
+ ly_native_ctx = yang_ctx_new_setup();
if (!ly_native_ctx) {
flog_err(EC_LIB_LIBYANG, "%s: ly_ctx_new() failed", __func__);
exit(1);
}
- ly_ctx_set_module_imp_clb(ly_native_ctx, yang_module_imp_clb, NULL);
ly_ctx_set_priv_dup_clb(ly_native_ctx, ly_dup_cb);
#ifndef LIBYANG_EXT_BUILTIN
*/
extern struct list *yang_data_list_new(void);
+/*
+ * Create and set up a libyang context (for use by the translator)
+ */
+extern struct ly_ctx *yang_ctx_new_setup(void);
+
/*
* Initialize the YANG subsystem. Should be called only once during the
* daemon initialization process.
RB_INSERT(yang_translators, &yang_translators, translator);
/* Initialize the translator libyang context. */
- translator->ly_ctx =
- ly_ctx_new(YANG_MODELS_PATH, LY_CTX_DISABLE_SEARCHDIR_CWD);
+ translator->ly_ctx = yang_ctx_new_setup();
if (!translator->ly_ctx) {
flog_warn(EC_LIB_LIBYANG, "%s: ly_ctx_new() failed", __func__);
goto error;
void yang_translator_init(void)
{
- ly_translator_ctx =
- ly_ctx_new(YANG_MODELS_PATH, LY_CTX_DISABLE_SEARCHDIR_CWD);
+ ly_translator_ctx = yang_ctx_new_setup();
if (!ly_translator_ctx) {
flog_err(EC_LIB_LIBYANG, "%s: ly_ctx_new() failed", __func__);
exit(1);