THIS IS AN AUTOMATED MESSAGE, DO NOT REPLY.
A new Flyspray task has been opened. Details are below.
User who did this - Kim Jakobsson (kjakobsson)
Attached to Project - sip-router
Summary - dialplan reload, out of memory
Task Type - Bug Report
Category - Module
Status - Unconfirmed
Assigned To -
Operating System - Linux
Severity - Medium
Priority - Normal
Reported Version - Development
Due in Version - Undecided
Due Date - Undecided
Details -
- Kamailio 3.0.x from GIT
- diaplan moduke with mysql backend
- approx 1700 lines of data
$ sercmd mi dp_reload
Aug 24 15:21:23 core01 /usr/local/sbin/kamailio[6764]: ERROR: db_mysql [km_dbase.c:346]: no memory left
Aug 24 15:21:23 core01 /usr/local/sbin/kamailio[6764]: ERROR: dialplan [dp_db.c:218]: failed to fetch
Aug 24 15:21:23 core01 /usr/local/sbin/kamailio[6764]: ERROR: dialplan [dialplan.c:450]: failed to reload rules fron database (db load)
Is this something that can be adjusted?
More information can be found at the following URL:
http://sip-router.org/tracker/index.php?do=details&task_id=86
You are receiving this message because you have requested it from the Flyspray bugtracking system. If you did not expect this message or don't want to receive mails in future, you can change your notification settings at the URL shown above.
Module: sip-router
Branch: master
Commit: a5583e0ccff1eda9c38041df9d15a8b21e3ebb0c
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=a5583e0…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Tue Aug 24 21:14:50 2010 +0200
core: counters can be used before forking
Counters can now be incremented (not only registered) before
counters_prefork_init(). This enables using them also from
mod_init() or the fixup functions (not recommended but needed for
"indirect" calls).
Fixes crashes when modules call a counter using function from
mod_init() or a fixup.
E.g.: xlog(s) does a dns lookup from mod_init. If the lookup fails
the dns code will try to increment the new dns.failed_dns_request
counter.
Reported-by: Michal Matyska michal.matyska iptel org
---
counters.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------
counters.h | 5 +++-
pt.c | 1 +
3 files changed, 65 insertions(+), 10 deletions(-)
diff --git a/counters.c b/counters.c
index dd8ddf7..56bcd2f 100644
--- a/counters.c
+++ b/counters.c
@@ -23,6 +23,7 @@
* History:
* --------
* 2010-08-06 initial version (andrei)
+ * 2010-08-24 counters can be used (inc,add) before prefork_init (andrei)
*/
#include "counters.h"
@@ -47,6 +48,11 @@
/* leave space for one flag */
#define MAX_COUNTER_ID 32767
+/* size (number of entries) of the temporary array used for keeping stats
+ pre-prefork init. Note: if more counters are registered then this size,
+ the array will be dynamically increased (doubled each time). The value
+ here is meant only to optimize startup/memory fragmentation. */
+#define PREINIT_CNTS_VALS_SIZE 128
struct counter_record {
str group;
@@ -85,7 +91,7 @@ static int grp_no; /* number of groups */
counter_array_t* _cnts_vals;
int _cnts_row_len; /* number of elements per row */
static int cnts_no; /* number of registered counters */
-static int cnts_max_rows; /* set to process number */
+static int cnts_max_rows; /* set to 0 if not yet fully init */
@@ -101,6 +107,8 @@ int init_counters()
goto error;
str_hash_init(&grp_hash_table);
cnts_no = 1; /* start at 1 (0 used only for invalid counters) */
+ cnts_max_rows = 0; /* 0 initially, !=0 after full init
+ (counters_prefork_init()) */
grp_no = 0;
cnt_id2record_size = CNT_ID2RECORD_SIZE;
cnt_id2record = pkg_malloc(sizeof(*cnt_id2record) * cnt_id2record_size);
@@ -127,7 +135,12 @@ void destroy_counters()
struct str_hash_entry* e;
struct str_hash_entry* bak;
if (_cnts_vals) {
- shm_free(_cnts_vals);
+ if (cnts_max_rows)
+ /* fully init => it is in shm */
+ shm_free(_cnts_vals);
+ else
+ /* partially init (before prefork) => pkg */
+ pkg_free(_cnts_vals);
_cnts_vals = 0;
}
if (cnts_hash_table.table) {
@@ -160,6 +173,7 @@ void destroy_counters()
grp_sorted_max_size = 0;
cnts_no = 0;
_cnts_row_len = 0;
+ cnts_max_rows = 0;
grp_no = 0;
}
@@ -171,7 +185,9 @@ void destroy_counters()
*/
int counters_prefork_init(int max_process_no)
{
+ counter_array_t* old;
int size, row_size;
+ counter_handle_t h;
/* round cnts_no so that cnts_no * sizeof(counter) it's a CACHELINE_PAD
multiple */
/* round-up row_size to a CACHELINE_PAD multiple if needed */
@@ -183,11 +199,20 @@ int counters_prefork_init(int max_process_no)
/* get updated cnts_no (row length) */
_cnts_row_len = row_size / sizeof(*_cnts_vals);
size = max_process_no * row_size;
+ /* replace the temporary pre-fork pkg array (with only 1 row) with
+ the final shm version (with max_process_no rows) */
+ old = _cnts_vals;
_cnts_vals = shm_malloc(max_process_no * row_size);
if (_cnts_vals == 0)
return -1;
memset(_cnts_vals, 0, max_process_no * row_size);
cnts_max_rows = max_process_no;
+ /* copy prefork values into the newly shm array */
+ if (old) {
+ for (h.id = 0; h.id < cnts_no; h.id++)
+ counter_pprocess_val(process_no, h) = old[h.id].v;
+ pkg_free(old);
+ }
return 0;
}
@@ -286,7 +311,9 @@ static struct counter_record* cnt_hash_add(
struct counter_record* cnt_rec;
struct grp_record* grp_rec;
struct counter_record** p;
+ counter_array_t* v;
int doc_len;
+ int n;
e = 0;
if (cnts_no >= MAX_COUNTER_ID)
@@ -323,7 +350,31 @@ static struct counter_record* cnt_hash_add(
cnt_rec->doc.s[0] = 0;
e->key = cnt_rec->name;
e->flags = 0;
- /* add it a pointer to it in the records array */
+ /* check to see if it fits in the prefork tmp. vals array.
+ This array contains only one "row", is allocated in pkg and
+ is used only until counters_prefork_init() (after that the
+ array is replaced with a shm version with all the needed rows).
+ */
+ if (cnt_rec->h.id >= _cnts_row_len || _cnts_vals == 0) {
+ /* array to small or not yet allocated => reallocate/allocate it
+ (min size PREINIT_CNTS_VALS_SIZE, max MAX_COUNTER_ID)
+ */
+ n = (cnt_rec->h.id < PREINIT_CNTS_VALS_SIZE) ?
+ PREINIT_CNTS_VALS_SIZE :
+ ((2 * (cnt_rec->h.id + (cnt_rec->h.id == 0)) < MAX_COUNTER_ID)?
+ (2 * (cnt_rec->h.id + (cnt_rec->h.id == 0))) :
+ MAX_COUNTER_ID + 1);
+ v = pkg_realloc(_cnts_vals, n * sizeof(*_cnts_vals));
+ if (v == 0)
+ /* realloc/malloc error */
+ goto error;
+ _cnts_vals = v;
+ /* zero newly allocated memory */
+ memset(&_cnts_vals[_cnts_row_len], 0,
+ (n - _cnts_row_len) * sizeof(*_cnts_vals));
+ _cnts_row_len = n; /* record new length */
+ }
+ /* add a pointer to it in the records array */
if (cnt_id2record_size <= cnt_rec->h.id) {
/* must increase the array */
p = pkg_realloc(cnt_id2record,
@@ -438,7 +489,7 @@ int counter_register( counter_handle_t* handle, const char* group,
str n;
struct counter_record* cnt_rec;
- if (unlikely(_cnts_vals)) {
+ if (unlikely(cnts_max_rows)) {
/* too late */
BUG("late attempt to register counter: %s.%s\n", group, name);
goto error;
@@ -554,7 +605,7 @@ counter_val_t counter_get_raw_val(counter_handle_t handle)
BUG("counters not fully initialized yet\n");
return 0;
}
- if (unlikely(handle.id >= cnts_no || handle.id < 0)) {
+ if (unlikely(handle.id >= cnts_no || (short)handle.id < 0)) {
BUG("invalid counter id %d (max %d)\n", handle.id, cnts_no - 1);
return 0;
}
@@ -597,7 +648,7 @@ void counter_reset(counter_handle_t handle)
{
int r;
- if (unlikely(_cnts_vals == 0)) {
+ if (unlikely(_cnts_vals == 0 || cnt_id2record == 0)) {
/* not init yet */
BUG("counters not fully initialized yet\n");
return;
@@ -622,7 +673,7 @@ void counter_reset(counter_handle_t handle)
*/
char* counter_get_name(counter_handle_t handle)
{
- if (unlikely(_cnts_vals == 0)) {
+ if (unlikely(_cnts_vals == 0 || cnt_id2record == 0)) {
/* not init yet */
BUG("counters not fully initialized yet\n");
goto error;
@@ -645,7 +696,7 @@ error:
*/
char* counter_get_group(counter_handle_t handle)
{
- if (unlikely(_cnts_vals == 0)) {
+ if (unlikely(_cnts_vals == 0 || cnt_id2record == 0)) {
/* not init yet */
BUG("counters not fully initialized yet\n");
goto error;
@@ -668,7 +719,7 @@ error:
*/
char* counter_get_doc(counter_handle_t handle)
{
- if (unlikely(_cnts_vals == 0)) {
+ if (unlikely(_cnts_vals == 0 || cnt_id2record == 0)) {
/* not init yet */
BUG("counters not fully initialized yet\n");
goto error;
diff --git a/counters.h b/counters.h
index ca09ab4..6081ae0 100644
--- a/counters.h
+++ b/counters.h
@@ -109,7 +109,10 @@ char* counter_get_name(counter_handle_t handle);
char* counter_get_group(counter_handle_t handle);
char* counter_get_doc(counter_handle_t handle);
-/** gets the per process value of counter h for process p_no. */
+/** gets the per process value of counter h for process p_no.
+ * Note that if used before counter_prefork_init() process_no is 0
+ * and _cnts_vals will point into a temporary one "row" array.
+ */
#define counter_pprocess_val(p_no, h) \
_cnts_vals[(p_no) * _cnts_row_len + (h).id].v
diff --git a/pt.c b/pt.c
index 994f998..68842e6 100644
--- a/pt.c
+++ b/pt.c
@@ -47,6 +47,7 @@
#if defined PKG_MALLOC || defined SHM_MEM
#include "cfg_core.h"
#endif
+#include "daemonize.h"
#include <stdio.h>
#include <time.h> /* time(), used to initialize random numbers */
Module: sip-router
Branch: master
Commit: a5b499a42d9b0613cc3e99619e744cbe894db3c1
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=a5b499a…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Tue Aug 24 12:27:08 2010 +0200
core: don't try to fixup to PVE in fixup_var_str*
Moved PVE (PV based format string) fixing attempts from
fixup_var_str* into new fixup functions: fixup_var_pve_str*.
If the argument is a constant string, fixup_var_pve_str*() will
try first "fixing" it to a PVAR, then (if it fails) to an AVP,
SELECT, PVE and finally normal string. If the PVE fixup returned a
"static" PVE, the result will be discarded and a normal string
fparam will be created (a little bit faster at runtime).
The only difference between fixup_var_str*() and
fixup_var_pve_str*() is that fixup_var_str*() will not attempt
fixing to PVE (does not support PV style format strings).
---
sr_module.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++------
sr_module.h | 17 +++++++++++--
2 files changed, 81 insertions(+), 11 deletions(-)
diff --git a/sr_module.c b/sr_module.c
index c759a17..f975062 100644
--- a/sr_module.c
+++ b/sr_module.c
@@ -41,11 +41,9 @@
* 2008-11-26 added fparam_free_contents() and fix_param_types (andrei)
*/
-/*!
- * \file
- * \brief SIP-router core ::
- * \ingroup core
- * Module: \ref core
+/** module loading, standard fixups.
+ * @file sr_module.c
+ * @ingroup core
*/
#include "sr_module.h"
@@ -1299,9 +1297,6 @@ int fixup_var_str_12(void** param, int param_no)
if ((ret = fix_param(FPARAM_PVS, param)) <= 0) return ret;
if ((ret = fix_param(FPARAM_AVP, param)) <= 0) return ret;
if ((ret = fix_param(FPARAM_SELECT, param)) <= 0) return ret;
- /* FIXME: if not PVE (string only), fix as string! or
- make a separate fixup fixup_varpve_... */
- if ((ret = fix_param(FPARAM_PVE, param)) <= 0) return ret;
}
if ((ret = fix_param(FPARAM_STR, param)) <= 0) return ret;
ERR("Error while fixing parameter, PV, AVP, SELECT, and str conversions"
@@ -1324,6 +1319,64 @@ int fixup_var_str_2(void** param, int param_no)
}
+
+/** fixup variable-pve-string.
+ * The parameter can be a PVAR, AVP, SELECT, PVE (pv based format string)
+ * or string.
+ * PVAR, AVP and select and non-static PVEs identifiers will be resolved to
+ * their values during runtime.
+ * The parameter value will be converted to fparam structure
+ * @param param - double pointer to param, as for normal fixup functions.
+ * @param param_no - parameter number, ignored.
+ * @return -1 on an error, 0 on success.
+ */
+int fixup_var_pve_str_12(void** param, int param_no)
+{
+ int ret;
+ fparam_t* fp;
+ if (fixup_get_param_type(param) != STRING_RVE_ST) {
+ /* if called with a RVE already converted to string =>
+ don't try AVP, PVAR, SELECT or PVE again (to avoid double
+ deref., e.g.: $foo="$bar"; f($foo) ) */
+ if ((ret = fix_param(FPARAM_PVS, param)) <= 0) return ret;
+ if ((ret = fix_param(FPARAM_AVP, param)) <= 0) return ret;
+ if ((ret = fix_param(FPARAM_SELECT, param)) <= 0) return ret;
+ if ((ret = fix_param(FPARAM_PVE, param)) <= 0) {
+ if (ret < 0)
+ return ret;
+ /* check if it resolved to a dynamic or "static" PVE.
+ If the resulting PVE is static (normal string), discard
+ it and use the normal string fixup (faster at runtime) */
+ fp = (fparam_t*)*param;
+ if (fp->v.pve->spec.getf == 0)
+ fparam_free_restore(param); /* fallback to STR below */
+ else
+ return ret; /* dynamic PVE => return */
+ }
+
+ }
+ if ((ret = fix_param(FPARAM_STR, param)) <= 0) return ret;
+ ERR("Error while fixing parameter, PV, AVP, SELECT, and str conversions"
+ " failed\n");
+ return -1;
+}
+
+/* Same as fixup_var_pve_str_12 but applies to the 1st parameter only */
+int fixup_var_pve_str_1(void** param, int param_no)
+{
+ if (param_no == 1) return fixup_var_pve_str_12(param, param_no);
+ else return 0;
+}
+
+/* Same as fixup_var_pve_str_12 but applies to the 2nd parameter only */
+int fixup_var_pve_str_2(void** param, int param_no)
+{
+ if (param_no == 2) return fixup_var_pve_str_12(param, param_no);
+ else return 0;
+}
+
+
+
/*
* Fixup variable integer, the parameter can be
* AVP, SELECT, or ordinary integer. AVP and select
@@ -1654,6 +1707,9 @@ int is_fparam_rve_fixup(fixup_function f)
if (f == fixup_var_str_12 ||
f == fixup_var_str_1 ||
f == fixup_var_str_2 ||
+ f == fixup_var_pve_str_12 ||
+ f == fixup_var_pve_str_1 ||
+ f == fixup_var_pve_str_2 ||
f == fixup_var_int_12 ||
f == fixup_var_int_1 ||
f == fixup_var_int_2 ||
@@ -1684,6 +1740,7 @@ free_fixup_function get_fixup_free(fixup_function f)
free_fixup_function ret;
/* "pure" fparam, all parameters */
if (f == fixup_var_str_12 ||
+ f == fixup_var_pve_str_12 ||
f == fixup_var_int_12 ||
f == fixup_int_12 ||
f == fixup_str_12 ||
@@ -1692,6 +1749,7 @@ free_fixup_function get_fixup_free(fixup_function f)
/* "pure" fparam, 1st parameter */
if (f == fixup_var_str_1 ||
+ f == fixup_var_pve_str_1 ||
f == fixup_var_int_1 ||
f == fixup_int_1 ||
f == fixup_str_1 ||
@@ -1700,6 +1758,7 @@ free_fixup_function get_fixup_free(fixup_function f)
/* "pure" fparam, 2nd parameters */
if (f == fixup_var_str_2 ||
+ f == fixup_var_pve_str_2 ||
f == fixup_var_int_2 ||
f == fixup_int_2 ||
f == fixup_str_2 ||
diff --git a/sr_module.h b/sr_module.h
index 4d32514..fb8be8b 100644
--- a/sr_module.h
+++ b/sr_module.h
@@ -49,9 +49,8 @@
* 2008-11-26 added fparam_free_contents() and fix_param_types (andrei)
*/
-/*!
- * \file
- * \brief modules/plug-in structures declarations
+/** modules structures/exports declarations and utilities (fixups a.s.o).
+ * @file sr_module.h
*/
@@ -515,6 +514,18 @@ int fixup_var_str_1(void** param, int param_no);
/* Same as fixup_var_str_12 but applies to the 2nd parameter only */
int fixup_var_str_2(void** param, int param_no);
+/** fixup variable-pve-string.
+ * The parameter can be a PVAR, AVP, SELECT, PVE (pv based format string)
+ * or string.
+ */
+int fixup_var_pve_str_12(void** param, int param_no);
+
+/* same as fixup_var_pve_str_12 but applies to the 1st parameter only */
+int fixup_var_pve_str_1(void** param, int param_no);
+
+/* same as fixup_var_pve_str_12 but applies to the 2nd parameter only */
+int fixup_var_pve_str_2(void** param, int param_no);
+
/*
* Fixup variable integer, the parameter can be
* AVP, SELECT, or ordinary integer. AVP and select
Module: sip-router
Branch: kamailio_3.0
Commit: 82fe7671c9c65cde0bd53bab615fa37b627fe3c2
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=82fe767…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Fri Aug 20 12:22:56 2010 +0200
tls: fix state change while waiting for lock return
tls_h_fix_read_conn() did not return the right thing if the state
changed while waiting for the lock (the fall-through return was
error instead of success).
Reported-by: Couprie Geoffroy geoffroy couprie atosorigin com
(cherry picked from commit 513c21f67f88484dd12dd6adce6d6ddc7fb60c31)
---
modules/tls/tls_server.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/modules/tls/tls_server.c b/modules/tls/tls_server.c
index 6d32af6..52b62e3 100644
--- a/modules/tls/tls_server.c
+++ b/modules/tls/tls_server.c
@@ -971,7 +971,7 @@ int tls_h_fix_read_conn(struct tcp_connection *c)
int ret;
struct tls_extra_data* tls_c;
- ret = -1;
+ ret = 1;
tls_c = 0;
if (unlikely(c->extra_data==0)){
lock_get(&c->write_lock);
Module: sip-router
Branch: sr_3.0
Commit: 513c21f67f88484dd12dd6adce6d6ddc7fb60c31
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=513c21f…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Fri Aug 20 12:22:56 2010 +0200
tls: fix state change while waiting for lock return
tls_h_fix_read_conn() did not return the right thing if the state
changed while waiting for the lock (the fall-through return was
error instead of success).
Reported-by: Couprie Geoffroy geoffroy couprie atosorigin com
---
modules/tls/tls_server.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/modules/tls/tls_server.c b/modules/tls/tls_server.c
index 6d32af6..52b62e3 100644
--- a/modules/tls/tls_server.c
+++ b/modules/tls/tls_server.c
@@ -971,7 +971,7 @@ int tls_h_fix_read_conn(struct tcp_connection *c)
int ret;
struct tls_extra_data* tls_c;
- ret = -1;
+ ret = 1;
tls_c = 0;
if (unlikely(c->extra_data==0)){
lock_get(&c->write_lock);