summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2015-11-21 12:59:25 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2015-11-21 12:59:25 +0000
commit8eb5135cba2b0d19e597b717cb9c55cadbda5c76 (patch)
tree2cc6690c4a49553b0a075e7a7035b5074be40383
parent0bf83b64bdef62a96eb141088a62ca60bc336b67 (diff)
Move local logging functions to util.c (which is shared with ikectl),
sync log.c with relayd and httpd - all three daemons are using a copy of the same file now. Nevertheless, adding "extern int debug/verbose" in util.c is not super nice but helps for now. No functional change.
-rw-r--r--sbin/iked/iked.h28
-rw-r--r--sbin/iked/log.c59
-rw-r--r--sbin/iked/util.c30
3 files changed, 69 insertions, 48 deletions
diff --git a/sbin/iked/iked.h b/sbin/iked/iked.h
index afd4148e426..308a96178f5 100644
--- a/sbin/iked/iked.h
+++ b/sbin/iked/iked.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: iked.h,v 1.91 2015/10/22 15:55:18 reyk Exp $ */
+/* $OpenBSD: iked.h,v 1.92 2015/11/21 12:59:24 reyk Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -914,6 +914,10 @@ const char *
print_proto(uint8_t);
int expand_string(char *, size_t, const char *, const char *);
uint8_t *string2unicode(const char *, size_t *);
+void print_debug(const char *, ...)
+ __attribute__((format(printf, 1, 2)));
+void print_verbose(const char *, ...)
+ __attribute__((format(printf, 1, 2)));
/* imsg_util.c */
struct ibuf *
@@ -938,14 +942,20 @@ void *ibuf_advance(struct ibuf *, size_t);
void ibuf_zero(struct ibuf *);
/* log.c */
-void log_init(int);
-void log_verbose(int);
-void log_warn(const char *, ...) __attribute__((format(printf, 1, 2)));
-void log_warnx(const char *, ...) __attribute__((format(printf, 1, 2)));
-void log_info(const char *, ...) __attribute__((format(printf, 1, 2)));
-void log_debug(const char *, ...) __attribute__((format(printf, 1, 2)));
-void print_debug(const char *, ...) __attribute__((format(printf, 1, 2)));
-void print_verbose(const char *, ...) __attribute__((format(printf, 1, 2)));
+void log_init(int);
+void log_verbose(int);
+void log_warn(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void log_warnx(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void log_info(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void log_debug(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void logit(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+void vlog(int, const char *, va_list)
+ __attribute__((__format__ (printf, 2, 0)));
__dead void fatal(const char *);
__dead void fatalx(const char *);
diff --git a/sbin/iked/log.c b/sbin/iked/log.c
index 61256f3f8ba..b5bcfba65e4 100644
--- a/sbin/iked/log.c
+++ b/sbin/iked/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.4 2015/01/16 06:39:58 deraadt Exp $ */
+/* $OpenBSD: log.c,v 1.5 2015/11/21 12:59:24 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -16,25 +16,33 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/queue.h>
-#include <sys/socket.h>
-#include <sys/tree.h>
-
-#include <errno.h>
-#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <string.h>
#include <syslog.h>
-#include <event.h>
-
-#include "iked.h"
+#include <errno.h>
+#include <time.h>
int debug;
int verbose;
-void vlog(int, const char *, va_list);
-void logit(int, const char *, ...);
+void log_init(int);
+void log_verbose(int);
+void log_warn(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void log_warnx(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void log_info(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void log_debug(const char *, ...)
+ __attribute__((__format__ (printf, 1, 2)));
+void logit(int, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)));
+void vlog(int, const char *, va_list)
+ __attribute__((__format__ (printf, 2, 0)));
+__dead void fatal(const char *);
+__dead void fatalx(const char *);
void
log_init(int n_debug)
@@ -143,41 +151,16 @@ log_debug(const char *emsg, ...)
}
void
-print_debug(const char *emsg, ...)
-{
- va_list ap;
-
- if (debug && verbose > 2) {
- va_start(ap, emsg);
- vfprintf(stderr, emsg, ap);
- va_end(ap);
- }
-}
-
-void
-print_verbose(const char *emsg, ...)
-{
- va_list ap;
-
- if (verbose) {
- va_start(ap, emsg);
- vfprintf(stderr, emsg, ap);
- va_end(ap);
- }
-}
-
-void
fatal(const char *emsg)
{
if (emsg == NULL)
logit(LOG_CRIT, "fatal: %s", strerror(errno));
- else {
+ else
if (errno)
logit(LOG_CRIT, "fatal: %s: %s",
emsg, strerror(errno));
else
logit(LOG_CRIT, "fatal: %s", emsg);
- }
exit(1);
}
diff --git a/sbin/iked/util.c b/sbin/iked/util.c
index 9363b19ca21..15786a6ab26 100644
--- a/sbin/iked/util.c
+++ b/sbin/iked/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.28 2015/11/19 21:32:53 mmcc Exp $ */
+/* $OpenBSD: util.c,v 1.29 2015/11/21 12:59:24 reyk Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -35,6 +35,10 @@
#include "iked.h"
#include "ikev2.h"
+/* log.c */
+extern int debug;
+extern int verbose;
+
void
socket_set_blockmode(int fd, enum blockmodes bm)
{
@@ -713,3 +717,27 @@ string2unicode(const char *ascii, size_t *outlen)
return (uc);
}
+
+void
+print_debug(const char *emsg, ...)
+{
+ va_list ap;
+
+ if (debug && verbose > 2) {
+ va_start(ap, emsg);
+ vfprintf(stderr, emsg, ap);
+ va_end(ap);
+ }
+}
+
+void
+print_verbose(const char *emsg, ...)
+{
+ va_list ap;
+
+ if (verbose) {
+ va_start(ap, emsg);
+ vfprintf(stderr, emsg, ap);
+ va_end(ap);
+ }
+}