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 -0000 1.21 +++ ospf6d/parse.y 3 Mar 2013 22:13:10 -0000 @@ -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 -0000 1.73 +++ ospfd/parse.y 3 Mar 2013 22:13:10 -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); } 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 -0000 1.22 +++ dvmrpd/parse.y 3 Mar 2013 22:13:10 -0000 @@ -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 -0000 1.6 +++ ifstated/ifstated.h 3 Mar 2013 22:14:38 -0000 @@ -142,5 +142,6 @@ void log_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.y 3 Aug 2010 18:42:40 -0000 1.30 +++ ifstated/parse.y 3 Mar 2013 22:13:10 -0000 @@ -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 -0000 1.168 +++ relayd/parse.y 3 Mar 2013 22:13:10 -0000 @@ -51,6 +51,7 @@ #include <netdb.h> #include <string.h> #include <ifaddrs.h> +#include <syslog.h> #include <openssl/ssl.h> @@ -1760,13 +1761,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/relayd.h =================================================================== RCS file: /cvs/src/usr.sbin/relayd/relayd.h,v retrieving revision 1.164 diff -u -p -r1.164 relayd.h --- relayd/relayd.h 5 Feb 2013 21:36:33 -0000 1.164 +++ relayd/relayd.h 3 Mar 2013 22:13:10 -0000 @@ -1123,6 +1123,7 @@ void log_warn(const char *, ...) __attri void log_warnx(const char *, ...) __attribute__((__format__ (printf, 1, 2))); void log_info(const char *, ...) __attribute__((__format__ (printf, 1, 2))); void log_debug(const char *, ...) __attribute__((__format__ (printf, 1, 2))); +void vlog(int, const char *, va_list) __attribute__((__format__ (printf, 2, 0))); __dead void fatal(const char *); __dead void fatalx(const char *); Index: ldpd/parse.y =================================================================== RCS file: /cvs/src/usr.sbin/ldpd/parse.y,v retrieving revision 1.7 diff -u -p -r1.7 parse.y --- ldpd/parse.y 1 Sep 2010 13:54:54 -0000 1.7 +++ ldpd/parse.y 3 Mar 2013 22:13:10 -0000 @@ -36,6 +36,7 @@ #include <stdarg.h> #include <stdio.h> #include <string.h> +#include <syslog.h> #include "ldp.h" #include "ldpd.h" @@ -323,14 +324,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: ripd/parse.y =================================================================== RCS file: /cvs/src/usr.sbin/ripd/parse.y,v retrieving revision 1.28 diff -u -p -r1.28 parse.y --- ripd/parse.y 3 Aug 2010 18:42:41 -0000 1.28 +++ ripd/parse.y 3 Mar 2013 22:13:10 -0000 @@ -37,6 +37,7 @@ #include <stdarg.h> #include <stdio.h> #include <string.h> +#include <syslog.h> #include "ripd.h" #include "rip.h" @@ -378,14 +379,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: snmpd/parse.y =================================================================== RCS file: /cvs/src/usr.sbin/snmpd/parse.y,v retrieving revision 1.23 diff -u -p -r1.23 parse.y --- snmpd/parse.y 17 Sep 2012 19:00:06 -0000 1.23 +++ snmpd/parse.y 3 Mar 2013 22:13:10 -0000 @@ -46,6 +46,7 @@ #include <stdio.h> #include <netdb.h> #include <string.h> +#include <syslog.h> #include "snmpd.h" #include "mib.h" @@ -458,13 +459,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: snmpd/snmpd.h =================================================================== RCS file: /cvs/src/usr.sbin/snmpd/snmpd.h,v retrieving revision 1.40 diff -u -p -r1.40 snmpd.h --- snmpd/snmpd.h 24 Jan 2013 09:30:27 -0000 1.40 +++ snmpd/snmpd.h 3 Mar 2013 22:13:10 -0000 @@ -445,6 +445,7 @@ void log_info(const char *, ...); void log_debug(const char *, ...); __dead void fatal(const char *); __dead void fatalx(const char *); +void vlog(int, const char *, va_list); const char *log_in6addr(const struct in6_addr *); const char *print_host(struct sockaddr_storage *, char *, size_t); Index: smtpd/parse.y =================================================================== RCS file: /cvs/src/usr.sbin/smtpd/parse.y,v retrieving revision 1.115 diff -u -p -r1.115 parse.y --- smtpd/parse.y 17 Feb 2013 12:28:30 -0000 1.115 +++ smtpd/parse.y 3 Mar 2013 22:13:10 -0000 @@ -47,6 +47,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <syslog.h> #include <unistd.h> #include <util.h> @@ -928,13 +929,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: smtpd/smtpd.h =================================================================== RCS file: /cvs/src/usr.sbin/smtpd/smtpd.h,v retrieving revision 1.407 diff -u -p -r1.407 smtpd.h --- smtpd/smtpd.h 15 Feb 2013 22:43:21 -0000 1.407 +++ smtpd/smtpd.h 3 Mar 2013 22:13:10 -0000 @@ -1130,6 +1130,10 @@ void imsgproc_reset_callback(struct imsg pid_t lka(void); +/* log.c */ +void vlog(int, const char *, va_list); + + /* lka_session.c */ void lka_session(uint64_t, struct envelope *); void lka_session_forward_reply(struct forward_req *, int); Index: ypldap/parse.y =================================================================== RCS file: /cvs/src/usr.sbin/ypldap/parse.y,v retrieving revision 1.11 diff -u -p -r1.11 parse.y --- ypldap/parse.y 30 Apr 2012 11:28:25 -0000 1.11 +++ ypldap/parse.y 3 Mar 2013 22:13:12 -0000 @@ -47,6 +47,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <syslog.h> #include <unistd.h> #include "ypldap.h" @@ -331,13 +332,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: ypldap/ypldap.h =================================================================== RCS file: /cvs/src/usr.sbin/ypldap/ypldap.h,v retrieving revision 1.13 diff -u -p -r1.13 ypldap.h --- ypldap/ypldap.h 30 Apr 2012 11:28:25 -0000 1.13 +++ ypldap/ypldap.h 3 Mar 2013 22:13:12 -0000 @@ -184,6 +184,7 @@ void log_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 *);