summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorFlorian Obser <florian@cvs.openbsd.org>2016-09-04 14:41:50 +0000
committerFlorian Obser <florian@cvs.openbsd.org>2016-09-04 14:41:50 +0000
commit1eec2c318901ec263450c488dd761ade57de1125 (patch)
tree73a14f92bf8af4d0be2d2e8c6796ef706170c75b /usr.sbin
parent67683f51ea9f8ca68581ec4e56ea4132becf530c (diff)
Add format attribute to logger functions.
Add syslog_debug to keep in sync with others. Input & OK benno@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/tftp-proxy/tftp-proxy.c56
-rw-r--r--usr.sbin/tftpd/tftpd.c58
2 files changed, 87 insertions, 27 deletions
diff --git a/usr.sbin/tftp-proxy/tftp-proxy.c b/usr.sbin/tftp-proxy/tftp-proxy.c
index 262fe0f37b4..030f9c8bfca 100644
--- a/usr.sbin/tftp-proxy/tftp-proxy.c
+++ b/usr.sbin/tftp-proxy/tftp-proxy.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tftp-proxy.c,v 1.18 2016/02/24 16:34:47 deraadt Exp $
+/* $OpenBSD: tftp-proxy.c,v 1.19 2016/09/04 14:41:16 florian Exp $
*
* Copyright (c) 2005 DLS Internet Services
* Copyright (c) 2004, 2005 Camiel Dobbelaar, <cd@sentia.nl>
@@ -98,11 +98,18 @@ void unprivproc_timeout(int, short, void *);
char ntop_buf[NTOP_BUFS][INET6_ADDRSTRLEN];
struct loggers {
- void (*err)(int, const char *, ...);
- void (*errx)(int, const char *, ...);
- void (*warn)(const char *, ...);
- void (*warnx)(const char *, ...);
- void (*info)(const char *, ...);
+ __dead void (*err)(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+ __dead void (*errx)(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+ void (*warn)(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+ void (*warnx)(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+ void (*info)(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+ void (*debug)(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
};
const struct loggers conslogger = {
@@ -110,15 +117,24 @@ const struct loggers conslogger = {
errx,
warn,
warnx,
- warnx
+ warnx, /* info */
+ warnx /* debug */
};
-void syslog_err(int, const char *, ...);
-void syslog_errx(int, const char *, ...);
-void syslog_warn(const char *, ...);
-void syslog_warnx(const char *, ...);
-void syslog_info(const char *, ...);
-void syslog_vstrerror(int, int, const char *, va_list);
+__dead void syslog_err(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+__dead void syslog_errx(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+void syslog_warn(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void syslog_warnx(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void syslog_info(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void syslog_debug(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void syslog_vstrerror(int, int, const char *, va_list)
+ __attribute__((__format__ (printf, 3, 0)));
const struct loggers syslogger = {
syslog_err,
@@ -126,6 +142,7 @@ const struct loggers syslogger = {
syslog_warn,
syslog_warnx,
syslog_info,
+ syslog_debug
};
const struct loggers *logger = &conslogger;
@@ -135,6 +152,7 @@ const struct loggers *logger = &conslogger;
#define lwarn(_f...) logger->warn(_f)
#define lwarnx(_f...) logger->warnx(_f)
#define linfo(_f...) logger->info(_f)
+#define ldebug(_f...) logger->debug(_f)
__dead void
usage(void)
@@ -1010,3 +1028,15 @@ syslog_info(const char *fmt, ...)
va_end(ap);
}
+void
+syslog_debug(const char *fmt, ...)
+{
+ va_list ap;
+
+ if (!debug)
+ return;
+
+ va_start(ap, fmt);
+ vsyslog(LOG_DEBUG, fmt, ap);
+ va_end(ap);
+}
diff --git a/usr.sbin/tftpd/tftpd.c b/usr.sbin/tftpd/tftpd.c
index 31f217bb6ab..6a76ae14e11 100644
--- a/usr.sbin/tftpd/tftpd.c
+++ b/usr.sbin/tftpd/tftpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tftpd.c,v 1.36 2016/03/31 23:03:26 jca Exp $ */
+/* $OpenBSD: tftpd.c,v 1.37 2016/09/04 14:41:49 florian Exp $ */
/*
* Copyright (c) 2012 David Gwynne <dlg@uq.edu.au>
@@ -222,11 +222,18 @@ struct errmsg {
};
struct loggers {
- void (*err)(int, const char *, ...);
- void (*errx)(int, const char *, ...);
- void (*warn)(const char *, ...);
- void (*warnx)(const char *, ...);
- void (*info)(const char *, ...);
+ __dead void (*err)(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+ __dead void (*errx)(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+ void (*warn)(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+ void (*warnx)(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+ void (*info)(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+ void (*debug)(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
};
const struct loggers conslogger = {
@@ -234,15 +241,24 @@ const struct loggers conslogger = {
errx,
warn,
warnx,
- warnx
+ warnx, /* info */
+ warnx /* debug */
};
-void syslog_err(int, const char *, ...);
-void syslog_errx(int, const char *, ...);
-void syslog_warn(const char *, ...);
-void syslog_warnx(const char *, ...);
-void syslog_info(const char *, ...);
-void syslog_vstrerror(int, int, const char *, va_list);
+__dead void syslog_err(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+__dead void syslog_errx(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+void syslog_warn(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void syslog_warnx(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void syslog_info(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void syslog_debug(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void syslog_vstrerror(int, int, const char *, va_list)
+ __attribute__((__format__ (printf, 3, 0)));
const struct loggers syslogger = {
syslog_err,
@@ -250,6 +266,7 @@ const struct loggers syslogger = {
syslog_warn,
syslog_warnx,
syslog_info,
+ syslog_debug
};
const struct loggers *logger = &conslogger;
@@ -259,6 +276,7 @@ const struct loggers *logger = &conslogger;
#define lwarn(_f...) logger->warn(_f)
#define lwarnx(_f...) logger->warnx(_f)
#define linfo(_f...) logger->info(_f)
+#define ldebug(_f...) logger->debug(_f)
__dead void
usage(void)
@@ -271,12 +289,12 @@ usage(void)
int cancreate = 0;
int verbose = 0;
+int debug = 0;
int
main(int argc, char *argv[])
{
extern char *__progname;
- int debug = 0;
int c;
struct passwd *pw;
@@ -1657,3 +1675,15 @@ syslog_info(const char *fmt, ...)
va_end(ap);
}
+void
+syslog_debug(const char *fmt, ...)
+{
+ va_list ap;
+
+ if (!debug)
+ return;
+
+ va_start(ap, fmt);
+ vsyslog(LOG_DEBUG, fmt, ap);
+ va_end(ap);
+}