diff options
author | 2017-02-11 16:12:36 +0000 | |
---|---|---|
committer | 2017-02-11 16:12:36 +0000 | |
commit | f0a65fa006efdee0b470b840e2c3a4c4d3282eb0 (patch) | |
tree | 1febd6e33e3cc567634e48025e2eb36f7a3ba685 | |
parent | Never look for broken blocks inside blocks that are already closed. (diff) | |
download | wireguard-openbsd-f0a65fa006efdee0b470b840e2c3a4c4d3282eb0.tar.xz wireguard-openbsd-f0a65fa006efdee0b470b840e2c3a4c4d3282eb0.zip |
Move parse_warning() into parse.c to prepare to replace errwarn.c
with standard daemon log.[ch].
ok mpi@
-rw-r--r-- | sbin/dhclient/dhcpd.h | 4 | ||||
-rw-r--r-- | sbin/dhclient/errwarn.c | 49 | ||||
-rw-r--r-- | sbin/dhclient/parse.c | 50 | ||||
-rw-r--r-- | usr.sbin/dhcpd/dhcpd.h | 8 | ||||
-rw-r--r-- | usr.sbin/dhcpd/errwarn.c | 57 | ||||
-rw-r--r-- | usr.sbin/dhcpd/parse.c | 54 |
6 files changed, 116 insertions, 106 deletions
diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 56baeb6c8da..f63d8830017 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.158 2016/09/02 15:44:26 mpi Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.159 2017/02/11 16:12:36 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -200,7 +200,6 @@ void note(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); #ifdef DEBUG void debug(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); #endif -void parse_warn(char *); /* conflex.c */ extern int lexline, lexchar; @@ -220,6 +219,7 @@ void parse_lease_time(FILE *, time_t *); int parse_decimal(FILE *, unsigned char *, char); int parse_hex(FILE *, unsigned char *); time_t parse_date(FILE *); +void parse_warn(char *); /* bpf.c */ void if_register_send(struct interface_info *); diff --git a/sbin/dhclient/errwarn.c b/sbin/dhclient/errwarn.c index 093d26e2c73..18b5f846c69 100644 --- a/sbin/dhclient/errwarn.c +++ b/sbin/dhclient/errwarn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: errwarn.c,v 1.23 2016/02/06 19:30:52 krw Exp $ */ +/* $OpenBSD: errwarn.c,v 1.24 2017/02/11 16:12:36 krw Exp $ */ /* Errors and warnings. */ @@ -61,7 +61,7 @@ #include "dhcp.h" #include "dhcpd.h" -static char mbuf[1024]; +char mbuf[1024]; int warnings_occurred; @@ -158,48 +158,3 @@ debug(char *fmt, ...) } } #endif - -void -parse_warn(char *msg) -{ - static char spaces[81]; - struct iovec iov[6]; - size_t iovcnt; - int i; - - snprintf(mbuf, sizeof(mbuf), "%s line %d: %s", tlname, lexline, msg); - -#ifndef DEBUG - syslog(LOG_ERR, "%s", mbuf); - syslog(LOG_ERR, "%s", token_line); - if (lexchar < 81) - syslog(LOG_ERR, "%*c", lexchar, '^'); -#endif - - if (log_perror) { - iov[0].iov_base = mbuf; - iov[0].iov_len = strlen(mbuf); - iov[1].iov_base = "\n"; - iov[1].iov_len = 1; - iov[2].iov_base = token_line; - iov[2].iov_len = strlen(token_line); - iov[3].iov_base = "\n"; - iov[3].iov_len = 1; - iovcnt = 4; - if (lexchar < 81) { - for (i = 0; i < lexchar; i++) { - if (token_line[i] == '\t') - spaces[i] = '\t'; - else - spaces[i] = ' '; - } - iov[4].iov_base = spaces; - iov[4].iov_len = lexchar - 1; - iov[5].iov_base = "^\n"; - iov[5].iov_len = 2; - iovcnt += 2; - } - writev(STDERR_FILENO, iov, iovcnt); - } - warnings_occurred = 1; -} diff --git a/sbin/dhclient/parse.c b/sbin/dhclient/parse.c index 8fed24971f3..d71242596e9 100644 --- a/sbin/dhclient/parse.c +++ b/sbin/dhclient/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.40 2016/02/06 19:30:52 krw Exp $ */ +/* $OpenBSD: parse.c,v 1.41 2017/02/11 16:12:36 krw Exp $ */ /* Common parser code for dhcpd and dhclient. */ @@ -55,6 +55,8 @@ #include <stdlib.h> #include <stdint.h> #include <string.h> +#include <syslog.h> +#include <unistd.h> #include "dhcp.h" #include "dhcpd.h" @@ -410,3 +412,49 @@ parse_date(FILE *cfile) return (guess); } + +void +parse_warn(char *msg) +{ + static char spaces[81]; + extern char mbuf[1024]; + struct iovec iov[6]; + size_t iovcnt; + int i; + + snprintf(mbuf, sizeof(mbuf), "%s line %d: %s", tlname, lexline, msg); + +#ifndef DEBUG + syslog(LOG_ERR, "%s", mbuf); + syslog(LOG_ERR, "%s", token_line); + if (lexchar < 81) + syslog(LOG_ERR, "%*c", lexchar, '^'); +#endif + + if (log_perror) { + iov[0].iov_base = mbuf; + iov[0].iov_len = strlen(mbuf); + iov[1].iov_base = "\n"; + iov[1].iov_len = 1; + iov[2].iov_base = token_line; + iov[2].iov_len = strlen(token_line); + iov[3].iov_base = "\n"; + iov[3].iov_len = 1; + iovcnt = 4; + if (lexchar < 81) { + for (i = 0; i < lexchar; i++) { + if (token_line[i] == '\t') + spaces[i] = '\t'; + else + spaces[i] = ' '; + } + iov[4].iov_base = spaces; + iov[4].iov_len = lexchar - 1; + iov[5].iov_base = "^\n"; + iov[5].iov_len = 2; + iovcnt += 2; + } + writev(STDERR_FILENO, iov, iovcnt); + } + warnings_occurred = 1; +} diff --git a/usr.sbin/dhcpd/dhcpd.h b/usr.sbin/dhcpd/dhcpd.h index 23e3f527aaf..49663332253 100644 --- a/usr.sbin/dhcpd/dhcpd.h +++ b/usr.sbin/dhcpd/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.55 2016/10/06 16:12:43 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.56 2017/02/11 16:12:36 krw Exp $ */ /* * Copyright (c) 1995, 1996, 1997, 1998, 1999 @@ -445,6 +445,11 @@ typedef unsigned char option_mask[16]; /* External definitions... */ +/* parse.c */ +void do_percentm(char *obuf, size_t size, char *ibuf); +int parse_warn(char *, ...) __attribute__ ((__format__ (__printf__, 1, + 2))); + /* options.c */ void parse_options(struct packet *); void parse_option_buffer(struct packet *, unsigned char *, int); @@ -460,7 +465,6 @@ void error(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); int warning(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); int note(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); int debug(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); -int parse_warn(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); /* dhcpd.c */ extern time_t cur_time; diff --git a/usr.sbin/dhcpd/errwarn.c b/usr.sbin/dhcpd/errwarn.c index e825c3b5ec2..417ec78e7e3 100644 --- a/usr.sbin/dhcpd/errwarn.c +++ b/usr.sbin/dhcpd/errwarn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: errwarn.c,v 1.9 2016/02/06 23:50:10 krw Exp $ */ +/* $OpenBSD: errwarn.c,v 1.10 2017/02/11 16:12:36 krw Exp $ */ /* Errors and warnings... */ @@ -59,10 +59,8 @@ #include "tree.h" #include "dhcpd.h" -static void do_percentm(char *obuf, size_t size, char *ibuf); - -static char mbuf[1024]; -static char fbuf[1024]; +char mbuf[1024]; +char fbuf[1024]; int warnings_occurred; @@ -168,7 +166,7 @@ debug(char *fmt, ...) /* * Find %m in the input string and substitute an error message string. */ -static void +void do_percentm(char *obuf, size_t size, char *ibuf) { char ch; @@ -202,50 +200,3 @@ do_percentm(char *obuf, size_t size, char *ibuf) } *t = '\0'; } - -int -parse_warn(char *fmt, ...) -{ - va_list list; - static char spaces[] = - " " - " "; /* 80 spaces */ - struct iovec iov[6]; - size_t iovcnt; - - do_percentm(mbuf, sizeof(mbuf), fmt); - snprintf(fbuf, sizeof(fbuf), "%s line %d: %s", tlname, lexline, mbuf); - va_start(list, fmt); - vsnprintf(mbuf, sizeof(mbuf), fbuf, list); - va_end(list); - - if (log_perror) { - iov[0].iov_base = mbuf; - iov[0].iov_len = strlen(mbuf); - iov[1].iov_base = "\n"; - iov[1].iov_len = 1; - iov[2].iov_base = token_line; - iov[2].iov_len = strlen(token_line); - iov[3].iov_base = "\n"; - iov[3].iov_len = 1; - iovcnt = 4; - if (lexchar < 81) { - iov[4].iov_base = spaces; - iov[4].iov_len = lexchar - 1; - iov[5].iov_base = "^\n"; - iov[5].iov_len = 2; - iovcnt += 2; - } - writev(STDERR_FILENO, iov, iovcnt); - } else { - syslog_r(log_priority | LOG_ERR, &sdata, "%s", mbuf); - syslog_r(log_priority | LOG_ERR, &sdata, "%s", token_line); - if (lexchar < 81) - syslog_r(log_priority | LOG_ERR, &sdata, "%*c", lexchar, - '^'); - } - - warnings_occurred = 1; - - return (0); -} diff --git a/usr.sbin/dhcpd/parse.c b/usr.sbin/dhcpd/parse.c index 615df5ae8ce..392b2b792a8 100644 --- a/usr.sbin/dhcpd/parse.c +++ b/usr.sbin/dhcpd/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.21 2016/08/27 01:26:22 guenther Exp $ */ +/* $OpenBSD: parse.c,v 1.22 2017/02/11 16:12:36 krw Exp $ */ /* Common parser code for dhcpd and dhclient. */ @@ -48,11 +48,14 @@ #include <netinet/in.h> #include <ctype.h> +#include <stdarg.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <syslog.h> #include <time.h> +#include <unistd.h> #include "dhcp.h" #include "tree.h" @@ -541,3 +544,52 @@ parse_date(FILE *cfile) return (guess); } + +int +parse_warn(char *fmt, ...) +{ + extern char mbuf[1024]; + extern char fbuf[1024]; + va_list list; + static char spaces[] = + " " + " "; /* 80 spaces */ + struct iovec iov[6]; + size_t iovcnt; + + do_percentm(mbuf, sizeof(mbuf), fmt); + snprintf(fbuf, sizeof(fbuf), "%s line %d: %s", tlname, lexline, mbuf); + va_start(list, fmt); + vsnprintf(mbuf, sizeof(mbuf), fbuf, list); + va_end(list); + + if (log_perror) { + iov[0].iov_base = mbuf; + iov[0].iov_len = strlen(mbuf); + iov[1].iov_base = "\n"; + iov[1].iov_len = 1; + iov[2].iov_base = token_line; + iov[2].iov_len = strlen(token_line); + iov[3].iov_base = "\n"; + iov[3].iov_len = 1; + iovcnt = 4; + if (lexchar < 81) { + iov[4].iov_base = spaces; + iov[4].iov_len = lexchar - 1; + iov[5].iov_base = "^\n"; + iov[5].iov_len = 2; + iovcnt += 2; + } + writev(STDERR_FILENO, iov, iovcnt); + } else { + syslog_r(log_priority | LOG_ERR, &sdata, "%s", mbuf); + syslog_r(log_priority | LOG_ERR, &sdata, "%s", token_line); + if (lexchar < 81) + syslog_r(log_priority | LOG_ERR, &sdata, "%*c", lexchar, + '^'); + } + + warnings_occurred = 1; + + return (0); +} |