浏览代码

core: mem dbg options updates + cleanups

- memlog and memdbg can now be changed at runtime
- double define warning fix for fm_malloc (when compiled with -DF_MALLOC)
- nicer qm_status() & qm_sums() output
- BSD licence for mem/*
Andrei Pelinescu-Onciul 16 年之前
父节点
当前提交
e4f42ce1de
共有 18 个文件被更改,包括 201 次插入211 次删除
  1. 2 2
      cfg.y
  2. 8 1
      cfg_core.c
  3. 2 0
      cfg_core.h
  4. 9 4
      main.c
  5. 16 18
      mem/f_malloc.c
  6. 15 20
      mem/f_malloc.h
  7. 3 0
      mem/ll_malloc.c
  8. 11 18
      mem/mem.c
  9. 11 18
      mem/mem.h
  10. 5 2
      mem/memdbg.h
  11. 11 18
      mem/meminfo.h
  12. 11 18
      mem/memtest.c
  13. 49 34
      mem/q_malloc.c
  14. 11 18
      mem/q_malloc.h
  15. 3 0
      mem/sf_malloc.c
  16. 11 18
      mem/shm_mem.c
  17. 11 18
      mem/shm_mem.h
  18. 12 4
      pt.c

+ 2 - 2
cfg.y

@@ -860,9 +860,9 @@ assign_stm:
 	| PHONE2TEL EQUAL error { yyerror("boolean value expected"); }
 	| SYN_BRANCH EQUAL NUMBER { syn_branch=$3; }
 	| SYN_BRANCH EQUAL error { yyerror("boolean value expected"); }
-	| MEMLOG EQUAL intno { memlog=$3; }
+	| MEMLOG EQUAL intno { default_core_cfg.memlog=$3; }
 	| MEMLOG EQUAL error { yyerror("int value expected"); }
-	| MEMDBG EQUAL intno { memdbg=$3; }
+	| MEMDBG EQUAL intno { default_core_cfg.memdbg=$3; }
 	| MEMDBG EQUAL error { yyerror("int value expected"); }
 	| MEMSUM EQUAL intno { default_core_cfg.mem_summary=$3; }
 	| MEMSUM EQUAL error { yyerror("int value expected"); }

+ 8 - 1
cfg_core.c

@@ -48,6 +48,7 @@
 struct cfg_group_core default_core_cfg = {
 	L_WARN, 	/*  print only msg. < L_WARN */
 	LOG_DAEMON,	/* log_facility -- see syslog(3) */
+	L_DBG,  /* memdbg */
 #ifdef USE_DST_BLACKLIST
 	/* blacklist */
 	0, /* dst blacklist is disabled by default */
@@ -93,6 +94,7 @@ struct cfg_group_core default_core_cfg = {
 	0, /* udp_mtu (disabled by default) */
 	0, /* udp_mtu_try_proto -> default disabled */
 	0,  /* force_rport */
+	L_DBG, /* memlog */
 	1 /* mem_summary -flags: 0 off, 1 shm/pkg_status, 2 shm/pkg_sums */
 };
 
@@ -103,6 +105,8 @@ cfg_def_t core_cfg_def[] = {
 		"debug level"},
 	{"log_facility",	CFG_VAR_INT|CFG_INPUT_STRING,	0, 0, log_facility_fixup, 0,
 		"syslog facility, see \"man 3 syslog\""},
+	{"memdbg",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
+		"log level for memory debugging messages"},
 #ifdef USE_DST_BLACKLIST
 	/* blacklist */
 	{"use_dst_blacklist",	CFG_VAR_INT,	0, 1, use_dst_blacklist_fixup, 0,
@@ -192,8 +196,11 @@ cfg_def_t core_cfg_def[] = {
 		"if send size > udp_mtu use proto (1 udp, 2 tcp, 3 tls, 4 sctp)"},
 	{"force_rport",     CFG_VAR_INT, 0, 1,  0, fix_global_req_flags,
 		"force rport for all the received messages" },
+	{"memlog",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
+		"log level for memory status/summary information"},
 	{"mem_summary",	CFG_VAR_INT|CFG_ATOMIC,	0, 3, 0, 0,
 		"memory debugging information displayed on exit (flags): "
-		" 0 - off, 1 - dump all used blocks, 2 - summary of used blocks" },
+		" 0 - off, 1 - dump all the used blocks (status),"
+		" 2 - summary of used blocks" },
 	{0, 0, 0, 0, 0, 0}
 };

