aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2016-10-19 10:47:17 +0200
committerHarald Welte <laforge@gnumonks.org>2016-10-19 10:55:25 +0200
commitdf7a306df5a1cb41ad42c303001f24a06f28458e (patch)
treec8c0100f1863fb5e93c5920f7603e841202d0aec
parent13351138e2081c5d02de11eef1050b17ffa199a1 (diff)
e1_recorder: Add signal handlers for log file rotation + talloc report
-rw-r--r--src/e1_recorder.c17
-rw-r--r--src/storage.c12
-rw-r--r--src/storage.h1
3 files changed, 28 insertions, 2 deletions
diff --git a/src/e1_recorder.c b/src/e1_recorder.c
index 703a67e..b0ae044 100644
--- a/src/e1_recorder.c
+++ b/src/e1_recorder.c
@@ -1,3 +1,5 @@
+#include <signal.h>
+
#include <osmocom/core/signal.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/application.h>
@@ -82,6 +84,18 @@ struct vty_app_info vty_info = {
static void *rec_tall_ctx;
struct e1_recorder g_recorder;
+static void signal_handler(int signo)
+{
+ switch (signo) {
+ case SIGHUP:
+ storage_close();
+ break;
+ case SIGUSR1:
+ talloc_report(rec_tall_ctx, stderr);
+ break;
+ }
+}
+
int main(int argc, char **argv)
{
int rc;
@@ -96,6 +110,9 @@ int main(int argc, char **argv)
e1inp_vty_init();
recorder_vty_init();
+ signal(SIGHUP, &signal_handler);
+ signal(SIGUSR1, &signal_handler);
+
rc = vty_read_config_file("osmo-e1-recorder.cfg", NULL);
if (rc < 0)
exit(1);
diff --git a/src/storage.c b/src/storage.c
index d222b3a..d18f8cd 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -27,16 +27,24 @@ static const char *storage_gen_filename(void)
return buf;
}
+void storage_close(void)
+{
+ LOGP(DMAIN, LOGL_INFO, "Closing Log file\n");
+ close(g_out_fd);
+ g_out_fd = -1;
+}
+
static int storage_reopen_if_needed(void)
{
if (g_written_bytes / (1024*1024) >= g_recorder.max_file_size_mb) {
- close(g_out_fd);
- g_out_fd = -1;
+ storage_close();
+ /* we re-open below */
}
if (g_out_fd < 0) {
int rc;
const char *fname = storage_gen_filename();
+ LOGP(DMAIN, LOGL_INFO, "Opening Log file %s\n", fname);
rc = chdir(g_recorder.storage_path);
if (rc < 0) {
LOGP(DMAIN, LOGL_ERROR, "Unable to chdir(%s): %s\n",
diff --git a/src/storage.h b/src/storage.h
index d256fdc..c7c1890 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -30,6 +30,7 @@ struct msgb;
struct e1inp_ts;
int e1frame_store(struct e1inp_ts *ts, struct msgb *msg, enum osmo_e1cap_capture_mode mode);
+void storage_close(void);
struct osmo_e1cap_file;
struct osmo_e1cap_file *osmo_e1cap_open(void *ctx, const char *path);