This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Vadim Yanitskiy gerrit-no-reply at lists.osmocom.orgVadim Yanitskiy has uploaded this change for review. ( https://gerrit.osmocom.org/13973 Change subject: libosmovty: deprecate vty_init(), add vty_init[_app]_ctx() ...................................................................... libosmovty: deprecate vty_init(), add vty_init[_app]_ctx() The main problem of vty_init() is that it's using NULL talloc context. We could modify it and start using the context from a given 'vty_app_info' structure, but this might cause the compatibility problems with the existing API users. Instead, let's deprecate vty_init() and introduce two new wrappers: - vty_init_ctx() - use a given talloc context, - vty_init_app_ctx() - use the application's talloc context. Change-Id: I65d71f8fc943e103b53b784f690ed56a6e373e3f --- M include/osmocom/vty/vty.h M src/vty/vty.c M tests/logging/logging_vty_test.c M tests/tdef/tdef_vty_test_config_root.c M tests/tdef/tdef_vty_test_config_subnode.c M tests/tdef/tdef_vty_test_dynamic.c M tests/vty/vty_test.c M tests/vty/vty_transcript_test.c 8 files changed, 45 insertions(+), 13 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/73/13973/1 diff --git a/include/osmocom/vty/vty.h b/include/osmocom/vty/vty.h index 03a2924..7461702 100644 --- a/include/osmocom/vty/vty.h +++ b/include/osmocom/vty/vty.h @@ -5,6 +5,7 @@ #include <stdbool.h> #include <osmocom/core/linuxlist.h> +#include <osmocom/core/defs.h> /*! \defgroup vty VTY (Virtual TTY) interface * @{ @@ -187,7 +188,10 @@ }; /* Prototypes. */ -void vty_init(struct vty_app_info *app_info); +void vty_init_ctx(struct vty_app_info *app_info, void *ctx); +void vty_init_app_ctx(struct vty_app_info *app_info); +void vty_init(struct vty_app_info *app_info) + OSMO_DEPRECATED("use vty_init_ctx() or vty_init_app_ctx() instead"); int vty_read_config_file(const char *file_name, void *priv); void vty_init_vtysh (void); void vty_reset (void); diff --git a/src/vty/vty.c b/src/vty/vty.c index 98b332d..2b339bb 100644 --- a/src/vty/vty.c +++ b/src/vty/vty.c @@ -1776,13 +1776,9 @@ vtyvec = vector_init(VECTOR_MIN_SIZE); } -/*! Initialize VTY layer - * \param[in] app_info application information - */ -/* Install vty's own commands like `who' command. */ -void vty_init(struct vty_app_info *app_info) +static inline void _vty_init(struct vty_app_info *app_info, void *ctx) { - tall_vty_ctx = talloc_named_const(NULL, 0, "vty"); + tall_vty_ctx = talloc_named_const(ctx, 0, "vty"); tall_vty_vec_ctx = talloc_named_const(tall_vty_ctx, 0, "vty_vector"); tall_vty_cmd_ctx = talloc_named_const(tall_vty_ctx, 0, "vty_command"); @@ -1812,6 +1808,38 @@ install_element(VTY_NODE, &vty_bind_cmd); } +/*! Initialize VTY layer using a given talloc context. + * \param[in] app_info application information. + * \param[in] ctx talloc context to use as parent. + * + * Install VTY's own commands like `who' command. + */ +void vty_init_ctx(struct vty_app_info *app_info, void *ctx) +{ + _vty_init(app_info, ctx); +} + +/*! Initialize VTY layer using application's talloc context. + * \param[in] app_info application information. + * + * Install VTY's own commands like `who' command. + */ +void vty_init_app_ctx(struct vty_app_info *app_info) +{ + _vty_init(app_info, app_info->tall_ctx); +} + +/*! Initialize VTY layer using NULL talloc context (deprecated). + * \param[in] app_info application information. + * + * Install VTY's own commands like `who' command. + * DEPRECATED: use vty_init_ctx() or vty_init_app_ctx() instead. + */ +void vty_init(struct vty_app_info *app_info) +{ + _vty_init(app_info, NULL); +} + /*! Read the configuration file using the VTY code * \param[in] file_name file name of the configuration file * \param[in] priv private data to be passed to \ref vty_read_file diff --git a/tests/logging/logging_vty_test.c b/tests/logging/logging_vty_test.c index 806a460..b190e68 100644 --- a/tests/logging/logging_vty_test.c +++ b/tests/logging/logging_vty_test.c @@ -238,7 +238,7 @@ root_ctx = talloc_named_const(NULL, 0, "logging_vty_test"); vty_info.tall_ctx = root_ctx; - vty_init(&vty_info); + vty_init_app_ctx(&vty_info); osmo_init_logging2(root_ctx, &log_info); diff --git a/tests/tdef/tdef_vty_test_config_root.c b/tests/tdef/tdef_vty_test_config_root.c index d69e028..0d6199e 100644 --- a/tests/tdef/tdef_vty_test_config_root.c +++ b/tests/tdef/tdef_vty_test_config_root.c @@ -246,7 +246,7 @@ osmo_init_logging2(root_ctx, &log_info); vty_info.tall_ctx = root_ctx; - vty_init(&vty_info); + vty_init_app_ctx(&vty_info); osmo_talloc_vty_add_cmds(); timer_init_vty(); /* <---- the only tdef relevant init */ diff --git a/tests/tdef/tdef_vty_test_config_subnode.c b/tests/tdef/tdef_vty_test_config_subnode.c index ce851f5..f2d1199 100644 --- a/tests/tdef/tdef_vty_test_config_subnode.c +++ b/tests/tdef/tdef_vty_test_config_subnode.c @@ -242,7 +242,7 @@ osmo_init_logging2(root_ctx, &log_info); vty_info.tall_ctx = root_ctx; - vty_init(&vty_info); + vty_init_app_ctx(&vty_info); osmo_talloc_vty_add_cmds(); gsmnet_init_vty(); /* <--- relevant init for this example */ diff --git a/tests/tdef/tdef_vty_test_dynamic.c b/tests/tdef/tdef_vty_test_dynamic.c index 20dae53..f5e2fe4 100644 --- a/tests/tdef/tdef_vty_test_dynamic.c +++ b/tests/tdef/tdef_vty_test_dynamic.c @@ -316,7 +316,7 @@ osmo_init_logging2(root_ctx, &log_info); vty_info.tall_ctx = root_ctx; - vty_init(&vty_info); + vty_init_app_ctx(&vty_info); osmo_talloc_vty_add_cmds(); member_init_vty(); /* <--- relevant init for this example */ diff --git a/tests/vty/vty_test.c b/tests/vty/vty_test.c index 30efb9a..b04fec3 100644 --- a/tests/vty/vty_test.c +++ b/tests/vty/vty_test.c @@ -502,7 +502,7 @@ /* Init stats */ osmo_stats_init(stats_ctx); - vty_init(&vty_info); + vty_init_ctx(&vty_info, ctx); /* Setup VTY commands */ logging_vty_add_cmds(); diff --git a/tests/vty/vty_transcript_test.c b/tests/vty/vty_transcript_test.c index 7ffe713..8418330 100644 --- a/tests/vty/vty_transcript_test.c +++ b/tests/vty/vty_transcript_test.c @@ -192,7 +192,7 @@ root_ctx = talloc_named_const(NULL, 0, "vty_transcript_test"); vty_info.tall_ctx = root_ctx; - vty_init(&vty_info); + vty_init_app_ctx(&vty_info); osmo_talloc_vty_add_cmds(); init_vty_cmds(); -- To view, visit https://gerrit.osmocom.org/13973 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-MessageType: newchange Gerrit-Change-Id: I65d71f8fc943e103b53b784f690ed56a6e373e3f Gerrit-Change-Number: 13973 Gerrit-PatchSet: 1 Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com> -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190510/7b830910/attachment.htm>