From 92adeb0dbb6df83f745f12e46ebe01a20fe047c9 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 3 Feb 2020 11:02:18 -0500 Subject: [PATCH] TT#75351 delete DB streams that have no corresponding file Change-Id: I07bdfd6f4dfbcef82d0eb11461672f211badde78 --- recording-daemon/db.c | 16 ++++++++++++++++ recording-daemon/db.h | 1 + recording-daemon/output.c | 18 ++++++++++++------ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/recording-daemon/db.c b/recording-daemon/db.c index 6397e09f1..f2c2944fc 100644 --- a/recording-daemon/db.c +++ b/recording-daemon/db.c @@ -58,6 +58,7 @@ static MYSQL_STMT __thread *stm_close_call, *stm_insert_stream, *stm_close_stream, + *stm_delete_stream, *stm_config_stream, *stm_insert_metadata; @@ -75,6 +76,7 @@ static void reset_conn(void) { my_stmt_close(&stm_close_call); my_stmt_close(&stm_insert_stream); my_stmt_close(&stm_close_stream); + my_stmt_close(&stm_delete_stream); my_stmt_close(&stm_config_stream); my_stmt_close(&stm_insert_metadata); mysql_close(mysql_conn); @@ -139,6 +141,8 @@ static int check_conn(void) { "end_timestamp = ? where id = ?")) goto err; } + if (prep(&stm_delete_stream, "delete from recording_streams where id = ?")) + goto err; if (prep(&stm_config_stream, "update recording_streams set channels = ?, sample_rate = ? where id = ?")) goto err; if (prep(&stm_insert_metadata, "insert into recording_metakeys (`call`, `key`, `value`) values " \ @@ -425,6 +429,18 @@ file:; free(filename); } +void db_delete_stream(output_t *op) { + if (check_conn()) + return; + if (op->db_id == 0) + return; + + MYSQL_BIND b[1]; + my_ull(&b[0], &op->db_id); + + execute_wrap(&stm_delete_stream, b, NULL); +} + void db_config_stream(output_t *op) { if (check_conn()) return; diff --git a/recording-daemon/db.h b/recording-daemon/db.h index 3fb1eee8d..82a4a1735 100644 --- a/recording-daemon/db.h +++ b/recording-daemon/db.h @@ -8,6 +8,7 @@ void db_do_call(metafile_t *); void db_close_call(metafile_t *); void db_do_stream(metafile_t *mf, output_t *op, const char *type, stream_t *, unsigned long ssrc); void db_close_stream(output_t *op); +void db_delete_stream(output_t *op); void db_config_stream(output_t *op); diff --git a/recording-daemon/output.c b/recording-daemon/output.c index d2640b855..530f60d11 100644 --- a/recording-daemon/output.c +++ b/recording-daemon/output.c @@ -16,7 +16,7 @@ int mp3_bitrate; -static void output_shutdown(output_t *output); +static int output_shutdown(output_t *output); @@ -133,15 +133,17 @@ err: } -static void output_shutdown(output_t *output) { +static int output_shutdown(output_t *output) { if (!output) - return; + return 0; if (!output->fmtctx) - return; + return 0; + int ret = 0; if (output->fmtctx->pb) { av_write_trailer(output->fmtctx); avio_closep(&output->fmtctx->pb); + ret = 1; } avformat_free_context(output->fmtctx); @@ -154,14 +156,18 @@ static void output_shutdown(output_t *output) { output->fmtctx = NULL; output->avst = NULL; + + return ret; } void output_close(output_t *output) { if (!output) return; - output_shutdown(output); - db_close_stream(output); + if (output_shutdown(output)) + db_close_stream(output); + else + db_delete_stream(output); encoder_free(output->encoder); g_slice_free1(sizeof(*output), output); }