Vadim Yanitskiy | ac3a3fc | 2021-11-09 03:35:44 +0300 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2021 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> |
| 3 | * |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * SPDX-License-Identifier: GPL-2.0+ |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | |
| 22 | #include <stdio.h> |
| 23 | #include <signal.h> |
| 24 | |
| 25 | #include <osmocom/core/application.h> |
| 26 | #include <osmocom/core/logging.h> |
| 27 | #include <osmocom/core/select.h> |
| 28 | #include <osmocom/core/utils.h> |
| 29 | |
| 30 | #include <osmocom/vty/telnet_interface.h> |
| 31 | #include <osmocom/vty/stats.h> |
| 32 | #include <osmocom/vty/vty.h> |
| 33 | |
| 34 | static void *root_ctx = NULL; |
| 35 | static int quit = 0; |
| 36 | |
| 37 | static void signal_handler(int signal) |
| 38 | { |
| 39 | fprintf(stdout, "signal %u received\n", signal); |
| 40 | |
| 41 | switch (signal) { |
| 42 | case SIGINT: |
| 43 | case SIGTERM: |
| 44 | quit++; |
| 45 | break; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | static struct vty_app_info vty_info = { |
| 50 | .name = "stats_vty_test", |
| 51 | }; |
| 52 | |
| 53 | static const struct log_info_cat default_categories[] = { }; |
| 54 | |
| 55 | const struct log_info log_info = { |
| 56 | .cat = default_categories, |
| 57 | .num_cat = ARRAY_SIZE(default_categories), |
| 58 | }; |
| 59 | |
| 60 | int main(int argc, char **argv) |
| 61 | { |
| 62 | int rc; |
| 63 | |
| 64 | root_ctx = talloc_named_const(NULL, 0, "stats_vty_test"); |
| 65 | |
| 66 | osmo_init_logging2(root_ctx, &log_info); |
| 67 | |
| 68 | vty_info.tall_ctx = root_ctx; |
| 69 | vty_init(&vty_info); |
| 70 | |
| 71 | osmo_stats_vty_add_cmds(); |
| 72 | |
arehbein | 0aa84cf | 2023-01-27 00:49:45 +0100 | [diff] [blame] | 73 | rc = telnet_init_default(root_ctx, NULL, 42042); |
Vadim Yanitskiy | ac3a3fc | 2021-11-09 03:35:44 +0300 | [diff] [blame] | 74 | if (rc < 0) |
| 75 | return 2; |
| 76 | |
| 77 | signal(SIGINT, &signal_handler); |
| 78 | signal(SIGTERM, &signal_handler); |
| 79 | osmo_init_ignore_signals(); |
| 80 | |
| 81 | while (!quit) |
| 82 | osmo_select_main(0); |
| 83 | |
| 84 | talloc_free(tall_vty_ctx); |
| 85 | talloc_free(root_ctx); |
| 86 | |
| 87 | return 0; |
| 88 | } |