]> source.dussan.org Git - rspamd.git/commitdiff
* Move config parse errors from stderr output to standart logging functions
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Fri, 6 Feb 2009 10:39:58 +0000 (13:39 +0300)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Fri, 6 Feb 2009 10:39:58 +0000 (13:39 +0300)
src/cfg_file.h
src/cfg_utils.c

index 7294bb28e16a7acf1843f8f0fe1b55d90fbe20aa..b80f4081ca967404a5390ada6a0823d3f5af40c6 100644 (file)
 /* 1 worker by default */
 #define DEFAULT_WORKERS_NUM 1
 
-#define yyerror(fmt, ...) \
-               fprintf (stderr, "Config file parse error!\non line: %d\n", yylineno); \
-               fprintf (stderr, "while reading text: %s\nreason: ", yytext); \
-               fprintf (stderr, fmt, ##__VA_ARGS__); \
-               fprintf (stderr, "\n")
-#define yywarn(fmt, ...) \
-               fprintf (stderr, "Config file parse warning!\non line %d\n", yylineno); \
-               fprintf (stderr, "while reading text: %s\nreason: ", yytext); \
-               fprintf (stderr, fmt, ##__VA_ARGS__); \
-               fprintf (stderr, "\n")
+#define yyerror parse_err
+#define yywarn parse_warn
 
 struct expression;
 struct tokenizer;
@@ -292,6 +284,8 @@ struct expression* parse_expression (memory_pool_t *pool, char *line);
 int yylex (void);
 int yyparse (void);
 void yyrestart (FILE *);
+void parse_err (const char *fmt, ...);
+void parse_warn (const char *fmt, ...);
 
 #endif /* ifdef CFG_FILE_H */
 /* 
index 68c1a1174396d3b66fa651356badc83a8a26427d..7e1e74b28dea458cb8b9121ab69d4a0972a0d53f 100644 (file)
@@ -632,6 +632,41 @@ parse_regexp (memory_pool_t *pool, char *line)
        return result;
 }
 
+void
+parse_err (const char *fmt, ...)
+{
+       va_list aq;
+       char logbuf[BUFSIZ], readbuf[32];
+       int r;
+       
+       va_start (aq, fmt);
+       g_strlcpy (readbuf, yytext, sizeof (readbuf));
+
+       r = snprintf (logbuf, sizeof (logbuf), "config file parse error! line: %d, text: %s, reason: ", yylineno, readbuf);
+       r += vsnprintf (logbuf + r, sizeof (logbuf) - r, fmt, aq);
+
+       va_end (aq);
+       g_error ("%s", logbuf);
+}
+
+void
+parse_warn (const char *fmt, ...)
+{
+       va_list aq;
+       char logbuf[BUFSIZ], readbuf[32];
+       int r;
+       
+       va_start (aq, fmt);
+       g_strlcpy (readbuf, yytext, sizeof (readbuf));
+
+       r = snprintf (logbuf, sizeof (logbuf), "config file parse warning! line: %d, text: %s, reason: ", yylineno, readbuf);
+       r += vsnprintf (logbuf + r, sizeof (logbuf) - r, fmt, aq);
+
+       va_end (aq);
+       g_warning ("%s", logbuf);
+}
+
+
 /*
  * vi:ts=4
  */