summaryrefslogtreecommitdiffstats
path: root/usr.sbin/amd
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2014-10-26 02:32:51 +0000
committerguenther <guenther@openbsd.org>2014-10-26 02:32:51 +0000
commit57a9081fdf706749238710882416fdbe7171854a (patch)
tree862eff6a1a44d0420e1de1ca52d2b0f087dee123 /usr.sbin/amd
parentRemove trailing newlines from a couple log messages (diff)
downloadwireguard-openbsd-57a9081fdf706749238710882416fdbe7171854a.tar.xz
wireguard-openbsd-57a9081fdf706749238710882416fdbe7171854a.zip
Use vsyslog() instead of manually expanding the string and calling syslog(%s)
Now that newline stripping isn't needed, use vfprintf() instead of formatting and then writing it out. Delete bogus XXX comment that predated the switch to vsnprintf() Make the format string const char *
Diffstat (limited to 'usr.sbin/amd')
-rw-r--r--usr.sbin/amd/amd/xutil.c34
-rw-r--r--usr.sbin/amd/include/config.h5
2 files changed, 16 insertions, 23 deletions
diff --git a/usr.sbin/amd/amd/xutil.c b/usr.sbin/amd/amd/xutil.c
index 8c03e877c10..8af54e771c3 100644
--- a/usr.sbin/amd/amd/xutil.c
+++ b/usr.sbin/amd/amd/xutil.c
@@ -32,7 +32,7 @@
* SUCH DAMAGE.
*
* from: @(#)xutil.c 8.1 (Berkeley) 6/6/93
- * $Id: xutil.c,v 1.14 2014/10/26 01:16:48 guenther Exp $
+ * $Id: xutil.c,v 1.15 2014/10/26 02:32:51 guenther Exp $
*/
#include "config.h"
@@ -156,9 +156,10 @@ checkup_mem(void)
* 'e' never gets longer than maxlen characters.
*/
static void
-expand_error(char *f, char *e, int maxlen)
+expand_error(const char *f, char *e, int maxlen)
{
- char *p, *q;
+ const char *p;
+ char *q;
int error = errno;
int len = 0;
@@ -224,15 +225,11 @@ extern char **gargv;
/*VARARGS1*/
void
-plog(int lvl, char *fmt, ...)
+plog(int lvl, const char *fmt, ...)
{
- char msg[1024];
char efmt[1024];
- char *ptr;
va_list ap;
- va_start(ap, fmt);
-
if (!(xlog_level & lvl))
return;
@@ -240,16 +237,6 @@ plog(int lvl, char *fmt, ...)
checkup_mem();
#endif /* DEBUG_MEM */
- expand_error(fmt, efmt, sizeof(efmt));
- /*
- * XXX: msg is 1024 bytes long. It is possible to write into it
- * more than 1024 bytes, if efmt is already large, and vargs expand
- * as well.
- */
- vsnprintf(msg, sizeof(msg), efmt, ap);
- ptr = msg + strlen(msg);
- if (ptr[-1] == '\n')
- *--ptr = '\0';
if (syslogging) {
switch(lvl) { /* from mike <mcooper@usc.edu> */
case XLOG_FATAL: lvl = LOG_CRIT; break;
@@ -262,16 +249,21 @@ plog(int lvl, char *fmt, ...)
case XLOG_STATS: lvl = LOG_INFO; break;
default: lvl = LOG_ERR; break;
}
- syslog(lvl, "%s", msg);
+ va_start(ap, fmt);
+ vsyslog(lvl, fmt, ap);
+ va_end(ap);
return;
}
+ expand_error(fmt, efmt, sizeof(efmt));
+
/*
* Mimic syslog header
*/
- va_end(ap);
show_time_host_and_name(lvl);
- fwrite(msg, ptr - msg, 1, logfp);
+ va_start(ap, fmt);
+ vfprintf(logfp, efmt, ap);
+ va_end(ap);
fputc('\n', logfp);
fflush(logfp);
}
diff --git a/usr.sbin/amd/include/config.h b/usr.sbin/amd/include/config.h
index 2badb742c95..c0c9e89df4c 100644
--- a/usr.sbin/amd/include/config.h
+++ b/usr.sbin/amd/include/config.h
@@ -32,7 +32,7 @@
* SUCH DAMAGE.
*
* from: @(#)config.h 8.1 (Berkeley) 6/6/93
- * $Id: config.h,v 1.10 2014/10/26 01:16:49 guenther Exp $
+ * $Id: config.h,v 1.11 2014/10/26 02:32:51 guenther Exp $
*/
/*
@@ -95,7 +95,8 @@ extern void going_down(int);
#ifdef DEBUG
#define dplog(fmt, args...) plog(XLOG_DEBUG, fmt, ## args)
#endif /* DEBUG */
-extern void plog(int, char *, ...) __attribute__((__format__ (syslog, 2, 3)));
+extern void plog(int, const char *, ...)
+ __attribute__((__format__ (syslog, 2, 3)));
extern void show_opts(int ch, struct opt_tab *);
__dead void xmallocfailure(void);
extern void *xmalloc(size_t);