If ospfd is running and you attempt to reload a configuration file
but it has an error (or the parser thinks it has an error even though
the file is valid..), yyerror just prints to stderr so the message
is lost unless you're running ospfd in the foreground.

I wrote a diff to handle this (included at the bottom of this mail)
but then I noticed that bgpd already does the same, so this just syncs
with bgpd's handling. OK?

Index: parse.y
===================================================================
RCS file: /cvs/src/usr.sbin/ospfd/parse.y,v
retrieving revision 1.73
diff -u -p -r1.73 parse.y
--- parse.y     13 Dec 2010 13:43:37 -0000      1.73
+++ parse.y     3 Mar 2013 21:13:58 -0000
@@ -36,6 +36,7 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <string.h>
+#include <syslog.h>
 
 #include "ospf.h"
 #include "ospfd.h"
@@ -692,14 +693,16 @@ struct keywords {
 int
 yyerror(const char *fmt, ...)
 {
-       va_list ap;
+       va_list          ap;
+       char            *nfmt;
 
        file->errors++;
        va_start(ap, fmt);
-       fprintf(stderr, "%s:%d: ", file->name, yylval.lineno);
-       vfprintf(stderr, fmt, ap);
-       fprintf(stderr, "\n");
+       if (asprintf(&nfmt, "%s:%d: %s", file->name, yylval.lineno, fmt) == -1)
+               fatalx("yyerror asprintf");
+       vlog(LOG_CRIT, nfmt, ap);
        va_end(ap);
+       free(nfmt);
        return (0);
 }
 


Here's the one I came up with myself FWIW.

Index: parse.y
===================================================================
RCS file: /cvs/src/usr.sbin/ospfd/parse.y,v
retrieving revision 1.73
diff -u -p -r1.73 parse.y
--- parse.y     13 Dec 2010 13:43:37 -0000      1.73
+++ parse.y     3 Mar 2013 21:01:25 -0000
@@ -693,12 +693,14 @@ int
 yyerror(const char *fmt, ...)
 {
        va_list ap;
+       char *buf;
 
        file->errors++;
        va_start(ap, fmt);
-       fprintf(stderr, "%s:%d: ", file->name, yylval.lineno);
-       vfprintf(stderr, fmt, ap);
-       fprintf(stderr, "\n");
+       if (vasprintf(&buf, fmt, ap) >= 0) {
+               log_warnx("%s:%d: %s", file->name, yylval.lineno, buf);
+               free(buf);
+       }
        va_end(ap);
        return (0);
 }

Reply via email to