From 924af073881b7fc94184962b2bbea6c5b9cf9c4d Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 11 Jan 2013 10:44:16 +0000 Subject: [PATCH] add shutdown points at strategic points in the code --- cdr.c | 10 ++++++++++ mediator.c | 2 +- mediator.h | 9 +++++++++ medmysql.c | 17 +++++++++++++---- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/cdr.c b/cdr.c index 8690f1f..0000b29 100644 --- a/cdr.c +++ b/cdr.c @@ -3,6 +3,7 @@ #include "medmysql.h" #include "config.h" #include "cdr.h" +#include "mediator.h" static char* cdr_map_status(const char *sip_status) { @@ -75,6 +76,9 @@ int cdr_process_records(med_entry_t *records, u_int64_t count, u_int64_t *ext_co ++msg_unknowns; e->method = MED_UNRECOGNIZED; } + + if (check_shutdown()) + return -1; } /*syslog(LOG_DEBUG, "%d INVITEs, %d BYEs, %d unrecognized", msg_invites, msg_byes, msg_unknowns);*/ @@ -422,6 +426,9 @@ int cdr_create_cdrs(med_entry_t *records, u_int64_t count, endtime = e->timestamp; unix_endtime = e->unix_timestamp; } + + if (check_shutdown()) + return -1; } if(invites == 0) @@ -496,6 +503,9 @@ int cdr_create_cdrs(med_entry_t *records, u_int64_t count, // TODO: error handling } } + + if (check_shutdown()) + return -1; } *cdr_count = cdr_index; diff --git a/mediator.c b/mediator.c index 6f99aca..a75acdb 100644 --- a/mediator.c +++ b/mediator.c @@ -17,7 +17,7 @@ #include "medmysql.h" #include "cdr.h" -static sig_atomic_t mediator_shutdown = 0; +sig_atomic_t mediator_shutdown = 0; int mediator_lockfd = -1; u_int64_t mediator_count = 0; diff --git a/mediator.h b/mediator.h index 7d47a55..9d7e3cd 100644 --- a/mediator.h +++ b/mediator.h @@ -47,6 +47,7 @@ #define MED_SEP '|' extern int mediator_lockfd; +extern sig_atomic_t mediator_shutdown; typedef enum { MED_INVITE = 1, @@ -80,5 +81,13 @@ extern GHashTable *med_uuid_table; void critical(const char *); +static inline int check_shutdown(void) { + if (mediator_shutdown) { + syslog(LOG_INFO, "Shutdown detected, aborting work in progress"); + return 1; + } + return 0; +} + #endif /* _MEDIATOR_H */ diff --git a/medmysql.c b/medmysql.c index 6f2eba7..c9b6d50 100644 --- a/medmysql.c +++ b/medmysql.c @@ -174,6 +174,9 @@ int medmysql_fetch_callids(med_callid_t **callids, u_int64_t *count) } /*syslog(LOG_DEBUG, "callid[%"PRIu64"]='%s'", i, c->value);*/ + + if (check_shutdown()) + return -1; } out: @@ -241,6 +244,9 @@ int medmysql_fetch_records(med_callid_t *callid, g_strlcpy(e->dst_leg, row[7], sizeof(e->dst_leg)); e->med_id = atoll(row[8]); e->valid = 1; + + if (check_shutdown()) + return -1; } out: @@ -420,6 +426,9 @@ int medmysql_insert_cdrs(cdr_entry_t *entries, u_int64_t count, struct medmysql_ CDRPRINT(","); CDRESCAPE(str_split); CDRPRINT("),"); + + if (check_shutdown()) + return -1; } /*syslog(LOG_DEBUG, "q='%s'", query);*/ @@ -603,13 +612,13 @@ static int medmysql_flush_medlist(struct medmysql_str *str) { } int medmysql_batch_end(struct medmysql_batches *batches) { - if (medmysql_flush_cdr(batches)) + if (medmysql_flush_cdr(batches) || check_shutdown()) return -1; - if (medmysql_flush_medlist(&batches->acc_trash)) + if (medmysql_flush_medlist(&batches->acc_trash) || check_shutdown()) return -1; - if (medmysql_flush_medlist(&batches->acc_backup)) + if (medmysql_flush_medlist(&batches->acc_backup) || check_shutdown()) return -1; - if (medmysql_flush_medlist(&batches->to_delete)) + if (medmysql_flush_medlist(&batches->to_delete) || check_shutdown()) return -1; if (mysql_query_wrapper(cdr_handler, "commit", 6))