Forráskód Böngészése

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.
Jan Janak 16 éve
szülő
commit
713a6e02b8
1 módosított fájl, 13 hozzáadás és 2 törlés
  1. 13 2
      modules/carrierroute/cr_config.c

+ 13 - 2
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);
+	}
 }