<p>Vadim Yanitskiy has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/13973">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">libosmovty: deprecate vty_init(), add vty_init[_app]_ctx()<br><br>The main problem of vty_init() is that it's using NULL talloc<br>context. We could modify it and start using the context from<br>a given 'vty_app_info' structure, but this might cause the<br>compatibility problems with the existing API users.<br><br>Instead, let's deprecate vty_init() and introduce two new wrappers:<br><br>  - vty_init_ctx() - use a given talloc context,<br>  - vty_init_app_ctx() - use the application's talloc context.<br><br>Change-Id: I65d71f8fc943e103b53b784f690ed56a6e373e3f<br>---<br>M include/osmocom/vty/vty.h<br>M src/vty/vty.c<br>M tests/logging/logging_vty_test.c<br>M tests/tdef/tdef_vty_test_config_root.c<br>M tests/tdef/tdef_vty_test_config_subnode.c<br>M tests/tdef/tdef_vty_test_dynamic.c<br>M tests/vty/vty_test.c<br>M tests/vty/vty_transcript_test.c<br>8 files changed, 45 insertions(+), 13 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/73/13973/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmocom/vty/vty.h b/include/osmocom/vty/vty.h</span><br><span>index 03a2924..7461702 100644</span><br><span>--- a/include/osmocom/vty/vty.h</span><br><span>+++ b/include/osmocom/vty/vty.h</span><br><span>@@ -5,6 +5,7 @@</span><br><span> #include <stdbool.h></span><br><span> </span><br><span> #include <osmocom/core/linuxlist.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/defs.h></span><br><span> </span><br><span> /*! \defgroup vty VTY (Virtual TTY) interface</span><br><span>  *  @{</span><br><span>@@ -187,7 +188,10 @@</span><br><span> };</span><br><span> </span><br><span> /* Prototypes. */</span><br><span style="color: hsl(0, 100%, 40%);">-void vty_init(struct vty_app_info *app_info);</span><br><span style="color: hsl(120, 100%, 40%);">+void vty_init_ctx(struct vty_app_info *app_info, void *ctx);</span><br><span style="color: hsl(120, 100%, 40%);">+void vty_init_app_ctx(struct vty_app_info *app_info);</span><br><span style="color: hsl(120, 100%, 40%);">+void vty_init(struct vty_app_info *app_info)</span><br><span style="color: hsl(120, 100%, 40%);">+    OSMO_DEPRECATED("use vty_init_ctx() or vty_init_app_ctx() instead");</span><br><span> int vty_read_config_file(const char *file_name, void *priv);</span><br><span> void vty_init_vtysh (void);</span><br><span> void vty_reset (void);</span><br><span>diff --git a/src/vty/vty.c b/src/vty/vty.c</span><br><span>index 98b332d..2b339bb 100644</span><br><span>--- a/src/vty/vty.c</span><br><span>+++ b/src/vty/vty.c</span><br><span>@@ -1776,13 +1776,9 @@</span><br><span>    vtyvec = vector_init(VECTOR_MIN_SIZE);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/*! Initialize VTY layer</span><br><span style="color: hsl(0, 100%, 40%);">- *  \param[in] app_info application information</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-/* Install vty's own commands like `who' command. */</span><br><span style="color: hsl(0, 100%, 40%);">-void vty_init(struct vty_app_info *app_info)</span><br><span style="color: hsl(120, 100%, 40%);">+static inline void _vty_init(struct vty_app_info *app_info, void *ctx)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-  tall_vty_ctx = talloc_named_const(NULL, 0, "vty");</span><br><span style="color: hsl(120, 100%, 40%);">+  tall_vty_ctx = talloc_named_const(ctx, 0, "vty");</span><br><span>  tall_vty_vec_ctx = talloc_named_const(tall_vty_ctx, 0, "vty_vector");</span><br><span>      tall_vty_cmd_ctx = talloc_named_const(tall_vty_ctx, 0, "vty_command");</span><br><span> </span><br><span>@@ -1812,6 +1808,38 @@</span><br><span>        install_element(VTY_NODE, &vty_bind_cmd);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! Initialize VTY layer using a given talloc context.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] app_info application information.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] ctx talloc context to use as parent.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Install VTY's own commands like `who' command.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+void vty_init_ctx(struct vty_app_info *app_info, void *ctx)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     _vty_init(app_info, ctx);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! Initialize VTY layer using application's talloc context.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] app_info application information.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Install VTY's own commands like `who' command.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+void vty_init_app_ctx(struct vty_app_info *app_info)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       _vty_init(app_info, app_info->tall_ctx);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! Initialize VTY layer using NULL talloc context (deprecated).</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] app_info application information.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Install VTY's own commands like `who' command.</span><br><span style="color: hsl(120, 100%, 40%);">+ * DEPRECATED: use vty_init_ctx() or vty_init_app_ctx() instead.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+void vty_init(struct vty_app_info *app_info)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+   _vty_init(app_info, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! Read the configuration file using the VTY code</span><br><span>  *  \param[in] file_name file name of the configuration file</span><br><span>  *  \param[in] priv private data to be passed to \ref vty_read_file</span><br><span>diff --git a/tests/logging/logging_vty_test.c b/tests/logging/logging_vty_test.c</span><br><span>index 806a460..b190e68 100644</span><br><span>--- a/tests/logging/logging_vty_test.c</span><br><span>+++ b/tests/logging/logging_vty_test.c</span><br><span>@@ -238,7 +238,7 @@</span><br><span>      root_ctx = talloc_named_const(NULL, 0, "logging_vty_test");</span><br><span> </span><br><span>    vty_info.tall_ctx = root_ctx;</span><br><span style="color: hsl(0, 100%, 40%);">-   vty_init(&vty_info);</span><br><span style="color: hsl(120, 100%, 40%);">+      vty_init_app_ctx(&vty_info);</span><br><span> </span><br><span>         osmo_init_logging2(root_ctx, &log_info);</span><br><span> </span><br><span>diff --git a/tests/tdef/tdef_vty_test_config_root.c b/tests/tdef/tdef_vty_test_config_root.c</span><br><span>index d69e028..0d6199e 100644</span><br><span>--- a/tests/tdef/tdef_vty_test_config_root.c</span><br><span>+++ b/tests/tdef/tdef_vty_test_config_root.c</span><br><span>@@ -246,7 +246,7 @@</span><br><span>  osmo_init_logging2(root_ctx, &log_info);</span><br><span> </span><br><span>     vty_info.tall_ctx = root_ctx;</span><br><span style="color: hsl(0, 100%, 40%);">-   vty_init(&vty_info);</span><br><span style="color: hsl(120, 100%, 40%);">+      vty_init_app_ctx(&vty_info);</span><br><span>     osmo_talloc_vty_add_cmds();</span><br><span> </span><br><span>      timer_init_vty(); /* <---- the only tdef relevant init */</span><br><span>diff --git a/tests/tdef/tdef_vty_test_config_subnode.c b/tests/tdef/tdef_vty_test_config_subnode.c</span><br><span>index ce851f5..f2d1199 100644</span><br><span>--- a/tests/tdef/tdef_vty_test_config_subnode.c</span><br><span>+++ b/tests/tdef/tdef_vty_test_config_subnode.c</span><br><span>@@ -242,7 +242,7 @@</span><br><span>  osmo_init_logging2(root_ctx, &log_info);</span><br><span> </span><br><span>     vty_info.tall_ctx = root_ctx;</span><br><span style="color: hsl(0, 100%, 40%);">-   vty_init(&vty_info);</span><br><span style="color: hsl(120, 100%, 40%);">+      vty_init_app_ctx(&vty_info);</span><br><span>     osmo_talloc_vty_add_cmds();</span><br><span> </span><br><span>      gsmnet_init_vty(); /* <--- relevant init for this example */</span><br><span>diff --git a/tests/tdef/tdef_vty_test_dynamic.c b/tests/tdef/tdef_vty_test_dynamic.c</span><br><span>index 20dae53..f5e2fe4 100644</span><br><span>--- a/tests/tdef/tdef_vty_test_dynamic.c</span><br><span>+++ b/tests/tdef/tdef_vty_test_dynamic.c</span><br><span>@@ -316,7 +316,7 @@</span><br><span>   osmo_init_logging2(root_ctx, &log_info);</span><br><span> </span><br><span>     vty_info.tall_ctx = root_ctx;</span><br><span style="color: hsl(0, 100%, 40%);">-   vty_init(&vty_info);</span><br><span style="color: hsl(120, 100%, 40%);">+      vty_init_app_ctx(&vty_info);</span><br><span>     osmo_talloc_vty_add_cmds();</span><br><span> </span><br><span>      member_init_vty(); /* <--- relevant init for this example */</span><br><span>diff --git a/tests/vty/vty_test.c b/tests/vty/vty_test.c</span><br><span>index 30efb9a..b04fec3 100644</span><br><span>--- a/tests/vty/vty_test.c</span><br><span>+++ b/tests/vty/vty_test.c</span><br><span>@@ -502,7 +502,7 @@</span><br><span>   /* Init stats */</span><br><span>     osmo_stats_init(stats_ctx);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- vty_init(&vty_info);</span><br><span style="color: hsl(120, 100%, 40%);">+      vty_init_ctx(&vty_info, ctx);</span><br><span> </span><br><span>        /* Setup VTY commands */</span><br><span>     logging_vty_add_cmds();</span><br><span>diff --git a/tests/vty/vty_transcript_test.c b/tests/vty/vty_transcript_test.c</span><br><span>index 7ffe713..8418330 100644</span><br><span>--- a/tests/vty/vty_transcript_test.c</span><br><span>+++ b/tests/vty/vty_transcript_test.c</span><br><span>@@ -192,7 +192,7 @@</span><br><span>       root_ctx = talloc_named_const(NULL, 0, "vty_transcript_test");</span><br><span> </span><br><span>         vty_info.tall_ctx = root_ctx;</span><br><span style="color: hsl(0, 100%, 40%);">-   vty_init(&vty_info);</span><br><span style="color: hsl(120, 100%, 40%);">+      vty_init_app_ctx(&vty_info);</span><br><span>     osmo_talloc_vty_add_cmds();</span><br><span>  init_vty_cmds();</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/13973">change 13973</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/13973"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I65d71f8fc943e103b53b784f690ed56a6e373e3f </div>
<div style="display:none"> Gerrit-Change-Number: 13973 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Vadim Yanitskiy <axilirator@gmail.com> </div>