warp-vpn

point to point VPN implementation
git clone git://git.2f30.org/warp-vpn
Log | Files | Refs | README

commit 75af64f57ab5e5c2437415c501e4574337ec1bb6
parent 05677408d904ffcb77ec39572a0c2664a0e8b467
Author: sin <sin@2f30.org>
Date:   Fri,  1 Apr 2016 12:15:24 +0100

factor out logging into a separate function

Diffstat:
Mstun.c | 34+++++++++++++++-------------------
1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/stun.c b/stun.c @@ -109,18 +109,25 @@ int foreground; int sflag; void +logmsg(int priority, char *msg, va_list ap) +{ + if (foreground) { + fputs("stun: ", stderr); + vfprintf(stderr, msg, ap); + fputc('\n', stderr); + } else { + vsyslog(priority, msg, ap); + } +} + +void logdbg(char *msg, ...) { va_list ap; if (debug) { va_start(ap, msg); - if (foreground) { - vfprintf(stderr, msg, ap); - fputc('\n', stderr); - } else { - vsyslog(LOG_DAEMON | LOG_DEBUG, msg, ap); - } + logmsg(LOG_DAEMON | LOG_DEBUG, msg, ap); va_end(ap); } } @@ -131,12 +138,7 @@ logwarn(char *msg, ...) va_list ap; va_start(ap, msg); - if (foreground) { - vfprintf(stderr, msg, ap); - fputc('\n', stderr); - } else { - vsyslog(LOG_DAEMON | LOG_WARNING, msg, ap); - } + logmsg(LOG_DAEMON | LOG_WARNING, msg, ap); va_end(ap); } @@ -146,13 +148,7 @@ logerr(char *msg, ...) va_list ap; va_start(ap, msg); - if (foreground) { - fputs("stun: ", stderr); - vfprintf(stderr, msg, ap); - fputc('\n', stderr); - } else { - vsyslog(LOG_DAEMON | LOG_ERR, msg, ap); - } + logmsg(LOG_DAEMON | LOG_WARNING, msg, ap); va_end(ap); exit(1); }