[asterisk-commits] murf: branch murf/selway r143673 - in /team/murf/selway: cdr/ channels/ funcs...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Sep 19 14:42:11 CDT 2008
Author: murf
Date: Fri Sep 19 14:42:10 2008
New Revision: 143673
URL: http://svn.digium.com/view/asterisk?view=rev&rev=143673
Log:
all the patches applied
Modified:
team/murf/selway/cdr/cdr_odbc.c
team/murf/selway/channels/chan_sip.c
team/murf/selway/funcs/func_odbc.c
team/murf/selway/res/res_odbc.c
Modified: team/murf/selway/cdr/cdr_odbc.c
URL: http://svn.digium.com/view/asterisk/team/murf/selway/cdr/cdr_odbc.c?view=diff&rev=143673&r1=143672&r2=143673
==============================================================================
--- team/murf/selway/cdr/cdr_odbc.c (original)
+++ team/murf/selway/cdr/cdr_odbc.c Fri Sep 19 14:42:10 2008
@@ -90,7 +90,7 @@
connected = 0;
}
-static int odbc_log(struct ast_cdr *cdr)
+static void build_query(struct ast_cdr *cdr)
{
int ODBC_res;
char sqlcmd[2048] = "", timestr[128];
@@ -102,7 +102,6 @@
else
ast_localtime(&cdr->start.tv_sec, &tm, NULL);
- ast_mutex_lock(&odbc_lock);
strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
memset(sqlcmd,0,2048);
if (loguniqueid) {
@@ -116,13 +115,12 @@
"duration,billsec,disposition,amaflags,accountcode) "
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)", table);
}
-
if (!connected) {
res = odbc_init();
if (res < 0) {
odbc_disconnect();
ast_mutex_unlock(&odbc_lock);
- return 0;
+ return;
}
}
@@ -134,7 +132,7 @@
SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
odbc_disconnect();
ast_mutex_unlock(&odbc_lock);
- return 0;
+ return;
}
/* We really should only have to do this once. But for some
@@ -149,7 +147,7 @@
SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
odbc_disconnect();
ast_mutex_unlock(&odbc_lock);
- return 0;
+ return;
}
SQLBindParameter(ODBC_stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(timestr), 0, ×tr, 0, NULL);
@@ -174,6 +172,14 @@
SQLBindParameter(ODBC_stmt, 15, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->uniqueid), 0, cdr->uniqueid, 0, NULL);
SQLBindParameter(ODBC_stmt, 16, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->userfield), 0, cdr->userfield, 0, NULL);
}
+}
+
+static int odbc_log(struct ast_cdr *cdr)
+{
+ int res = 0;
+
+ ast_mutex_lock(&odbc_lock);
+ build_query(cdr);
if (connected) {
res = odbc_do_query();
@@ -182,7 +188,7 @@
ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Query FAILED Call not logged!\n");
if (option_verbose > 10)
ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Reconnecting to dsn %s\n", dsn);
- SQLDisconnect(ODBC_con);
+ odbc_disconnect();
res = odbc_init();
if (res < 0) {
if (option_verbose > 10)
@@ -191,6 +197,8 @@
} else {
if (option_verbose > 10)
ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Trying Query again!\n");
+ SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
+ build_query(cdr); /* what a waste. If we have to reconnect, we have to build a new query */
res = odbc_do_query();
if (res < 0) {
if (option_verbose > 10)
@@ -374,14 +382,19 @@
static int odbc_do_query(void)
{
int ODBC_res;
-
+ if (ODBC_stmt == SQL_NULL_HANDLE ) {
+ if (option_verbose > 10)
+ ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: ODBC_stmt is a NULL HANDLE\n");
+ }
+ else {
+ if (option_verbose > 10)
+ ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: ODBC_stmt LOOKS OK...\n");
+ }
ODBC_res = SQLExecute(ODBC_stmt);
if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
if (option_verbose > 10)
ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Error in Query %d\n", ODBC_res);
- SQLFreeHandle(SQL_HANDLE_STMT, ODBC_stmt);
- odbc_disconnect();
return -1;
} else {
if (option_verbose > 10)
Modified: team/murf/selway/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/murf/selway/channels/chan_sip.c?view=diff&rev=143673&r1=143672&r2=143673
==============================================================================
--- team/murf/selway/channels/chan_sip.c (original)
+++ team/murf/selway/channels/chan_sip.c Fri Sep 19 14:42:10 2008
@@ -2076,6 +2076,9 @@
}
}
+/* adding this for tracking */
+int hangfix_count = 0;
+
/*! \brief Kill a SIP dialog (called by scheduler) */
static int __sip_autodestruct(const void *data)
{
@@ -2092,10 +2095,14 @@
}
/* If there are packets still waiting for delivery, delay the destruction */
- if (p->packets) {
+ if (p->packets && !ast_test_flag(&p->flags[0], SIP_NEEDDESTROY)) {
if (option_debug > 2)
ast_log(LOG_DEBUG, "Re-scheduled destruction of SIP call %s\n", p->callid ? p->callid : "<unknown>");
append_history(p, "ReliableXmit", "timeout");
+ if (p->method == SIP_CANCEL || p->method == SIP_BYE) {
+ ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ hangfix_count++;
+ }
return 10000;
}
@@ -10028,6 +10035,15 @@
"\r\n", total, idtext);
return 0;
}
+/*! \brief CLI Show Hangfix command; shows how many times a 'software safety valve'
+ * saved a channel from being hung
+ * */
+
+static int sip_show_hangfix(int fd, int argc, char *argv[])
+{
+ ast_cli(fd,"The NEEDDESTROY flag has been set on %d channels so far; they probably would have hung otherwise.\n", hangfix_count);
+ return RESULT_SUCCESS;
+}
/*! \brief CLI Show Peers command */
static int sip_show_peers(int fd, int argc, char *argv[])
@@ -11791,6 +11807,10 @@
static char show_history_usage[] =
"Usage: sip show history <channel>\n"
" Provides detailed dialog history on a given SIP channel.\n";
+
+static char show_hangfix_usage[] =
+"Usage: sip show hangfix\n"
+" Shows how many times a code patch allowed zombie channels to taste sweet death.\n";
static char show_peers_usage[] =
"Usage: sip show peers [like <pattern>]\n"
@@ -18476,6 +18496,10 @@
sip_show_objects, "List all SIP object allocations",
show_objects_usage },
+ { { "sip", "show", "hangfix", NULL },
+ sip_show_hangfix, "Show how many times a patch allowed a zombie channel to die",
+ show_hangfix_usage },
+
{ { "sip", "show", "peers", NULL },
sip_show_peers, "List defined SIP peers",
show_peers_usage },
Modified: team/murf/selway/funcs/func_odbc.c
URL: http://svn.digium.com/view/asterisk/team/murf/selway/funcs/func_odbc.c?view=diff&rev=143673&r1=143672&r2=143673
==============================================================================
--- team/murf/selway/funcs/func_odbc.c (original)
+++ team/murf/selway/funcs/func_odbc.c Fri Sep 19 14:42:10 2008
@@ -63,20 +63,35 @@
char sql_read[2048];
char sql_write[2048];
unsigned int flags;
+ int query_timeout;
struct ast_custom_function *acf;
};
+struct gps {
+ long query_timeout;
+ char *sql;
+};
+
AST_LIST_HEAD_STATIC(queries, acf_odbc_query);
static SQLHSTMT generic_prepare(struct odbc_obj *obj, void *data)
{
int res;
- char *sql = data;
+ struct gps *gps = data;
+ char *sql = gps->sql;
SQLHSTMT stmt;
res = SQLAllocHandle (SQL_HANDLE_STMT, obj->con, &stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
+ return NULL;
+ }
+
+ res = SQLSetStmtAttr(stmt, SQL_ATTR_QUERY_TIMEOUT, (SQLPOINTER)gps->query_timeout, 0);
+ if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
+ ast_log(LOG_WARNING, "SQL set query timeout failed![%s]\n", sql);
+ SQLCloseCursor(stmt);
+ SQLFreeHandle(SQL_HANDLE_STMT, stmt);
return NULL;
}
@@ -108,6 +123,7 @@
);
SQLHSTMT stmt;
SQLLEN rows=0;
+ struct gps gps = { .sql = buf };
AST_LIST_LOCK(&queries);
AST_LIST_TRAVERSE(&queries, query, list) {
@@ -123,6 +139,7 @@
}
obj = ast_odbc_request_obj(query->dsn, 0);
+ gps.query_timeout = query->query_timeout;
if (!obj) {
ast_log(LOG_ERROR, "No database handle available with the name of '%s' (check res_odbc.conf)\n", query->dsn);
@@ -184,7 +201,7 @@
AST_LIST_UNLOCK(&queries);
- stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, buf);
+ stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps);
if (stmt) {
/* Rows affected */
@@ -225,6 +242,7 @@
SQLHSTMT stmt;
SQLSMALLINT colcount=0;
SQLLEN indicator;
+ struct gps gps = { .sql = sql };
AST_LIST_LOCK(&queries);
AST_LIST_TRAVERSE(&queries, query, list) {
@@ -240,6 +258,7 @@
}
obj = ast_odbc_request_obj(query->dsn, 0);
+ gps.query_timeout = query->query_timeout;
if (!obj) {
ast_log(LOG_ERROR, "No such DSN registered (or out of connections): %s (check res_odbc.conf)\n", query->dsn);
@@ -274,7 +293,7 @@
AST_LIST_UNLOCK(&queries);
- stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, sql);
+ stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps);
if (!stmt) {
ast_odbc_release_obj(obj);
@@ -435,6 +454,13 @@
if ((tmp = ast_variable_retrieve(cfg, catg, "escapecommas"))) {
if (ast_false(tmp))
ast_clear_flag((*query), OPT_ESCAPECOMMAS);
+ }
+
+ if ((tmp = ast_variable_retrieve(cfg, catg, "timeout"))) {
+ (*query)->query_timeout = atoi(tmp);
+ if ((*query)->query_timeout < 0) {
+ (*query)->query_timeout = 0;
+ }
}
(*query)->acf = ast_calloc(1, sizeof(struct ast_custom_function));
Modified: team/murf/selway/res/res_odbc.c
URL: http://svn.digium.com/view/asterisk/team/murf/selway/res/res_odbc.c?view=diff&rev=143673&r1=143672&r2=143673
==============================================================================
--- team/murf/selway/res/res_odbc.c (original)
+++ team/murf/selway/res/res_odbc.c Fri Sep 19 14:42:10 2008
@@ -96,7 +96,12 @@
stmt = prepare_cb(obj, data);
if (stmt) {
+ if (option_verbose > 10)
+ ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Executing statement!\n");
+
res = SQLExecute(stmt);
+ if (option_verbose > 10)
+ ast_verbose( VERBOSE_PREFIX_4 "cdr_odbc: Statement executed, res= %d\n", res);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO) && (res != SQL_NO_DATA)) {
if (res == SQL_ERROR) {
SQLGetDiagField(SQL_HANDLE_STMT, stmt, 1, SQL_DIAG_NUMBER, &numfields, SQL_IS_INTEGER, &diagbytes);
@@ -190,6 +195,7 @@
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
obj->up = 0;
} else {
+ SQLSetStmtAttr(stmt, SQL_ATTR_QUERY_TIMEOUT, (SQLPOINTER)5, 0);
res = SQLPrepare(stmt, (unsigned char *)test_sql, SQL_NTS);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
obj->up = 0;
More information about the asterisk-commits
mailing list