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 + #include #include #include @@ -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);