rework app startup to search for config files in user's home directory
This commit is contained in:
parent
326f987a14
commit
36c650399b
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
*
|
||||
* \section COPYRIGHT
|
||||
*
|
||||
* Copyright 2013-2015 Software Radio Systems Limited
|
||||
*
|
||||
* \section LICENSE
|
||||
*
|
||||
* This file is part of the srsUE library.
|
||||
*
|
||||
* srsUE 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.
|
||||
*
|
||||
* srsUE 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.
|
||||
*
|
||||
* A copy of the GNU Affero General Public License can be found in
|
||||
* the LICENSE file in the top-level directory of this distribution
|
||||
* and at http://www.gnu.org/licenses/.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRSLTE_CONFIG_FILE_H
|
||||
#define SRSLTE_CONFIG_FILE_H
|
||||
|
||||
#include <fstream>
|
||||
#include <pwd.h>
|
||||
#include "common.h"
|
||||
|
||||
bool config_exists(std::string &filename, std::string default_name)
|
||||
{
|
||||
std::ifstream conf(filename.c_str(), std::ios::in);
|
||||
if(conf.fail()) {
|
||||
const char *homedir = NULL;
|
||||
char full_path[256];
|
||||
ZERO_OBJECT(full_path);
|
||||
if ((homedir = getenv("HOME")) == NULL) {
|
||||
homedir = getpwuid(getuid())->pw_dir;
|
||||
}
|
||||
if (!homedir) {
|
||||
homedir = ".";
|
||||
}
|
||||
snprintf(full_path, sizeof(full_path), "%s/.srs/%s", homedir, default_name.c_str());
|
||||
filename = std::string(full_path);
|
||||
|
||||
// try to open again
|
||||
conf.open(filename.c_str());
|
||||
if (conf.fail()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // SRSLTE_CONFIG_FILE_H
|
|
@ -30,11 +30,13 @@
|
|||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "srslte/common/config_file.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/program_options/parsers.hpp>
|
||||
#include <srsenb/hdr/enb.h>
|
||||
|
||||
#include "srsenb/hdr/enb.h"
|
||||
#include "srsenb/hdr/metrics_stdout.h"
|
||||
|
@ -224,31 +226,31 @@ void parse_args(all_args_t *args, int argc, char* argv[]) {
|
|||
}
|
||||
|
||||
// print version number and exit
|
||||
// print version number and exit
|
||||
if (vm.count("version")) {
|
||||
cout << "Version " <<
|
||||
srslte_get_version_major() << "." <<
|
||||
srslte_get_version_minor() << "." <<
|
||||
srslte_get_version_patch() << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// no config file given - print usage and exit
|
||||
if (!vm.count("config_file")) {
|
||||
cout << "Error: Configuration file not provided" << endl;
|
||||
cout << "Usage: " << argv[0] << " [OPTIONS] config_file" << endl << endl;
|
||||
exit(0);
|
||||
} else {
|
||||
cout << "Reading configuration file " << config_file << "..." << endl;
|
||||
ifstream conf(config_file.c_str(), ios::in);
|
||||
if(conf.fail()) {
|
||||
cout << "Failed to read configuration file " << config_file << " - exiting" << endl;
|
||||
exit(1);
|
||||
}
|
||||
bpo::store(bpo::parse_config_file(conf, common), vm);
|
||||
bpo::notify(vm);
|
||||
if (vm.count("version")) {
|
||||
cout << "Version " <<
|
||||
srslte_get_version_major() << "." <<
|
||||
srslte_get_version_minor() << "." <<
|
||||
srslte_get_version_patch() << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// if no config file given, check users home path
|
||||
if (!vm.count("config_file")) {
|
||||
if (!config_exists(config_file, "enb.conf")) {
|
||||
cout << "Failed to read eNB configuration file " << config_file << " - exiting" << endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Reading configuration file " << config_file << "..." << endl;
|
||||
ifstream conf(config_file.c_str(), ios::in);
|
||||
if(conf.fail()) {
|
||||
cout << "Failed to read configuration file " << config_file << " - exiting" << endl;
|
||||
exit(1);
|
||||
}
|
||||
bpo::store(bpo::parse_config_file(conf, common), vm);
|
||||
bpo::notify(vm);
|
||||
|
||||
// Convert hex strings
|
||||
{
|
||||
std::stringstream sstr;
|
||||
|
@ -329,6 +331,22 @@ void parse_args(all_args_t *args, int argc, char* argv[]) {
|
|||
args->log.s1ap_hex_limit = args->log.all_hex_limit;
|
||||
}
|
||||
}
|
||||
|
||||
// Check remaining eNB config files
|
||||
if (!config_exists(args->enb_files.sib_config, "sib.conf")) {
|
||||
cout << "Failed to read SIB configuration file " << args->enb_files.sib_config << " - exiting" << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!config_exists(args->enb_files.rr_config, "rr.conf")) {
|
||||
cout << "Failed to read RR configuration file " << args->enb_files.rr_config << " - exiting" << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!config_exists(args->enb_files.drb_config, "drb.conf")) {
|
||||
cout << "Failed to read DRB configuration file " << args->enb_files.drb_config << " - exiting" << endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static int sigcnt = 0;
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <boost/program_options.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include "srslte/common/bcd_helpers.h"
|
||||
#include "srslte/common/config_file.h"
|
||||
#include "srsepc/hdr/mme/mme.h"
|
||||
#include "srsepc/hdr/hss/hss.h"
|
||||
#include "srsepc/hdr/spgw/spgw.h"
|
||||
|
@ -154,23 +155,23 @@ parse_args(all_args_t *args, int argc, char* argv[]) {
|
|||
exit(0);
|
||||
}
|
||||
|
||||
//Parsing Config File
|
||||
// if no config file given, check users home path
|
||||
if (!vm.count("config_file")) {
|
||||
cout << "Error: Configuration file not provided" << endl;
|
||||
cout << "Usage: " << argv[0] << " [OPTIONS] config_file" << endl << endl;
|
||||
exit(0);
|
||||
} else {
|
||||
cout << "Reading configuration file " << config_file << "..." << endl;
|
||||
ifstream conf(config_file.c_str(), ios::in);
|
||||
if(conf.fail()) {
|
||||
cout << "Failed to read configuration file " << config_file << " - exiting" << endl;
|
||||
exit(1);
|
||||
}
|
||||
bpo::store(bpo::parse_config_file(conf, common), vm);
|
||||
bpo::notify(vm);
|
||||
if (!config_exists(config_file, "epc.conf")) {
|
||||
cout << "Failed to read ePC configuration file " << config_file << " - exiting" << endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Parsing Config File
|
||||
cout << "Reading configuration file " << config_file << "..." << endl;
|
||||
ifstream conf(config_file.c_str(), ios::in);
|
||||
if(conf.fail()) {
|
||||
cout << "Failed to read configuration file " << config_file << " - exiting" << endl;
|
||||
exit(1);
|
||||
}
|
||||
bpo::store(bpo::parse_config_file(conf, common), vm);
|
||||
bpo::notify(vm);
|
||||
|
||||
//Concert hex strings
|
||||
{
|
||||
|
@ -246,6 +247,13 @@ parse_args(all_args_t *args, int argc, char* argv[]) {
|
|||
args->log_args.hss_hex_limit = args->log_args.all_hex_limit;
|
||||
}
|
||||
}
|
||||
|
||||
// Check user database
|
||||
if (!config_exists(args->hss_args.db_file, "user_db.csv")) {
|
||||
cout << "Failed to read HSS user database file " << args->hss_args.db_file << " - exiting" << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <signal.h>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include "srslte/common/config_file.h"
|
||||
#include "srsepc/hdr/mbms-gw/mbms-gw.h"
|
||||
|
||||
using namespace std;
|
||||
|
@ -131,22 +132,24 @@ parse_args(all_args_t *args, int argc, char* argv[]) {
|
|||
exit(0);
|
||||
}
|
||||
|
||||
//Parsing Config File
|
||||
// if no config file given, check users home path
|
||||
if (!vm.count("config_file")) {
|
||||
cout << "Error: Configuration file not provided" << endl;
|
||||
cout << "Usage: " << argv[0] << " [OPTIONS] config_file" << endl << endl;
|
||||
exit(0);
|
||||
} else {
|
||||
cout << "Reading configuration file " << config_file << "..." << endl;
|
||||
ifstream conf(config_file.c_str(), ios::in);
|
||||
if(conf.fail()) {
|
||||
cout << "Failed to read configuration file " << config_file << " - exiting" << endl;
|
||||
exit(1);
|
||||
}
|
||||
bpo::store(bpo::parse_config_file(conf, common), vm);
|
||||
bpo::notify(vm);
|
||||
if (!config_exists(config_file, "mbms.conf")) {
|
||||
cout << "Failed to read MBMS-GW configuration file " << config_file << " - exiting" << endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
//Parsing Config File
|
||||
cout << "Reading configuration file " << config_file << "..." << endl;
|
||||
ifstream conf(config_file.c_str(), ios::in);
|
||||
if(conf.fail()) {
|
||||
cout << "Failed to read configuration file " << config_file << " - exiting" << endl;
|
||||
exit(1);
|
||||
}
|
||||
bpo::store(bpo::parse_config_file(conf, common), vm);
|
||||
bpo::notify(vm);
|
||||
|
||||
args->mbms_gw_args.name = mbms_gw_name;
|
||||
args->mbms_gw_args.sgi_mb_if_addr = mbms_gw_sgi_mb_if_addr;
|
||||
args->mbms_gw_args.m1u_multi_addr = mbms_gw_m1u_multi_addr;
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include <boost/program_options/parsers.hpp>
|
||||
|
||||
#include "srsue/hdr/ue.h"
|
||||
#include "srslte/common/config_file.h"
|
||||
#include "srslte/srslte.h"
|
||||
#include "srsue/hdr/metrics_stdout.h"
|
||||
#include "srsue/hdr/metrics_csv.h"
|
||||
|
@ -343,22 +344,24 @@ void parse_args(all_args_t *args, int argc, char *argv[]) {
|
|||
exit(0);
|
||||
}
|
||||
|
||||
// no config file given - print usage and exit
|
||||
// if no config file given, check users home path
|
||||
if (!vm.count("config_file")) {
|
||||
cout << "Error: Configuration file not provided" << endl;
|
||||
cout << "Usage: " << argv[0] << " [OPTIONS] config_file" << endl << endl;
|
||||
exit(0);
|
||||
} else {
|
||||
cout << "Reading configuration file " << config_file << "..." << endl;
|
||||
ifstream conf(config_file.c_str(), ios::in);
|
||||
if (conf.fail()) {
|
||||
cout << "Failed to read configuration file " << config_file << " - exiting" << endl;
|
||||
|
||||
if (!config_exists(config_file, "ue.conf")) {
|
||||
cout << "Failed to read UE configuration file " << config_file << " - exiting" << endl;
|
||||
exit(1);
|
||||
}
|
||||
bpo::store(bpo::parse_config_file(conf, common), vm);
|
||||
bpo::notify(vm);
|
||||
}
|
||||
|
||||
cout << "Reading configuration file " << config_file << "..." << endl;
|
||||
ifstream conf(config_file.c_str(), ios::in);
|
||||
if (conf.fail()) {
|
||||
cout << "Failed to read configuration file " << config_file << " - exiting" << endl;
|
||||
exit(1);
|
||||
}
|
||||
bpo::store(bpo::parse_config_file(conf, common), vm);
|
||||
bpo::notify(vm);
|
||||
|
||||
// Apply all_level to any unset layers
|
||||
if (vm.count("log.all_level")) {
|
||||
if (!vm.count("log.phy_level")) {
|
||||
|
|
Loading…
Reference in New Issue