Skip to content

Instantly share code, notes, and snippets.

@roramirez
Created March 1, 2016 21:20
Show Gist options
  • Save roramirez/8b99e4d7e3b82503e33f to your computer and use it in GitHub Desktop.
Save roramirez/8b99e4d7e3b82503e33f to your computer and use it in GitHub Desktop.
diff --git a/cdr/cdr_adaptive_odbc.c b/cdr/cdr_adaptive_odbc.c
index 0da8c01..2b9f339 100644
--- a/cdr/cdr_adaptive_odbc.c
+++ b/cdr/cdr_adaptive_odbc.c
@@ -90,6 +90,8 @@ struct tables {
static AST_RWLIST_HEAD_STATIC(odbc_tables, tables);
+static int connected = 0;
+
static int load_config(void)
{
struct ast_config *cfg;
@@ -298,6 +300,7 @@ static int load_config(void)
/* Insert column info into column list */
AST_LIST_INSERT_TAIL(&(tableptr->columns), entry, list);
res = 0;
+ connected = 1;
}
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
@@ -325,6 +328,20 @@ static int free_config(void)
return 0;
}
+
+static int reload_config(void)
+{
+ if (AST_RWLIST_WRLOCK(&odbc_tables)) {
+ ast_log(LOG_ERROR, "Unable to lock column list. Reload failed.\n");
+ return -1;
+ }
+
+ free_config();
+ load_config();
+ AST_RWLIST_UNLOCK(&odbc_tables);
+ return 0;
+}
+
static SQLHSTMT generic_prepare(struct odbc_obj *obj, void *data)
{
int res, i;
@@ -398,6 +415,12 @@ static int odbc_log(struct ast_cdr *cdr)
return -1;
}
+ // check was a connection on load by flag connected
+ if (!connected) {
+ ast_log(LOG_WARNING, "The initial connection is load is not work. Reload module...\n");
+ reload_config();
+ }
+
if (AST_RWLIST_RDLOCK(&odbc_tables)) {
ast_log(LOG_ERROR, "Unable to lock table list. Insert CDR(s) failed.\n");
ast_free(sql);
@@ -814,15 +837,7 @@ static int load_module(void)
static int reload(void)
{
- if (AST_RWLIST_WRLOCK(&odbc_tables)) {
- ast_log(LOG_ERROR, "Unable to lock column list. Reload failed.\n");
- return -1;
- }
-
- free_config();
- load_config();
- AST_RWLIST_UNLOCK(&odbc_tables);
- return 0;
+ return reload_config();
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Adaptive ODBC CDR backend",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment