projects
/
tinc
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Ensure compatibility with OpenSSL 1.1.0.
[tinc]
/
src
/
logger.c
diff --git
a/src/logger.c
b/src/logger.c
index
8c496de
..
6765cc5
100644
(file)
--- a/
src/logger.c
+++ b/
src/logger.c
@@
-1,7
+1,7
@@
/*
logger.c -- logging code
/*
logger.c -- logging code
- Copyright (C) 2004 Guus Sliepen <guus@tinc-vpn.org>
- 2004
Ivo Timmermans <ivo@tinc-vpn.org>
+ Copyright (C) 2004
-2006
Guus Sliepen <guus@tinc-vpn.org>
+ 2004
-2005 Ivo Timmermans
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@
-13,11
+13,9
@@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- $Id$
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "system.h"
*/
#include "system.h"
@@
-46,14
+44,18
@@
void openlogger(const char *ident, logmode_t mode) {
case LOGMODE_FILE:
logpid = getpid();
logfile = fopen(logfilename, "a");
case LOGMODE_FILE:
logpid = getpid();
logfile = fopen(logfilename, "a");
- if(!logfile)
+ if(!logfile) {
+ fprintf(stderr, "Could not open log file %s: %s\n", logfilename, strerror(errno));
logmode = LOGMODE_NULL;
logmode = LOGMODE_NULL;
+ }
break;
case LOGMODE_SYSLOG:
#ifdef HAVE_MINGW
loghandle = RegisterEventSource(NULL, logident);
break;
case LOGMODE_SYSLOG:
#ifdef HAVE_MINGW
loghandle = RegisterEventSource(NULL, logident);
- if(!loghandle)
+ if(!loghandle) {
+ fprintf(stderr, "Could not open log handle!");
logmode = LOGMODE_NULL;
logmode = LOGMODE_NULL;
+ }
break;
#else
#ifdef HAVE_SYSLOG_H
break;
#else
#ifdef HAVE_SYSLOG_H
@@
-66,8
+68,24
@@
void openlogger(const char *ident, logmode_t mode) {
}
}
}
}
+void reopenlogger() {
+ if(logmode != LOGMODE_FILE)
+ return;
+
+ fflush(logfile);
+ FILE *newfile = fopen(logfilename, "a");
+ if(!newfile) {
+ logger(LOG_ERR, "Unable to reopen log file %s: %s", logfilename, strerror(errno));
+ return;
+ }
+ fclose(logfile);
+ logfile = newfile;
+}
+
void logger(int priority, const char *format, ...) {
va_list ap;
void logger(int priority, const char *format, ...) {
va_list ap;
+ char timestr[32] = "";
+ time_t now;
va_start(ap, format);
va_start(ap, format);
@@
-78,7
+96,9
@@
void logger(int priority, const char *format, ...) {
fflush(stderr);
break;
case LOGMODE_FILE:
fflush(stderr);
break;
case LOGMODE_FILE:
- fprintf(logfile, "%ld %s[%ld]: ", time(NULL), logident, (long)logpid);
+ now = time(NULL);
+ strftime(timestr, sizeof timestr, "%Y-%m-%d %H:%M:%S", localtime(&now));
+ fprintf(logfile, "%s %s[%ld]: ", timestr, logident, (long)logpid);
vfprintf(logfile, format, ap);
fprintf(logfile, "\n");
fflush(logfile);
vfprintf(logfile, format, ap);
fprintf(logfile, "\n");
fflush(logfile);
@@
-87,7
+107,7
@@
void logger(int priority, const char *format, ...) {
#ifdef HAVE_MINGW
{
char message[4096];
#ifdef HAVE_MINGW
{
char message[4096];
- char *messages[] = {message};
+ c
onst c
har *messages[] = {message};
vsnprintf(message, sizeof(message), format, ap);
ReportEvent(loghandle, priority, 0, 0, NULL, 1, 0, messages, NULL);
}
vsnprintf(message, sizeof(message), format, ap);
ReportEvent(loghandle, priority, 0, 0, NULL, 1, 0, messages, NULL);
}