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/.
Max gerrit-no-reply at lists.osmocom.orgReview at https://gerrit.osmocom.org/1899 Get rid of global config options struct Make it obvious that the command-line options are only used within main() by removing global static struct and explicitly passing passing it to handle_options() instead. Change-Id: I83f0a352327e6ea659b789c37deacf2f86eb3dde --- M src/Makefile.am M src/hlr.c A src/hlr.h 3 files changed, 48 insertions(+), 19 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-hlr refs/changes/99/1899/1 diff --git a/src/Makefile.am b/src/Makefile.am index 56a5670..6e7fcdc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,6 +13,7 @@ noinst_HEADERS = \ auc.h \ + hlr.h \ db.h \ luop.h \ gsup_router.h \ diff --git a/src/hlr.c b/src/hlr.c index d74d9fb..5c59b88 100644 --- a/src/hlr.c +++ b/src/hlr.c @@ -33,6 +33,7 @@ #include <osmocom/vty/telnet_interface.h> #include <osmocom/vty/ports.h> +#include "hlr.h" #include "db.h" #include "logging.h" #include "gsup_server.h" @@ -300,17 +301,7 @@ printf(" -V --version Print the version of OsmoHLR.\n"); } -static struct { - const char *config_file; - const char *db_file; - bool daemonize; -} cmdline_opts = { - .config_file = "osmo-hlr.cfg", - .db_file = "hlr.db", - .daemonize = false, -}; - -static void handle_options(int argc, char **argv) +static void handle_options(struct cmdline_opts *cfg, int argc, char **argv) { while (1) { int option_index = 0, c; @@ -338,16 +329,16 @@ print_help(); exit(0); case 'c': - cmdline_opts.config_file = optarg; + cfg->config_file = optarg; break; case 'l': - cmdline_opts.db_file = optarg; + cfg->db_file = optarg; break; case 'd': log_parse_category_mask(osmo_stderr_target, optarg); break; case 'D': - cmdline_opts.daemonize = 1; + cfg->daemonize = true; break; case 's': log_set_use_color(osmo_stderr_target, 0); @@ -401,9 +392,15 @@ int main(int argc, char **argv) { int rc; + struct cmdline_opts *c_opts; hlr_ctx = talloc_named_const(NULL, 1, "OsmoHLR"); msgb_talloc_ctx_init(hlr_ctx, 0); + + c_opts = talloc_zero(hlr_ctx, struct cmdline_opts); + + c_opts->config_file = "osmo-hlr.cfg"; + c_opts->db_file = "hlr.db"; rc = osmo_init_logging(&hlr_log_info); if (rc < 0) { @@ -412,14 +409,14 @@ } vty_init(&vty_info); - handle_options(argc, argv); + handle_options(c_opts, argc, argv); hlr_vty_init(&hlr_log_info); - rc = vty_read_config_file(cmdline_opts.config_file, NULL); + rc = vty_read_config_file(c_opts->config_file, NULL); if (rc < 0) { LOGP(DMAIN, LOGL_FATAL, "Failed to parse the config file: '%s'\n", - cmdline_opts.config_file); + c_opts->config_file); return rc; } @@ -437,7 +434,7 @@ exit(1); } - g_dbc = db_open(hlr_ctx, cmdline_opts.db_file); + g_dbc = db_open(hlr_ctx, c_opts->db_file); if (!g_dbc) { LOGP(DMAIN, LOGL_FATAL, "Error opening database\n"); exit(1); @@ -453,7 +450,7 @@ signal(SIGINT, &signal_hdlr); signal(SIGUSR1, &signal_hdlr); - if (cmdline_opts.daemonize) { + if (c_opts->daemonize) { rc = osmo_daemonize(); if (rc < 0) { perror("Error during daemonize"); diff --git a/src/hlr.h b/src/hlr.h new file mode 100644 index 0000000..4e296ff --- /dev/null +++ b/src/hlr.h @@ -0,0 +1,31 @@ +/* OsmoHLR generic header */ + +/* (C) 2017 sysmocom s.f.m.c. GmbH <info at sysmocom.de> + * All Rights Reserved + * + * Author: Max Suraev <msuraev at sysmocom.de> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#pragma once + +#include <stdbool.h> + +struct cmdline_opts { + const char *config_file; + const char *db_file; + bool daemonize; +}; -- To view, visit https://gerrit.osmocom.org/1899 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I83f0a352327e6ea659b789c37deacf2f86eb3dde Gerrit-PatchSet: 1 Gerrit-Project: osmo-hlr Gerrit-Branch: master Gerrit-Owner: Max <msuraev at sysmocom.de>