On 2013/03/03 14:25, Theo de Raadt wrote:
I like the bgpd behaviour, and all the similar daemons should have the
same behaviour.
Here it is for all of the daemons which have parse.y and log.c; it only
really affects the ones which support reload, but I think it makes sense to
use the same code in all for consistency.
ldapd, bgpd, npppd, ntpd already use vlog, hostapd doesn't use log.c.
Index: ospf6d/parse.y
===
RCS file: /cvs/src/usr.sbin/ospf6d/parse.y,v
retrieving revision 1.21
diff -u -p -r1.21 parse.y
--- ospf6d/parse.y 27 Jun 2011 03:07:26 - 1.21
+++ ospf6d/parse.y 3 Mar 2013 22:13:10 -
@@ -38,6 +38,7 @@
#include stdarg.h
#include stdio.h
#include string.h
+#include syslog.h
#include ospf6.h
#include ospf6d.h
@@ -516,14 +517,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);
}
Index: ospfd/parse.y
===
RCS file: /cvs/src/usr.sbin/ospfd/parse.y,v
retrieving revision 1.73
diff -u -p -r1.73 parse.y
--- ospfd/parse.y 13 Dec 2010 13:43:37 - 1.73
+++ ospfd/parse.y 3 Mar 2013 22:13:10 -
@@ -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);
}
Index: dvmrpd/parse.y
===
RCS file: /cvs/src/usr.sbin/dvmrpd/parse.y,v
retrieving revision 1.22
diff -u -p -r1.22 parse.y
--- dvmrpd/parse.y 31 Dec 2010 21:22:42 - 1.22
+++ dvmrpd/parse.y 3 Mar 2013 22:13:10 -
@@ -358,14 +358,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);
}
Index: ifstated/ifstated.h
===
RCS file: /cvs/src/usr.sbin/ifstated/ifstated.h,v
retrieving revision 1.6
diff -u -p -r1.6 ifstated.h
--- ifstated/ifstated.h 4 Feb 2010 13:50:14 - 1.6
+++ ifstated/ifstated.h 3 Mar 2013 22:14:38 -
@@ -142,5 +142,6 @@ voidlog_warn(const char *, ...);
void log_warnx(const char *, ...);
void log_info(const char *, ...);
void log_debug(const char *, ...);
+void vlog(int, const char *, va_list);
__dead void fatal(const char *);
__dead void fatalx(const char *);
Index: ifstated/parse.y
===
RCS file: /cvs/src/usr.sbin/ifstated/parse.y,v
retrieving revision 1.30
diff -u -p -r1.30 parse.y
--- ifstated/parse.y3 Aug 2010 18:42:40 - 1.30
+++ ifstated/parse.y3 Mar 2013 22:13:10 -
@@ -355,13 +355,15 @@ int
yyerror(const char *fmt, ...)
{
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);
}
Index: relayd/parse.y
===
RCS file: /cvs/src/usr.sbin/relayd/parse.y,v
retrieving revision 1.168
diff -u -p -r1.168 parse.y
--- relayd/parse.y 19 Oct 2012 16:49:50 - 1.168
+++ relayd/parse.y 3 Mar 2013 22:13:10 -
@@ -51,6 +51,7 @@
#include netdb.h
#include string.h
#include ifaddrs.h
+#include