summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-12-27 08:58:57 +0100
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-12-27 19:01:37 +0100
commit63c0e6d1996733d107434585fbef5e888b3075ed (patch)
tree37973849e32a30cdd224d1873944212408f3913d
parent738f9d892aa99639c9148643923505f748e72937 (diff)
layer23: Make the logfile configurable with cell_log
Be able to add extra (short) options from the 'applet' to the main application. Use this to print the help mentioning app specific options, pass the getopt string and handle the command line parsing for it. Change cell_log to keep the logname in the app_cell_log.c and then access it from the cell_log.c implementation.
-rw-r--r--src/host/layer23/include/osmocom/bb/common/l23_app.h3
-rw-r--r--src/host/layer23/src/common/main.c51
-rw-r--r--src/host/layer23/src/misc/app_cell_log.c26
-rw-r--r--src/host/layer23/src/misc/cell_log.c2
4 files changed, 69 insertions, 13 deletions
diff --git a/src/host/layer23/include/osmocom/bb/common/l23_app.h b/src/host/layer23/include/osmocom/bb/common/l23_app.h
index 46141e13..fcfd4bdf 100644
--- a/src/host/layer23/include/osmocom/bb/common/l23_app.h
+++ b/src/host/layer23/include/osmocom/bb/common/l23_app.h
@@ -21,7 +21,10 @@ struct l23_app_info {
const char *copyright;
const char *contribution;
+ char *getopt_string;
int (*cfg_supported)();
+ int (*cfg_print_help)();
+ int (*cfg_handle_opt)(int c,const char *optarg);
};
extern struct l23_app_info *l23_app_info();
diff --git a/src/host/layer23/src/common/main.c b/src/host/layer23/src/common/main.c
index 1f9afafa..a791ccf4 100644
--- a/src/host/layer23/src/common/main.c
+++ b/src/host/layer23/src/common/main.c
@@ -35,6 +35,7 @@
#include <osmocore/select.h>
#include <osmocore/linuxlist.h>
#include <osmocore/gsmtap_util.h>
+#include <osmocore/utils.h>
#include <arpa/inet.h>
@@ -101,25 +102,46 @@ static void print_help()
if (options & L23_OPT_DBG)
printf(" -d --debug Change debug flags.\n");
+
+ if (app && app->cfg_print_help)
+ app->cfg_print_help();
+}
+
+static void build_config(char **opt, struct option **option)
+{
+ struct l23_app_info *app;
+ static struct option long_options[] = {
+ {"help", 0, 0, 'h'},
+ {"socket", 1, 0, 's'},
+ {"sap", 1, 0, 'S'},
+ {"arfcn", 1, 0, 'a'},
+ {"gsmtap-ip", 1, 0, 'i'},
+ {"vty-port", 1, 0, 'v'},
+ {"debug", 1, 0, 'd'},
+ };
+
+
+ app = l23_app_info();
+ *opt = talloc_asprintf(l23_ctx, "hs:S:a:i:v:d:%s",
+ app && app->getopt_string ? app->getopt_string : "");
+ *option = talloc_zero_array(l23_ctx, struct option,
+ ARRAY_SIZE(long_options) + 1);
+ memcpy(*option, long_options, sizeof(long_options));
}
static void handle_options(int argc, char **argv)
{
struct sockaddr_in gsmtap;
+ struct l23_app_info *app = l23_app_info();
+ struct option *long_options;
+ char *opt;
+
+ build_config(&opt, &long_options);
+
while (1) {
int option_index = 0, c;
- static struct option long_options[] = {
- {"help", 0, 0, 'h'},
- {"socket", 1, 0, 's'},
- {"sap", 1, 0, 'S'},
- {"arfcn", 1, 0, 'a'},
- {"gsmtap-ip", 1, 0, 'i'},
- {"vty-port", 1, 0, 'v'},
- {"debug", 1, 0, 'd'},
- {0, 0, 0, 0},
- };
-
- c = getopt_long(argc, argv, "hs:S:a:i:v:d:",
+
+ c = getopt_long(argc, argv, opt,
long_options, &option_index);
if (c == -1)
break;
@@ -153,9 +175,14 @@ static void handle_options(int argc, char **argv)
log_parse_category_mask(stderr_target, optarg);
break;
default:
+ if (app && app->cfg_handle_opt)
+ app->cfg_handle_opt(c, optarg);
break;
}
}
+
+ talloc_free(opt);
+ talloc_free(long_options);
}
void sighandler(int sigset)
diff --git a/src/host/layer23/src/misc/app_cell_log.c b/src/host/layer23/src/misc/app_cell_log.c
index a72588f7..e80a7b25 100644
--- a/src/host/layer23/src/misc/app_cell_log.c
+++ b/src/host/layer23/src/misc/app_cell_log.c
@@ -30,7 +30,12 @@
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/misc/cell_log.h>
+#include <osmocore/talloc.h>
+
extern struct log_target *stderr_target;
+extern void *l23_ctx;
+
+char *logname = "/var/log/osmocom.log";
int _scan_work(struct osmocom_ms *ms)
{
@@ -77,9 +82,30 @@ static int l23_cfg_supported()
return L23_OPT_TAP | L23_OPT_DBG;
}
+static int l23_cfg_print_help()
+{
+ printf("\nApplication specific\n");
+ printf(" -l --logfile LOGFILE Logfile for the cell log.\n");
+ return 0;
+}
+
+static int l23_cfg_handle(int c, const char *optarg)
+{
+ switch (c) {
+ case 'l':
+ logname = talloc_strdup(l23_ctx, optarg);
+ break;
+ }
+
+ return 0;
+}
+
static struct l23_app_info info = {
.copyright = "Copyright (C) 2010 Andreas Eversberg\n",
+ .getopt_string = "l:",
.cfg_supported = l23_cfg_supported,
+ .cfg_handle_opt = l23_cfg_handle,
+ .cfg_print_help = l23_cfg_print_help,
};
struct l23_app_info *l23_app_info()
diff --git a/src/host/layer23/src/misc/cell_log.c b/src/host/layer23/src/misc/cell_log.c
index 1034ffad..ce68ef06 100644
--- a/src/host/layer23/src/misc/cell_log.c
+++ b/src/host/layer23/src/misc/cell_log.c
@@ -88,7 +88,7 @@ static double pm_gps_x, pm_gps_y, pm_gps_z;
static int arfcn;
static int rach_count;
static FILE *logfp = NULL;
-static char *logname = "/var/log/osmocom.log";
+extern char *logname;
static struct gsm48_sysinfo sysinfo;