Browse code

xcap_client: init db con per process

- introduced child_init function to init db connection per process
- db connection closed in destroy function
- reported and credits to Pascal Maugeri and Inaki Baz Castillo

Daniel-Constantin Mierla authored on 09/06/2009 11:47:15
Showing 2 changed files
... ...
@@ -1610,7 +1610,7 @@ void update_db_subs(db1_con_t *db,db_func_t dbf, shtable_t hash_table,
1610 1610
 			lock_release(&hash_table[i].lock);	
1611 1611
 	}
1612 1612
 
1613
-	update_vals[0].val.int_val= (int)time(NULL)- 10;
1613
+	update_vals[0].val.int_val= (int)time(NULL) - expires_offset;
1614 1614
 	update_ops[0]= OP_LT;
1615 1615
 	if(dbf.delete(db, update_cols, update_ops, update_vals, 1) < 0)
1616 1616
 	{
... ...
@@ -53,6 +53,7 @@ MODULE_VERSION
53 53
 #define XCAP_TABLE_VERSION   3
54 54
 
55 55
 static int mod_init(void);
56
+static int child_init(int rank);
56 57
 void destroy(void);
57 58
 struct mi_root* refreshXcapDoc(struct mi_root* cmd, void* param);
58 59
 int get_auid_flag(str auid);
... ...
@@ -112,7 +113,7 @@ struct module_exports exports= {
112 113
 	mod_init,					/* module initialization function */
113 114
 	0,							/* response handling function */
114 115
 	(destroy_function) destroy, /* destroy function */
115
-	0							/* per-child init function */
116
+	child_init					/* per-child init function */
116 117
 };
117 118
 
118 119
 /**
... ...
@@ -149,10 +150,13 @@ static int mod_init(void)
149 150
 		return -1;
150 151
 	}
151 152
 
152
-	if(db_check_table_version(&xcap_dbf, xcap_db, &xcap_db_table, XCAP_TABLE_VERSION) < 0) {
153
+	if(db_check_table_version(&xcap_dbf, xcap_db, &xcap_db_table,
154
+				XCAP_TABLE_VERSION) < 0) {
153 155
 		LM_ERR("error during table version check.\n");
154 156
 		return -1;
155 157
 	}
158
+	xcap_dbf.close(xcap_db);
159
+	xcap_db = NULL;
156 160
 
157 161
 	curl_global_init(CURL_GLOBAL_ALL);
158 162
 
... ...
@@ -163,9 +167,21 @@ static int mod_init(void)
163 167
 	return 0;
164 168
 }
165 169
 
170
+static int child_init(int rank)
171
+{
172
+	if((xcap_db = xcap_dbf.init(&xcap_db_url))==NULL)
173
+	{
174
+		LM_ERR("cannot connect to db\n");
175
+		return -1;
176
+	}
177
+	return -1;
178
+}
179
+
166 180
 void destroy(void)
167 181
 {
168 182
 	curl_global_cleanup();
183
+	if(xcap_db != NULL)
184
+		xcap_dbf.close(xcap_db);
169 185
 }
170 186
 
171 187
 void query_xcap_update(unsigned int ticks, void* param)