+ 2 - 0
cfg_core.h

@@ -47,6 +47,7 @@ extern void	*core_cfg;
 struct cfg_group_core {
 	int	debug;
 	int	log_facility;
+	int memdbg; /** < log level for memory debugging messages */
 #ifdef USE_DST_BLACKLIST
 	/* blacklist */
 	int	use_dst_blacklist; /* 1 if blacklist is enabled */
@@ -89,6 +90,7 @@ struct cfg_group_core {
 	int udp_mtu; /**< maximum send size for udp, if > try another protocol*/
 	int udp_mtu_try_proto; /**< if packet> udp_mtu, try proto (e.g. TCP) */
 	int force_rport; /**< if set rport will always be forced*/
+	int memlog; /** < log level for memory status/summary info */
 	int mem_summary; /**< display memory status/summary info on exit */
 };
 

+ 9 - 4
main.c

@@ -331,10 +331,6 @@ int check_via =  0;
 int phone2tel = 1;
 /* shall use stateful synonym branches? faster but not reboot-safe */
 int syn_branch = 1;
-/* debugging level for memory stats */
-int memlog = L_DBG;
-/* debugging level for the malloc debug messages */
-int memdbg = L_DBG;
 /* debugging level for timer debugging */
 int timerlog = L_WARN;
 /* should replies include extensive warnings? by default yes,
@@ -494,6 +490,8 @@ char* pgid_file = 0;
 /* call it before exiting; if show_status==1, mem status is displayed */
 void cleanup(show_status)
 {
+	int memlog;
+	
 	/*clean-up*/
 #ifndef SHM_SAFE_MALLOC
 	if (mem_lock)
@@ -528,6 +526,7 @@ void cleanup(show_status)
 	destroy_nonsip_hooks();
 	destroy_routes();
 	destroy_atomic_ops();
+	memlog=cfg_get(core, core_cfg, memlog);
 #ifdef PKG_MALLOC
 	if (show_status && memlog <= cfg_get(core, core_cfg, debug)){
 		if (cfg_get(core, core_cfg, mem_summary) & 1) {
@@ -645,6 +644,7 @@ void handle_sigs()
 {
 	pid_t	chld;
 	int	chld_status;
+	int memlog;
 
 	switch(sig_flag){
 		case 0: break; /* do nothing*/
@@ -671,6 +671,7 @@ void handle_sigs()
 #ifdef STATS
 			dump_all_statistic();
 #endif
+		memlog=cfg_get(core, core_cfg, memlog);
 #ifdef PKG_MALLOC
 		if (memlog <= cfg_get(core, core_cfg, debug)){
 			if (cfg_get(core, core_cfg, mem_summary) & 1) {
@@ -748,6 +749,9 @@ void handle_sigs()
 void sig_usr(int signo)
 {
 
+#ifdef PKG_MALLOC
+	int memlog;
+#endif
 
 	if (is_main){
 		if (sig_flag==0) sig_flag=signo;
@@ -771,6 +775,7 @@ void sig_usr(int signo)
 					LOG(L_INFO, "INFO: signal %d received\n", signo);
 					/* print memory stats for non-main too */
 					#ifdef PKG_MALLOC
+					memlog=cfg_get(core, core_cfg, memlog);
 					if (memlog <= cfg_get(core, core_cfg, debug)){
 						if (cfg_get(core, core_cfg, mem_summary) & 1) {
 							LOG(memlog, "Memory status (pkg):\n");

+ 16 - 18
mem/f_malloc.c

@@ -3,26 +3,19 @@
  *
  * Copyright (C) 2001-2003 FhG Fokus
  *
- * This file is part of ser, a free SIP server.
+ * This file is part of sip-router, a free SIP server.
  *
- * ser is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
  *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 /*
  * History:
@@ -55,6 +48,7 @@
 #include "../compiler_opt.h"
 #include "memdbg.h"
 #include "../bit_scan.h"
+#include "../cfg/cfg.h" /* memlog */
 
 
 /*useful macros*/
@@ -586,7 +580,9 @@ void fm_status(struct fm_block* qm)
 	int h;
 	int unused;
 	unsigned long size;
+	int memlog;
 
+	memlog=cfg_get(core, core_cfg, memlog);
 	LOG(memlog, "fm_status (%p):\n", qm);
 	if (!qm) return;
 
@@ -753,11 +749,13 @@ void fm_sums(struct fm_block* qm)
 	struct fm_frag* f;
 	struct fm_frag* free_frag;
 	int i, hash;
+	int memlog;
 	mem_counter *root,*x;
 	
 	root=0;
 	if (!qm) return;
 
+	memlog=cfg_get(core, core_cfg, memlog);
 	LOG(memlog, "summarizing all alloc'ed. fragments:\n");
 	
 	for (f=qm->first_frag, i=0; (char*)f<(char*)qm->last_frag;

+ 15 - 20
mem/f_malloc.h

@@ -4,26 +4,19 @@
  *
  * Copyright (C) 2001-2003 FhG Fokus
  *
- * This file is part of ser, a free SIP server.
+ * This file is part of sip-router, a free SIP server.
  *
- * ser is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
  *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 /*
  * History:
@@ -41,8 +34,10 @@
 #define f_malloc_h
 
 #ifdef DBG_QM_MALLOC
-#define DBG_F_MALLOC
-#endif
+#ifndef DBG_F_MALLOC
+	#define DBG_F_MALLOC
+#endif /* DBG_F_MALLOC */
+#endif /* DBG_QM_MALLOC */
 
 #include "meminfo.h"
 

+ 3 - 0
mem/ll_malloc.c

@@ -46,6 +46,7 @@
 #include "../dprint.h"
 #include "../globals.h"
 #include "memdbg.h"
+#include "../cfg/cfg.h" /* memlog */
 
 #define MAX_POOL_FRAGS 10000 /* max fragments per pool hash bucket */
 #define MIN_POOL_FRAGS 10    /* min fragments per pool hash bucket */
@@ -969,9 +970,11 @@ void sfm_status(struct sfm_block* qm)
 	int unused;
 	unsigned long size;
 	int k;
+	int memlog;
 
 #warning "ll_status doesn't work (might crash if used)"
 
+	memlog=cfg_get(core, core_cfg, memlog);
 	LOG(memlog, "sfm_status (%p):\n", qm);
 	if (!qm) return;
 

+ 11 - 18
mem/mem.c

@@ -3,26 +3,19 @@
  *
  * Copyright (C) 2001-2003 FhG Fokus
  *
- * This file is part of ser, a free SIP server.
+ * This file is part of sip-router, a free SIP server.
  *
- * ser is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
  *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  *
  *
  * History:

+ 11 - 18
mem/mem.h

@@ -5,26 +5,19 @@
  *
  * Copyright (C) 2001-2003 FhG Fokus
  *
- * This file is part of ser, a free SIP server.
+ * This file is part of sip-router, a free SIP server.
  *
- * ser is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
  *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 /*
  * History:

+ 5 - 2
mem/memdbg.h

@@ -25,6 +25,8 @@
 #ifndef _memdbg_h
 #define _memdbg_h
 
+#include "../cfg/cfg.h" /* memdbg*/
+
 extern int memdbg;
 
 #ifdef NO_DEBUG
@@ -35,9 +37,10 @@ extern int memdbg;
 	#endif
 #else /* NO_DEBUG */
 	#ifdef __SUNPRO_C
-		#define MDBG(...) LOG(memdbg, __VA_ARGS__)
+		#define MDBG(...) LOG(cfg_get(core, core_cfg, memdbg), __VA_ARGS__)
 	#else
-		#define MDBG(fmt, args...) LOG(memdbg, fmt,  ## args)
+		#define MDBG(fmt, args...) \
+			LOG(cfg_get(core, core_cfg, memdbg), fmt,  ## args)
 	#endif
 #endif /* NO_DEBUG */
 

+ 11 - 18
mem/meminfo.h

@@ -4,26 +4,19 @@
  *
  * Copyright (C) 2001-2003 FhG Fokus
  *
- * This file is part of ser, a free SIP server.
+ * This file is part of sip-router, a free SIP server.
  *
- * ser is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
  *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 /*
  * History:

+ 11 - 18
mem/memtest.c

@@ -3,26 +3,19 @@
  *
  * Copyright (C) 2001-2003 FhG Fokus
  *
- * This file is part of ser, a free SIP server.
+ * This file is part of sip-router, a free SIP server.
  *
- * ser is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
  *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
 

+ 49 - 34
mem/q_malloc.c

@@ -3,26 +3,19 @@
  *
  * Copyright (C) 2001-2003 FhG Fokus
  *
- * This file is part of ser, a free SIP server.
+ * This file is part of sip-router, a free SIP server.
  *
- * ser is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
  *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 /*
  * History:
@@ -54,6 +47,7 @@
 #include "../dprint.h"
 #include "../globals.h"
 #include "memdbg.h"
+#include "../cfg/cfg.h" /* memlog */
 
 
 /*useful macros*/
@@ -637,7 +631,9 @@ void qm_check(struct qm_block* qm)
 {
 	struct qm_frag* f;
 	long fcount = 0;
+	int memlog;
 	
+	memlog=cfg_get(core, core_cfg, memlog);
 	LOG(memlog, "DEBUG: qm_check()\n");
 	f = qm->first_frag;
 	while ((char*)f < (char*)qm->last_frag_end) {
@@ -693,32 +689,43 @@ void qm_status(struct qm_block* qm)
 	int i,j;
 	int h;
 	int unused;
+	int memlog;
+
 
-	LOG(memlog, "qm_status (%p):\n", qm);
+	memlog=cfg_get(core, core_cfg, memlog);
+	LOG_(DEFAULT_FACILITY, memlog, "qm_status: ", "(%p):\n", qm);
 	if (!qm) return;
 
-	LOG(memlog, " heap size= %lu\n", qm->size);
-	LOG(memlog, " used= %lu, used+overhead=%lu, free=%lu\n",
+	LOG_(DEFAULT_FACILITY, memlog, "qm_status: ", "heap size= %lu\n",
+			qm->size);
+	LOG_(DEFAULT_FACILITY, memlog, "qm_status: ",
+			"used= %lu, used+overhead=%lu, free=%lu\n",
 			qm->used, qm->real_used, qm->size-qm->real_used);
-	LOG(memlog, " max used (+overhead)= %lu\n", qm->max_real_used);
+	LOG_(DEFAULT_FACILITY, memlog, "qm_status: ",
+			"max used (+overhead)= %lu\n", qm->max_real_used);
 	
-	LOG(memlog, "dumping all alloc'ed. fragments:\n");
+	LOG_(DEFAULT_FACILITY, memlog, "qm_status: ",
+			"dumping all alloc'ed. fragments:\n");
 	for (f=qm->first_frag, i=0;(char*)f<(char*)qm->last_frag_end;f=FRAG_NEXT(f)
 			,i++){
 		if (! f->u.is_free){
-			LOG(memlog, "    %3d. %c  address=%p frag=%p size=%lu used=%d\n",
-				i, 
+			LOG_(DEFAULT_FACILITY, memlog, "qm_status: ",
+					"   %3d. %c  address=%p frag=%p size=%lu used=%d\n",
+				i,
 				(f->u.is_free)?'a':'N',
 				(char*)f+sizeof(struct qm_frag), f, f->size, FRAG_WAS_USED(f));
 #ifdef DBG_QM_MALLOC
-			LOG(memlog, "            %s from %s: %s(%ld)\n",
+			LOG_(DEFAULT_FACILITY, memlog, "qm_status: ",
+					"          %s from %s: %s(%ld)\n",
 				(f->u.is_free)?"freed":"alloc'd", f->file, f->func, f->line);
-			LOG(memlog, "        start check=%lx, end check= %lx, %lx\n",
+			LOG_(DEFAULT_FACILITY, memlog, "qm_status: ",
+					"         start check=%lx, end check= %lx, %lx\n",
 				f->check, FRAG_END(f)->check1, FRAG_END(f)->check2);
 #endif
 		}
 	}
-	LOG(memlog, "dumping free list stats :\n");
+	LOG_(DEFAULT_FACILITY, memlog, "qm_status: ",
+			"dumping free list stats :\n");
 	for(h=0,i=0;h<QM_HASH_SIZE;h++){
 		unused=0;
 		for (f=qm->free_hash[h].head.u.nxt_free,j=0; 
@@ -726,7 +733,8 @@ void qm_status(struct qm_block* qm)
 				if (!FRAG_WAS_USED(f)){
 					unused++;
 #ifdef DBG_QM_MALLOC
-					LOG(memlog, "unused fragm.: hash = %3d, fragment %p,"
+					LOG_(DEFAULT_FACILITY, memlog, "qm_status: ",
+						"unused fragm.: hash = %3d, fragment %p,"
 						" address %p size %lu, created from %s: %s(%lu)\n",
 					    h, f, (char*)f+sizeof(struct qm_frag), f->size,
 						f->file, f->func, f->line);
@@ -734,7 +742,8 @@ void qm_status(struct qm_block* qm)
 				}
 		}
 
-		if (j) LOG(memlog, "hash= %3d. fragments no.: %5d, unused: %5d\n"
+		if (j) LOG_(DEFAULT_FACILITY, memlog, "qm_status: ",
+				"hash= %3d. fragments no.: %5d, unused: %5d\n"
 					"\t\t bucket size: %9lu - %9ld (first %9lu)\n",
 					h, j, unused, UN_HASH(h),
 					((h<=QM_MALLOC_OPTIMIZE/ROUNDTO)?1:2)*UN_HASH(h),
@@ -746,7 +755,8 @@ void qm_status(struct qm_block* qm)
 		}
 
 	}
-	LOG(memlog, "-----------------------------\n");
+	LOG_(DEFAULT_FACILITY, memlog, "qm_status: ",
+			"-----------------------------\n");
 }
 
 
@@ -820,11 +830,14 @@ void qm_sums(struct qm_block* qm)
 	struct qm_frag* f;
 	int i;
 	mem_counter *root, *x;
+	int memlog;
 	
 	root=0;
 	if (!qm) return;
 	
-	LOG(memlog, "summarizing all alloc'ed. fragments:\n");
+	memlog=cfg_get(core, core_cfg, memlog);
+	LOG_(DEFAULT_FACILITY, memlog, "qm_sums: ",
+			"summarizing all alloc'ed. fragments:\n");
 	
 	for (f=qm->first_frag, i=0;(char*)f<(char*)qm->last_frag_end;
 			f=FRAG_NEXT(f),i++){
@@ -836,7 +849,8 @@ void qm_sums(struct qm_block* qm)
 	}
 	x = root;
 	while(x){
-		LOG(memlog, " count=%6d size=%10lu bytes from %s: %s(%ld)\n",
+		LOG_(DEFAULT_FACILITY, memlog, "qm_sums: ",
+				" count=%6d size=%10lu bytes from %s: %s(%ld)\n",
 			x->count,x->size,
 			x->file, x->func, x->line
 			);
@@ -844,7 +858,8 @@ void qm_sums(struct qm_block* qm)
 		free(x);
 		x = root;
 	}
-	LOG(memlog, "-----------------------------\n");
+	LOG_(DEFAULT_FACILITY, memlog, "qm_sums: ",
+			"-----------------------------\n");
 }
 #endif /* DBG_QM_MALLOC */
 

+ 11 - 18
mem/q_malloc.h

@@ -4,26 +4,19 @@
  *
  * Copyright (C) 2001-2003 FhG Fokus
  *
- * This file is part of ser, a free SIP server.
+ * This file is part of sip-router, a free SIP server.
  *
- * ser is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
  *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 /*
  * History:

+ 3 - 0
mem/sf_malloc.c

@@ -44,6 +44,7 @@
 #include "../dprint.h"
 #include "../globals.h"
 #include "memdbg.h"
+#include "../cfg/cfg.h" /* memlog */
 
 #define MAX_POOL_FRAGS 10000 /* max fragments per pool hash bucket */
 #define MIN_POOL_FRAGS 10    /* min fragments per pool hash bucket */
@@ -990,7 +991,9 @@ void sfm_status(struct sfm_block* qm)
 	int unused;
 	unsigned long size;
 	int k;
+	int memlog;
 
+	memlog=cfg_get(core, core_cfg, memlog);
 	LOG(memlog, "sfm_status (%p):\n", qm);
 	if (!qm) return;
 

+ 11 - 18
mem/shm_mem.c

@@ -4,26 +4,19 @@
  *
  * Copyright (C) 2001-2003 FhG Fokus
  *
- * This file is part of ser, a free SIP server.
+ * This file is part of sip-router, a free SIP server.
  *
- * ser is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
  *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 /*
  * History:

+ 11 - 18
mem/shm_mem.h

@@ -4,26 +4,19 @@
  *
  * Copyright (C) 2001-2003 FhG Fokus
  *
- * This file is part of ser, a free SIP server.
+ * This file is part of sip-router, a free SIP server.
  *
- * ser is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
  *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 /*
  * History:

+ 12 - 4
pt.c

@@ -525,17 +525,21 @@ end:
 void mem_dump_pkg_cb(str *gname, str *name)
 {
 	int	old_memlog;
+	int memlog;
 
 	if (cfg_get(core, core_cfg, mem_dump_pkg) == my_pid()) {
 		/* set memlog to ALERT level to force
 		printing the log messages */
-		old_memlog = memlog;
+		old_memlog = cfg_get(core, core_cfg, memlog);
 		memlog = L_ALERT;
+		/* ugly hack to temporarily switch memlog to something visible,
+		   possible race with a parallel cfg_set */
+		((struct cfg_group_core*)core_cfg)->memlog=memlog;
 
 		LOG(memlog, "Memory status (pkg) of process %d:\n", my_pid());
 		pkg_status();
 
-		memlog = old_memlog;
+		((struct cfg_group_core*)core_cfg)->memlog=old_memlog;
 	}
 }
 #endif
@@ -548,17 +552,21 @@ void mem_dump_pkg_cb(str *gname, str *name)
 int mem_dump_shm_fixup(void *handle, str *gname, str *name, void **val)
 {
 	int	old_memlog;
+	int memlog;
 
 	if ((long)(void*)(*val)) {
 		/* set memlog to ALERT level to force
 		printing the log messages */
-		old_memlog = memlog;
+		old_memlog = cfg_get(core, core_cfg, memlog);
 		memlog = L_ALERT;
+		/* ugly hack to temporarily switch memlog to something visible,
+		   possible race with a parallel cfg_set */
+		((struct cfg_group_core*)core_cfg)->memlog=memlog;
 
 		LOG(memlog, "Memory status (shm)\n");
 		shm_status();
 
-		memlog = old_memlog;
+		((struct cfg_group_core*)core_cfg)->memlog=old_memlog;
 		*val = (void*)(long)0;
 	}
 	return 0;