Quellcode durchsuchen

tm: convert to PKG/SHM memory logging helper functions

Henning Westerholt vor 5 Jahren
Ursprung
Commit
2ac50d041f

+ 7 - 5
src/modules/tm/dlg.c

@@ -73,8 +73,10 @@ int register_new_dlg_cb(int type, dialog_cb f, void *param)
 	struct new_dlg_cb *dlg_cb;
 
 	dlg_cb = shm_malloc(sizeof(struct new_dlg_cb));
-	if(dlg_cb == 0)
+	if(dlg_cb == 0) {
+		SHM_MEM_ERROR;
 		return E_OUT_OF_MEM;
+	}
 	dlg_cb->types = type;
 	dlg_cb->callback = f;
 	dlg_cb->param = param;
@@ -195,7 +197,7 @@ static inline int str_duplicate(str *_d, str *_s)
 {
 	_d->s = shm_malloc(_s->len);
 	if(!_d->s) {
-		LM_ERR("no share memory left\n");
+		SHM_MEM_ERROR;
 		return -1;
 	}
 
@@ -323,7 +325,7 @@ int new_dlg_uac(str *_cid, str *_ltag, unsigned int _lseq, str *_luri,
 
 	res = (dlg_t *)shm_malloc(sizeof(dlg_t));
 	if(res == 0) {
-		LM_ERR("no memory left\n");
+		SHM_MEM_ERROR;
 		return -2;
 	}
 
@@ -908,7 +910,7 @@ static inline int get_dlg_uri(struct hdr_field *_h, str *_s)
 
 	_s->s = shm_malloc(_h->body.len - tag_len);
 	if(!_s->s) {
-		LM_ERR("no share memory left\n");
+		SHM_MEM_ERROR;
 		return -1;
 	}
 
@@ -1024,7 +1026,7 @@ int new_dlg_uas(struct sip_msg *_req, int _code, /*str* _tag,*/ dlg_t **_d)
 
 	res = (dlg_t *)shm_malloc(sizeof(dlg_t));
 	if(res == 0) {
-		LM_ERR("no memory left\n");
+		SHM_MEM_ERROR;
 		return -3;
 	}
 	/* Clear everything */

+ 2 - 1
src/modules/tm/h_table.c

@@ -333,6 +333,7 @@ struct cell *build_cell(struct sip_msg *p_msg)
 
 	new_cell = (struct cell *)shm_malloc(cell_size);
 	if(!new_cell) {
+		SHM_MEM_ERROR;
 		ser_error = E_OUT_OF_MEM;
 		return NULL;
 	}
@@ -480,7 +481,7 @@ struct s_table *init_hash_table()
 	/*allocs the table*/
 	_tm_table = (struct s_table *)shm_malloc(sizeof(struct s_table));
 	if(!_tm_table) {
-		LM_ERR("no shmem for TM table\n");
+		SHM_MEM_ERROR;
 		goto error0;
 	}
 

+ 3 - 3
src/modules/tm/rpc_uac.c

@@ -217,7 +217,7 @@ static int get_hfblock(str *uri, struct hdr_field *hf, int proto,
 	/* construct a single header block now */
 	ret = pkg_malloc(total_len);
 	if (!ret) {
-		LM_ERR("no pkg mem for hf block\n");
+		PKG_MEM_ERROR;
 		goto error;
 	}
 	i = sl.next;
@@ -278,7 +278,7 @@ static void  rpc_print_routes(rpc_t* rpc, void* c,
 
 	buf=pkg_malloc(size+1);
 	if (buf==0){
-		LM_ERR("out of memory\n");
+		PKG_MEM_ERROR;
 		rpc->add(c, "s", "");
 		return;
 	}
@@ -322,7 +322,7 @@ static void  rpc_print_uris(rpc_t* rpc, void* c, struct sip_msg* reply)
 	dlg_t* dlg;
 	dlg=shm_malloc(sizeof(dlg_t));
 	if (dlg==0){
-		ERR("out of memory (shm)\n");
+		SHM_MEM_ERROR;
 		return;
 	}
 	memset(dlg, 0, sizeof(dlg_t));

+ 8 - 8
src/modules/tm/t_fifo.c

@@ -208,12 +208,12 @@ int parse_tw_append( modparam_t type, void* val)
 	/* new tw_append structure */
 	app = (struct tw_append*)pkg_malloc( sizeof(struct tw_append) );
 	if (app==0) {
-		LM_ERR("no more pkg memory\n");
+		PKG_MEM_ERROR;
 		goto error;
 	}
 	app->name.s = (char*)pkg_malloc( foo.len+1 );
 	if (app->name.s==0) {
-		LM_ERR("no more pkg memory\n");
+		PKG_MEM_ERROR;
 		goto error;
 	}
 	memcpy( app->name.s, foo.s, foo.len);
@@ -234,7 +234,7 @@ int parse_tw_append( modparam_t type, void* val)
 		/* new hdr_avp structure */
 		ha = (struct hdr_avp*)pkg_malloc( sizeof(struct hdr_avp) );
 		if (ha==0) {
-			LM_ERR("no more pkg memory\n");
+			PKG_MEM_ERROR;
 			goto error;
 		}
 		memset( ha, 0, sizeof(struct hdr_avp));
@@ -250,7 +250,7 @@ int parse_tw_append( modparam_t type, void* val)
 			/* set the title */
 			ha->title.s = (char*)pkg_malloc( foo.len+1 );
 			if (ha->title.s==0) {
-				LM_ERR("no more pkg memory\n");
+				PKG_MEM_ERROR;
 				goto error;
 			}
 			memcpy( ha->title.s, foo.s, foo.len);
@@ -297,7 +297,7 @@ int parse_tw_append( modparam_t type, void* val)
 				/* string name */
 				ha->sval.s = (char*)pkg_malloc(avp_name.s.len+1);
 				if (ha->sval.s==0) {
-					LM_ERR("no more pkg mem\n");
+					PKG_MEM_ERROR;
 					goto error;
 				}
 				memcpy( ha->sval.s, avp_name.s.s, avp_name.s.len);
@@ -313,7 +313,7 @@ int parse_tw_append( modparam_t type, void* val)
 					foo.s=int2str((unsigned long)ha->ival, &foo.len);
 					ha->title.s = (char*)pkg_malloc( n+1 );
 					if (ha->title.s==0) {
-						LM_ERR("no more pkg memory\n");
+						PKG_MEM_ERROR;
 						goto error;
 					}
 					memcpy( ha->title.s, foo.s, foo.len);
@@ -336,7 +336,7 @@ int parse_tw_append( modparam_t type, void* val)
 				/* duplicate hdr name */
 				ha->sval.s = (char*)pkg_malloc(foo.len+1);
 				if (ha->sval.s==0) {
-					LM_ERR("no more pkg mem\n");
+					PKG_MEM_ERROR;
 					goto error;
 				}
 				memcpy( ha->sval.s, foo.s, foo.len);
@@ -413,7 +413,7 @@ int fixup_t_write( void** param, int param_no)
 	if (param_no==2) {
 		twi = (struct tw_info*)pkg_malloc( sizeof(struct tw_info) );
 		if (twi==0) {
-			LM_ERR("no more pkg memory\n");
+			PKG_MEM_ERROR;
 			return E_OUT_OF_MEM;
 		}
 		memset( twi, 0 , sizeof(struct tw_info));

+ 13 - 2
src/modules/tm/t_fwd.c

@@ -229,6 +229,7 @@ static int prepare_new_uac( struct cell *t, struct sip_msg *i_req,
 		i_req->parsed_uri_ok=0;
 		i_req->new_uri.s=pkg_malloc(uri->len);
 		if (unlikely(i_req->new_uri.s==0)){
+			PKG_MEM_ERROR;
 			ret=E_OUT_OF_MEM;
 			goto error03;
 		}
@@ -498,6 +499,7 @@ static int prepare_new_uac( struct cell *t, struct sip_msg *i_req,
 	if (unlikely(i_req->path_vec.s && i_req->path_vec.len)){
 		t->uac[branch].path.s=shm_malloc(i_req->path_vec.len+1);
 		if (unlikely(t->uac[branch].path.s==0)) {
+			SHM_MEM_ERROR;
 			shm_free(shbuf);
 			t->uac[branch].request.buffer=0;
 			t->uac[branch].request.buffer_len=0;
@@ -513,6 +515,7 @@ static int prepare_new_uac( struct cell *t, struct sip_msg *i_req,
 	if (unlikely(i_req->instance.s && i_req->instance.len)){
 		t->uac[branch].instance.s=shm_malloc(i_req->instance.len+1);
 		if (unlikely(t->uac[branch].instance.s==0)) {
+			SHM_MEM_ERROR;
 			shm_free(shbuf);
 			t->uac[branch].request.buffer=0;
 			t->uac[branch].request.buffer_len=0;
@@ -528,6 +531,7 @@ static int prepare_new_uac( struct cell *t, struct sip_msg *i_req,
 	if (unlikely(i_req->ruid.s && i_req->ruid.len)){
 		t->uac[branch].ruid.s=shm_malloc(i_req->ruid.len+1);
 		if (unlikely(t->uac[branch].ruid.s==0)) {
+			SHM_MEM_ERROR;
 			shm_free(shbuf);
 			t->uac[branch].request.buffer=0;
 			t->uac[branch].request.buffer_len=0;
@@ -543,6 +547,7 @@ static int prepare_new_uac( struct cell *t, struct sip_msg *i_req,
 	if (unlikely(i_req->location_ua.s && i_req->location_ua.len)){
 		t->uac[branch].location_ua.s=shm_malloc(i_req->location_ua.len+1);
 		if (unlikely(t->uac[branch].location_ua.s==0)) {
+			SHM_MEM_ERROR;
 			shm_free(shbuf);
 			t->uac[branch].request.buffer=0;
 			t->uac[branch].request.buffer_len=0;
@@ -670,7 +675,7 @@ static char *print_uac_request_from_buf( struct cell *t, struct sip_msg *i_req,
 	shbuf=(char *)shm_malloc(*len);
 	if (!shbuf) {
 		ser_error=E_OUT_OF_MEM;
-		LM_ERR("no shmem\n");
+		SHM_MEM_ERROR;
 		goto error01;
 	}
 
@@ -906,6 +911,7 @@ static int add_uac_from_buf( struct cell *t, struct sip_msg *request,
 	if (unlikely(path && path->s)){
 		t->uac[branch].path.s=shm_malloc(path->len+1);
 		if (unlikely(t->uac[branch].path.s==0)) {
+			SHM_MEM_ERROR;
 			shm_free(shbuf);
 			t->uac[branch].request.buffer=0;
 			t->uac[branch].request.buffer_len=0;
@@ -922,6 +928,7 @@ static int add_uac_from_buf( struct cell *t, struct sip_msg *request,
 	if (unlikely(instance && instance->s)){
 		t->uac[branch].instance.s=shm_malloc(instance->len+1);
 		if (unlikely(t->uac[branch].instance.s==0)) {
+			SHM_MEM_ERROR;
 			shm_free(shbuf);
 			t->uac[branch].request.buffer=0;
 			t->uac[branch].request.buffer_len=0;
@@ -938,6 +945,7 @@ static int add_uac_from_buf( struct cell *t, struct sip_msg *request,
 	if (unlikely(ruid && ruid->s)){
 		t->uac[branch].ruid.s=shm_malloc(ruid->len+1);
 		if (unlikely(t->uac[branch].ruid.s==0)) {
+			SHM_MEM_ERROR;
 			shm_free(shbuf);
 			t->uac[branch].request.buffer=0;
 			t->uac[branch].request.buffer_len=0;
@@ -954,6 +962,7 @@ static int add_uac_from_buf( struct cell *t, struct sip_msg *request,
 	if (unlikely(location_ua && location_ua->s)){
 		t->uac[branch].location_ua.s=shm_malloc(location_ua->len+1);
 		if (unlikely(t->uac[branch].location_ua.s==0)) {
+			SHM_MEM_ERROR;
 			shm_free(shbuf);
 			t->uac[branch].request.buffer=0;
 			t->uac[branch].request.buffer_len=0;
@@ -1213,8 +1222,10 @@ static struct cancel_reason* cancel_reason_pack(short cause, void* data,
 		if (unlikely(reason_len == 0))
 			return 0; /* nothing to do, no reason */
 		cr = shm_malloc(sizeof(struct cancel_reason) + reason_len);
-		if (unlikely(cr == 0))
+		if (unlikely(cr == 0)) {
+			SHM_MEM_ERROR;
 			goto error;
+		}
 		d = (char*)cr +sizeof(*cr);
 		cr->cause = CANCEL_REAS_PACKED_HDRS;
 		cr->u.packed_hdrs.s = d;

+ 2 - 2
src/modules/tm/t_hooks.c

@@ -71,7 +71,7 @@ int init_tmcb_lists()
 	local_req_in_tmcb_hl = (struct tmcb_head_list*)shm_malloc
 		( sizeof(struct tmcb_head_list) );
 	if ((req_in_tmcb_hl==0) || (local_req_in_tmcb_hl==0)) {
-		LM_CRIT("no more shared mem\n");
+		SHM_MEM_CRITICAL;
 		goto error;
 	}
 	req_in_tmcb_hl->first = 0;
@@ -133,7 +133,7 @@ int insert_tmcb(struct tmcb_head_list *cb_list, int types,
 
 	/* build a new callback structure */
 	if (!(cbp=shm_malloc( sizeof( struct tm_callback)))) {
-		LM_ERR("out of shm. mem\n");
+		SHM_MEM_ERROR;
 		return E_OUT_OF_MEM;
 	}
 

+ 7 - 7
src/modules/tm/t_msgbuilder.c

@@ -170,7 +170,7 @@ char *build_local(struct cell *Trans,unsigned int branch,
 
 	cancel_buf=shm_malloc( *len+1 );
 	if (!cancel_buf) {
-		LM_ERR("cannot allocate memory\n");
+		SHM_MEM_ERROR;
 		goto error01;
 	}
 	p = cancel_buf;
@@ -327,7 +327,7 @@ char *build_local_reparse(tm_cell_t *Trans,unsigned int branch,
 	cancel_buf = shm_malloc(sizeof(char)*cancel_buf_len);
 	if (!cancel_buf)
 	{
-		LM_ERR("cannot allocate shared memory\n");
+		SHM_MEM_ERROR;
 		goto error;
 	}
 	d = cancel_buf;
@@ -651,7 +651,7 @@ static inline int get_uac_rs(sip_msg_t *msg, int is_req, struct rte **rtset)
 		p = (rr_t*)ptr->parsed;
 		while(p) {
 			if (! (t = pkg_malloc(sizeof(struct rte)))) {
-				LM_ERR("out of pkg mem (asked for: %d).\n",
+				PKG_MEM_ERROR_FMT("(asked for: %d).\n",
 						(int)sizeof(struct rte));
 				goto err;
 			}
@@ -999,7 +999,7 @@ eval_flags:
 				 * header parser's allocator (using pkg/shm) */
 				chklen = sizeof(struct rte) + sizeof(rr_t);
 				if (! (t = pkg_malloc(chklen))) {
-					ERR("out of pkg memory (%d required)\n", (int)chklen);
+					PKG_MEM_ERROR_FMT("(%d required)\n", (int)chklen);
 					/* last element was freed, unlink it */
 					if(prev_t == NULL) {
 						/* there is only one elem in route set: the remote target */
@@ -1204,7 +1204,7 @@ char *build_dlg_ack(struct sip_msg* rpl, struct cell *Trans,
 	req_buf = shm_malloc(offset + *len + 1);
 	req_buf += offset;
 	if (!req_buf) {
-		LM_ERR("Cannot allocate memory (%u+1)\n", *len);
+		SHM_MEM_ERROR_FMT("required (%u+1)\n", *len);
 		goto error01;
 	}
 	p = req_buf;
@@ -1565,7 +1565,7 @@ char* build_uac_req(str* method, str* headers, str* body, dlg_t* dialog,
 
 	buf = shm_malloc(*len + 1);
 	if (!buf) {
-		LM_ERR("no more shared memory (%d)\n", *len);
+		SHM_MEM_ERROR_FMT("required (%d)\n", *len);
 		goto error;
 	}
 
@@ -1688,7 +1688,7 @@ char *build_uac_cancel(str *headers,str *body,struct cell *cancelledT,
 	cancel_buf=shm_malloc( *len+1 );
 	if (!cancel_buf)
 	{
-		LM_ERR("no more share memory\n");
+		SHM_MEM_ERROR;
 		goto error01;
 	}
 	p = cancel_buf;

+ 2 - 2
src/modules/tm/t_reply.c

@@ -316,7 +316,7 @@ inline static int update_totag_set(struct cell *t, struct sip_msg *ok)
 	n=(struct totag_elem*) shm_malloc(sizeof(struct totag_elem));
 	s=(char *)shm_malloc(tag->len);
 	if (!s || !n) {
-		LM_ERR("no more shm memory \n");
+		SHM_MEM_ERROR;
 		if (n) shm_free(n);
 		if (s) shm_free(s);
 		return 0;
@@ -855,7 +855,7 @@ int fake_req_clone_str_helper(str *src, str *dst, char *txt)
 	if (src->s!=0 && src->len!=0) {
 		dst->s=pkg_malloc(src->len+1);
 		if (!dst->s) {
-			LM_ERR("no pkg mem to clone %s back to faked msg\n", txt);
+			PKG_MEM_ERROR;
 			return -1;
 		}
 		dst->len=src->len;

+ 6 - 6
src/modules/tm/t_serial.c

@@ -347,7 +347,7 @@ int ki_t_load_contacts_mode(struct sip_msg* msg, int mode)
 	/* Allocate memory for first contact */
 	contacts = (struct contact *)pkg_malloc(sizeof(struct contact));
 	if (!contacts) {
-		LM_ERR("no memory for contact info\n");
+		PKG_MEM_ERROR_FMT("for contact info\n");
 		return -1;
 	}
 	memset(contacts, 0, sizeof(struct contact));
@@ -418,7 +418,7 @@ int ki_t_load_contacts_mode(struct sip_msg* msg, int mode)
 
 		next = (struct contact *)pkg_malloc(sizeof(struct contact));
 		if (!next) {
-			LM_ERR("no memory for contact info\n");
+			PKG_MEM_ERROR_FMT("for contact info\n");
 			free_contact_list(contacts);
 			return -1;
 		}
@@ -680,13 +680,13 @@ int ki_t_next_contacts(struct sip_msg* msg)
 		instance = vavp->val.v.s;
 		il = (struct instance_list *)pkg_malloc(sizeof(struct instance_list));
 		if (!il) {
-			LM_ERR("no memory for instance list entry\n");
+			PKG_MEM_ERROR_FMT("for instance list entry\n");
 			return -1;
 		}
 		il->instance.s = pkg_malloc(instance.len);
 		if (!il->instance.s) {
 			pkg_free(il);
-			LM_ERR("no memory for instance list instance\n");
+			PKG_MEM_ERROR_FMT("for instance list instance\n");
 			return -1;
 		}
 		il->instance.len = instance.len;
@@ -859,13 +859,13 @@ int ki_t_next_contacts(struct sip_msg* msg)
 				ilp = (struct instance_list *)
 					pkg_malloc(sizeof(struct instance_list));
 				if (!ilp) {
-					LM_ERR("no memory for instance list element\n");
+					PKG_MEM_ERROR_FMT("for instance list element\n");
 					free_instance_list(il);
 					return -1;
 				}
 				ilp->instance.s = pkg_malloc(instance.len);
 				if (!ilp->instance.s) {
-					LM_ERR("no memory for instance list instance\n");
+					PKG_MEM_ERROR_FMT("for instance list instance\n");
 					pkg_free(ilp);
 					free_instance_list(il);
 					return -1;

+ 1 - 1
src/modules/tm/t_stats.c

@@ -55,7 +55,7 @@ int init_tm_stats_child(void)
 		size=sizeof(*tm_stats) * get_max_procs();
 		tm_stats=shm_malloc(size);
 		if (tm_stats == 0) {
-			ERR("No mem for stats\n");
+			SHM_MEM_ERROR;
 			goto error;
 		}
 		memset(tm_stats, 0, size);

+ 1 - 1
src/modules/tm/test.c

@@ -44,7 +44,7 @@ int _test_insert_to_reply( struct sip_msg *msg, char *str )
     len=strlen( str );
     buf=pkg_malloc( len );
     if (!buf) {
-        LM_ERR("no mem\n");
+        PKG_MEM_ERROR;
         return 0;
     }
     memcpy( buf, str, len );