[SR-Dev] git:master: Replace missing logging macros with va_arg support using static buffer.

Jan Janak jan at iptel.org
Tue Mar 17 22:08:27 CET 2009


Module: sip-router
Branch: master
Commit: 713a6e02b866ed337146f2ee21b97cf15e4f9a37
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=713a6e02b866ed337146f2ee21b97cf15e4f9a37

Author: Jan Janak <jan at iptel.org>
Committer: Jan Janak <jan at iptel.org>
Date:   Tue Mar 17 22:06:36 2009 +0100

Replace missing logging macros with va_arg support using static buffer.

There is no support for logging macros with va_arg support in the
sr core, so we need to reimplement it in conf_error using a static
buffer. The function first prints the whole string into a static
buffer using vsnprintf and the buffer is then logged using LM_GEN1.

---

 modules/carrierroute/cr_config.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/modules/carrierroute/cr_config.c b/modules/carrierroute/cr_config.c
index 48975a5..642f911 100644
--- a/modules/carrierroute/cr_config.c
+++ b/modules/carrierroute/cr_config.c
@@ -32,6 +32,8 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
 #include "../../mem/shm_mem.h"
 #include "../../mem/mem.h"
 #include "../../ut.h"
@@ -50,8 +52,17 @@
  * @param ap format arguments
  */
 static void conf_error(cfg_t *cfg, const char * fmt, va_list ap) {
-	// FIXME this don't seems to work reliable, produces strange error messages
-	LM_GEN1(L_ERR, (char *) fmt, ap);
+	int ret;
+	static char buf[1024];
+
+	ret = vsnprintf(buf, sizeof(buf), fmt, ap);
+	if (ret < 0 || ret >= sizeof(buf)) {
+		LM_ERR("could not print error message\n");
+	} else {
+		// FIXME this don't seems to work reliable in all cases, charset 
+		// problems
+		LM_GEN1(L_ERR, "%s", buf);
+	}
 }
 
 




More information about the sr-dev mailing list