X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Flogger.c;h=ad7cef280c3d95cb210fcfd8e54920baa29e38d1;hp=e01980e9480a7ff86b86bef99ac224bcdba868cd;hb=3e61c7233b087b8400c29ca7a8d079aad8b706d8;hpb=eb80105ea855f2c7ee0ea467574acf86cf455a77 diff --git a/src/logger.c b/src/logger.c index e01980e9..ad7cef28 100644 --- a/src/logger.c +++ b/src/logger.c @@ -1,6 +1,6 @@ /* logger.c -- logging code - Copyright (C) 2004-2012 Guus Sliepen + Copyright (C) 2004-2015 Guus Sliepen 2004-2005 Ivo Timmermans This program is free software; you can redistribute it and/or modify @@ -22,22 +22,23 @@ #include "conf.h" #include "meta.h" +#include "names.h" #include "logger.h" #include "connection.h" #include "control_common.h" +#include "process.h" #include "sptps.h" debug_t debug_level = DEBUG_NOTHING; static logmode_t logmode = LOGMODE_STDERR; static pid_t logpid; -extern char *logfilename; static FILE *logfile = NULL; #ifdef HAVE_MINGW static HANDLE loghandle = NULL; #endif static const char *logident = NULL; bool logcontrol = false; - +int umbilical = 0; static void real_logger(int level, int priority, const char *message) { char timestr[32] = ""; @@ -79,6 +80,11 @@ static void real_logger(int level, int priority, const char *message) { case LOGMODE_NULL: break; } + + if(umbilical && do_detach) { + write(umbilical, message, strlen(message)); + write(umbilical, "\n", 1); + } } if(logcontrol) { @@ -114,9 +120,17 @@ void logger(int level, int priority, const char *format, ...) { static void sptps_logger(sptps_t *s, int s_errno, const char *format, va_list ap) { char message[1024] = ""; - int len = vsnprintf(message, sizeof message, format, ap); - if(len > 0 && len < sizeof message && message[len - 1] == '\n') - message[len - 1] = 0; + size_t msglen = sizeof message; + + int len = vsnprintf(message, msglen, format, ap); + if(len > 0 && len < sizeof message) { + if(message[len - 1] == '\n') + message[--len] = 0; + + connection_t *c = s->handle; + if(c) + snprintf(message + len, sizeof message - len, " from %s (%s)", c->name, c->hostname); + } real_logger(DEBUG_ALWAYS, LOG_ERR, message); }