e1_recorder: Add signal handlers for log file rotation + talloc report

This commit is contained in:
Harald Welte 2016-10-19 10:47:17 +02:00
parent 13351138e2
commit df7a306df5
3 changed files with 28 additions and 2 deletions

View File

@ -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);

View File

@ -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",

View File

@ -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);