From 8f6d7c0a1609e9d94564fa521605c07e1acceefe Mon Sep 17 00:00:00 2001 From: Dylan Mikus Date: Thu, 10 Dec 2015 20:59:29 +0000 Subject: [PATCH] Logging cleanup and added recording filesystem logging messages. We log errors when filesystem operations fail, among other things. --- daemon/call.c | 16 ++++------------ daemon/fs.c | 40 ++++++++++++++++++++++++++++++++++++---- daemon/fs.h | 7 ++++++- daemon/media_socket.c | 15 --------------- 4 files changed, 46 insertions(+), 32 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index d39f6198c..3dbd240a3 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -17,7 +17,6 @@ #include #include #include -#include #include "poller.h" #include "aux.h" @@ -700,8 +699,6 @@ static struct endpoint_map *__get_endpoint_map(struct call_media *media, unsigne socket_t *sock; struct intf_list *il, *em_il; - ilog(LOG_INFO, "XXDylan: __get_endpoint_map"); - for (l = media->endpoint_maps.tail; l; l = l->prev) { em = l->data; if (em->logical_intf != media->logical_intf) @@ -1527,7 +1524,9 @@ int monologue_offer_answer(struct call_monologue *other_ml, GQueue *streams, ml_media = other_ml_media = NULL; str *pcap_path = recording_setup_file(call, monologue); - if (pcap_path != NULL && call->meta_fp != NULL) { + if (pcap_path != NULL != NULL && monologue->recording_pdumper != NULL + && call->meta_fp) { + // Write the location of the PCAP file to the metadata file fprintf(call->meta_fp, "%s\n", pcap_path->s); } @@ -2492,14 +2491,7 @@ static void __monologue_destroy(struct call_monologue *monologue) { GList *l; call = monologue->call; - ilog(LOG_INFO, "XXXDylan: closing pcap stuff"); - if (monologue->recording_pdumper != NULL) { - pcap_dump_flush(monologue->recording_pdumper); - pcap_dump_close(monologue->recording_pdumper); - } - if (monologue->recording_pd != NULL) { - pcap_close(monologue->recording_pd); - } + recording_finish_file(monologue); g_hash_table_remove(call->tags, &monologue->tag); diff --git a/daemon/fs.c b/daemon/fs.c index 359b4c342..c76972a93 100644 --- a/daemon/fs.c +++ b/daemon/fs.c @@ -7,6 +7,7 @@ #include #include #include "call.h" +#include @@ -116,6 +117,7 @@ str *meta_setup_file(struct call *call) { call->meta_filepath = NULL; } call->meta_fp = mfp; + ilog(LOG_INFO, "Wrote metadata file to temporary path: %s", meta_filepath->s); return meta_filepath; } } @@ -127,7 +129,6 @@ str *meta_setup_file(struct call *call) { int meta_finish_file(struct call *call) { int return_code = 0; - if (call->meta_fp != NULL) { // Print start timestamp and end timestamp // YYYY-MM-DDThh:mm:ss @@ -157,10 +158,12 @@ int meta_finish_file(struct call *call) { int fn_len; char *meta_filename = strrchr(call->meta_filepath->s, '/'); char *meta_ext = NULL; - if (meta_filename == NULL) + if (meta_filename == NULL) { meta_filename = call->meta_filepath->s; - else + } + else { meta_filename = meta_filename + 1; + } // We can always expect a file extension meta_ext = strrchr(meta_filename, '.'); fn_len = meta_ext - meta_filename; @@ -169,7 +172,14 @@ int meta_finish_file(struct call *call) { char new_metapath[prefix_len + fn_len + ext_len + 1]; snprintf(new_metapath, prefix_len+fn_len+1, "%s/metadata/%s", spooldir, meta_filename); snprintf(new_metapath + prefix_len+fn_len, ext_len+1, ".txt"); - return_code = return_code | rename(call->meta_filepath->s, new_metapath); + return_code = return_code || rename(call->meta_filepath->s, new_metapath); + if (return_code != 0) { + ilog(LOG_ERROR, "Could not move metadata file \"%s\" to \"%s/metadata/\"", + call->meta_filepath->s, spooldir); + } else { + ilog(LOG_INFO, "Moved metadata file \"%s\" to \"%s/metadata\"", + call->meta_filepath->s, spooldir); + } } if (call->meta_filepath != NULL) { free(call->meta_filepath->s); @@ -200,6 +210,13 @@ str *recording_setup_file(struct call *call, struct call_monologue *monologue) { call->recording_pcaps = g_slist_prepend(call->recording_pcaps, g_strdup(path_chars)); monologue->recording_pd = pcap_open_dead(DLT_RAW, 65535); monologue->recording_pdumper = pcap_dump_open(monologue->recording_pd, path_chars); + if (monologue->recording_pdumper == NULL) { + pcap_close(monologue->recording_pd); + monologue->recording_pd = NULL; + ilog(LOG_INFO, "Failed to write recording file: %s", recording_path->s); + } else { + ilog(LOG_INFO, "Writing recording file: %s", recording_path->s); + } } else { monologue->recording_path = NULL; monologue->recording_pd = NULL; @@ -209,6 +226,21 @@ str *recording_setup_file(struct call *call, struct call_monologue *monologue) { return recording_path; } +/** + * Flushes PCAP file, closes the dumper and descriptors, and frees object memory. + */ +void recording_finish_file(struct call_monologue *monologue) { + if (monologue->recording_pdumper != NULL) { + pcap_dump_flush(monologue->recording_pdumper); + pcap_dump_close(monologue->recording_pdumper); + free(monologue->recording_path->s); + free(monologue->recording_path); + } + if (monologue->recording_pd != NULL) { + pcap_close(monologue->recording_pd); + } +} + /** * Write out a PCAP packet with payload string. * A fair amount extraneous of packet data is spoofed. diff --git a/daemon/fs.h b/daemon/fs.h index 07f2b154d..a2a93659c 100644 --- a/daemon/fs.h +++ b/daemon/fs.h @@ -27,7 +27,7 @@ void fs_init(char *spooldir); * start timestamp (YYYY-MM-DDThh:mm:ss) * end timestamp (YYYY-MM-DDThh:mm:ss) * - * metadata + * generic metadata * */ str *meta_setup_file(struct call *call); @@ -44,6 +44,11 @@ int meta_finish_file(struct call *call); */ str *recording_setup_file(struct call *call, struct call_monologue *monologue); +/** + * Flushes PCAP file, closes the dumper and descriptors, and frees object memory. + */ +void recording_finish_file(struct call_monologue *monologue); + /** * Write out a PCAP packet with payload string. * A fair amount extraneous of packet data is spoofed. diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 03bd6546d..ff958c41e 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -1306,7 +1306,6 @@ kernel_check: kernelize(stream); forward: - // ilog(LOG_INFO, "XXEGREENSTREAM: %s", s->s); if (sink) mutex_lock(&sink->out_lock); @@ -1377,20 +1376,6 @@ static void stream_fd_readable(int fd, void *p, uintptr_t u) { log_info_stream_fd(sfd); - /* - * I should be able to create a filedescriptor here for each stream and pass it - * to stream_packet. Each file descriptor should then receive one side of the - * rtp for each call. I fully expect some packets to get dropped using this - * naive method. If we are seeing problems in testing we could use a RAM disk. - */ - - // var egreentmp1[15] = "/tmp" + rand(); - // ilog(LOG_INFO, "XXEGREEN: Creting new file descriptor for recording %s", egreentmp1); - // int egreenFD = open(egreentmp1, O_WRONLY | O_CREAT | O_TRUNC); - // char egreentmp[15]; - // sprintf(egreentmp, "%d", egreenFD); - // ilog(LOG_INFO, "XXEGREEN: FD created: %s", egreentmp); - for (iters = 0; ; iters++) { #if MAX_RECV_ITERS if (iters >= MAX_RECV_ITERS) {