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/.
osmith gerrit-no-reply at lists.osmocom.orgosmith has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-bsc-nat/+/26660 ) Change subject: Add command-line options ...................................................................... Add command-line options Related: OS#2545 Change-Id: I41bca9e1b88bb130870d078ed3f499e39e0bf5d3 --- M src/osmo-bsc-nat/main.c 1 file changed, 65 insertions(+), 2 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-bsc-nat refs/changes/60/26660/1 diff --git a/src/osmo-bsc-nat/main.c b/src/osmo-bsc-nat/main.c index 813909b..1edc134 100644 --- a/src/osmo-bsc-nat/main.c +++ b/src/osmo-bsc-nat/main.c @@ -19,6 +19,8 @@ #include "config.h" +#include <getopt.h> + #include <osmocom/core/application.h> #include <osmocom/vty/cpu_sched_vty.h> #include <osmocom/vty/logging.h> @@ -47,7 +49,59 @@ .go_parent_cb = bsc_nat_vty_go_parent, }; -static void main_vty_init() +static struct { + const char *config_file; +} bsc_nat_cmdline_config = { + .config_file = "osmo-bsc-nat.cfg", +}; + +static void print_help() +{ + printf("usage: osmo-bsc-nat <options>\n"); + printf("\n"); + printf("optional arguments:\n"); + printf(" -h, --help show this help message and exit\n"); + printf(" -c, --config-file the config file to use\n"); + printf(" -V, --version show version number and exit\n"); +} + +static void handle_options(int argc, char **argv) +{ + while (1) { + int idx = 0, c; + static const struct option long_options[] = { + {"help", 0, 0, 'h'}, + {"config-file", 1, 0, 'c'}, + {"version", 0, 0, 'V' }, + { 0, 0, 0, 0 }, + }; + + c = getopt_long(argc, argv, "hc:V", long_options, &idx); + + if (c == -1) + break; + + switch (c) { + case 'h': + print_help(); + exit(0); + break; + case 'c': + bsc_nat_cmdline_config.config_file = optarg; + break; + case 'V': + print_version(1); + exit(0); + break; + default: + fprintf(stderr, "Error in command line options. Exiting.\n"); + exit(-1); + break; + } + } +} + +static void main_vty_init(int argc, char **argv) { int rc; @@ -61,6 +115,15 @@ osmo_talloc_vty_add_cmds(); osmo_cpu_sched_vty_init(tall_bsc_nat_ctx); + handle_options(argc, argv); + + rc = vty_read_config_file(bsc_nat_cmdline_config.config_file, NULL); + if (rc < 0) { + fprintf(stderr, "Failed to parse the config file: '%s'\n", + bsc_nat_cmdline_config.config_file); + exit(1); + } + rc = telnet_init_dynif(tall_bsc_nat_ctx, g_bsc_nat, vty_get_bind_addr(), OSMO_VTY_PORT_BSC_NAT); if (rc < 0) { perror("Error binding VTY port"); @@ -81,7 +144,7 @@ g_bsc_nat = bsc_nat_alloc(tall_bsc_nat_ctx); - main_vty_init(); + main_vty_init(argc, argv); while (!osmo_select_shutdown_done()) osmo_select_main_ctx(0); -- To view, visit https://gerrit.osmocom.org/c/osmo-bsc-nat/+/26660 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-bsc-nat Gerrit-Branch: master Gerrit-Change-Id: I41bca9e1b88bb130870d078ed3f499e39e0bf5d3 Gerrit-Change-Number: 26660 Gerrit-PatchSet: 1 Gerrit-Owner: osmith <osmith at sysmocom.de> Gerrit-MessageType: newchange -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20211221/692bda7f/attachment.htm>