summaryrefslogtreecommitdiff
path: root/sbin/dhclient/errwarn.c
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2012-12-04 19:24:04 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2012-12-04 19:24:04 +0000
commit0360b5844fced3950f93dd48956263e3c61bcdd9 (patch)
treebd95a817b825106e554977a57c6c89f39636708b /sbin/dhclient/errwarn.c
parent88c41f8abbe91b0c05088f347532ff624af55472 (diff)
Eliminate hand-rolled pseudo-strerror() %m strangeness by replacing
all occurances of %m with strerror(errno). And then nuking do_percentm() and related buffer shuffling. Also simplify parse_warn() so it takes a simple char * of the error, and thus rely on pointing to error location in input for details. Makes sense to beck@
Diffstat (limited to 'sbin/dhclient/errwarn.c')
-rw-r--r--sbin/dhclient/errwarn.c68
1 files changed, 7 insertions, 61 deletions
diff --git a/sbin/dhclient/errwarn.c b/sbin/dhclient/errwarn.c
index e7ddff58142..781df5875a6 100644
--- a/sbin/dhclient/errwarn.c
+++ b/sbin/dhclient/errwarn.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: errwarn.c,v 1.18 2012/11/15 14:54:18 krw Exp $ */
+/* $OpenBSD: errwarn.c,v 1.19 2012/12/04 19:24:03 krw Exp $ */
/* Errors and warnings... */
@@ -45,10 +45,7 @@
#include <sys/uio.h>
-static void do_percentm(char *obuf, size_t size, char *ibuf);
-
static char mbuf[1024];
-static char fbuf[1024];
int warnings_occurred;
@@ -60,10 +57,8 @@ error(char *fmt, ...)
{
va_list list;
- do_percentm(fbuf, sizeof(fbuf), fmt);
-
va_start(list, fmt);
- vsnprintf(mbuf, sizeof(mbuf), fbuf, list);
+ vsnprintf(mbuf, sizeof(mbuf), fmt, list);
va_end(list);
#ifndef DEBUG
@@ -90,10 +85,8 @@ warning(char *fmt, ...)
{
va_list list;
- do_percentm(fbuf, sizeof(fbuf), fmt);
-
va_start(list, fmt);
- vsnprintf(mbuf, sizeof(mbuf), fbuf, list);
+ vsnprintf(mbuf, sizeof(mbuf), fmt, list);
va_end(list);
#ifndef DEBUG
@@ -116,10 +109,8 @@ note(char *fmt, ...)
{
va_list list;
- do_percentm(fbuf, sizeof(fbuf), fmt);
-
va_start(list, fmt);
- vsnprintf(mbuf, sizeof(mbuf), fbuf, list);
+ vsnprintf(mbuf, sizeof(mbuf), fmt, list);
va_end(list);
#ifndef DEBUG
@@ -143,10 +134,8 @@ debug(char *fmt, ...)
{
va_list list;
- do_percentm(fbuf, sizeof(fbuf), fmt);
-
va_start(list, fmt);
- vsnprintf(mbuf, sizeof(mbuf), fbuf, list);
+ vsnprintf(mbuf, sizeof(mbuf), fmt, list);
va_end(list);
syslog(LOG_DEBUG, "%s", mbuf);
@@ -160,59 +149,16 @@ debug(char *fmt, ...)
}
#endif
-/*
- * Find %m in the input string and substitute an error message string.
- */
-static void
-do_percentm(char *obuf, size_t size, char *ibuf)
-{
- char ch;
- char *s = ibuf;
- char *t = obuf;
- int prlen;
- size_t fmt_left;
- int saved_errno = errno;
-
- /*
- * We wouldn't need this mess if printf handled %m, or if
- * strerror() had been invented before syslog().
- */
- for (fmt_left = size; (ch = *s); ++s) {
- if (ch == '%' && s[1] == 'm') {
- ++s;
- prlen = snprintf(t, fmt_left, "%s",
- strerror(saved_errno));
- if (prlen == -1)
- prlen = 0;
- else if (prlen >= fmt_left)
- prlen = fmt_left - 1;
- t += prlen;
- fmt_left -= prlen;
- } else {
- if (fmt_left > 1) {
- *t++ = ch;
- fmt_left--;
- }
- }
- }
- *t = '\0';
-}
-
int
-parse_warn(char *fmt, ...)
+parse_warn(char *msg)
{
- 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);
+ snprintf(mbuf, sizeof(mbuf), "%s line %d: %s", tlname, lexline, msg);
#ifndef DEBUG
syslog(LOG_ERR, "%s", mbuf);