summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkrw <krw@openbsd.org>2017-02-16 00:24:43 +0000
committerkrw <krw@openbsd.org>2017-02-16 00:24:43 +0000
commite1f80b9af667cfffea4922ec75a138e9dbce1461 (patch)
tree6b8fc307e79f19db9b87d9a6eaaf7e2b2010c726
parentFix memory leaks in match_filter_list() error paths. (diff)
downloadwireguard-openbsd-e1f80b9af667cfffea4922ec75a138e9dbce1461.tar.xz
wireguard-openbsd-e1f80b9af667cfffea4922ec75a138e9dbce1461.zip
Bring parse_warn() into the log.[ch] 21st century and adopt the "^"
placement logic from dhclient.
-rw-r--r--usr.sbin/dhcpd/dhcpd.c5
-rw-r--r--usr.sbin/dhcpd/dhcpd.h4
-rw-r--r--usr.sbin/dhcpd/parse.c41
3 files changed, 15 insertions, 35 deletions
diff --git a/usr.sbin/dhcpd/dhcpd.c b/usr.sbin/dhcpd/dhcpd.c
index 569fc48c36f..16d59222b91 100644
--- a/usr.sbin/dhcpd/dhcpd.c
+++ b/usr.sbin/dhcpd/dhcpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.c,v 1.55 2017/02/13 23:04:05 krw Exp $ */
+/* $OpenBSD: dhcpd.c,v 1.56 2017/02/16 00:24:43 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@cvs.openbsd.org>
@@ -74,7 +74,6 @@ u_int16_t client_port;
struct passwd *pw;
int log_priority;
-int log_perror = 0;
int pfpipe[2];
int gotpipe = 0;
int syncrecv;
@@ -135,7 +134,6 @@ main(int argc, char *argv[])
break;
case 'd':
daemonize = 0;
- log_perror = 1;
break;
case 'f':
daemonize = 0;
@@ -146,7 +144,6 @@ main(int argc, char *argv[])
case 'n':
daemonize = 0;
cftest = 1;
- log_perror = 1;
break;
case 'u':
udpsockmode = 1;
diff --git a/usr.sbin/dhcpd/dhcpd.h b/usr.sbin/dhcpd/dhcpd.h
index 97596ab18a3..4aa080fa432 100644
--- a/usr.sbin/dhcpd/dhcpd.h
+++ b/usr.sbin/dhcpd/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.59 2017/02/13 23:04:05 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.60 2017/02/16 00:24:43 krw Exp $ */
/*
* Copyright (c) 1995, 1996, 1997, 1998, 1999
@@ -465,8 +465,6 @@ extern struct group root_group;
extern u_int16_t server_port;
extern u_int16_t client_port;
-extern int log_priority;
-extern int log_perror;
extern char *path_dhcpd_conf;
extern char *path_dhcpd_db;
diff --git a/usr.sbin/dhcpd/parse.c b/usr.sbin/dhcpd/parse.c
index 3e0ff2b9479..c3348e8b6f7 100644
--- a/usr.sbin/dhcpd/parse.c
+++ b/usr.sbin/dhcpd/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.25 2017/02/13 23:04:05 krw Exp $ */
+/* $OpenBSD: parse.c,v 1.26 2017/02/16 00:24:43 krw Exp $ */
/* Common parser code for dhcpd and dhclient. */
@@ -555,42 +555,27 @@ parse_warn(char *fmt, ...)
{
static char fbuf[1024];
static char mbuf[1024];
+ static char spaces[81];
va_list list;
- static char spaces[] =
- " "
- " "; /* 80 spaces */
- struct iovec iov[6];
- size_t iovcnt;
+ int i;
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;
+ log_warnx("%s", mbuf);
+ log_warnx("%s", token_line);
+ if (lexchar < sizeof(spaces)) {
+ memset(spaces, 0, sizeof(spaces));
+ for (i = 0; i < lexchar - 1; i++) {
+ if (token_line[i] == '\t')
+ spaces[i] = '\t';
+ else
+ spaces[i] = ' ';
}
- writev(STDERR_FILENO, iov, iovcnt);
- } else {
- log_warnx("%s", mbuf);
- log_warnx("%s", token_line);
- if (lexchar < 81)
- log_warnx("%*c", lexchar, '^');
}
+ log_warnx("%s^", spaces);
warnings_occurred = 1;