Instead of UNIX time, the log messages now start with the time in RFC3339
format, which human-readable and still easy for the computer to parse and sort.
The HUP signal will also cause the log file to be closed and reopened, which is
useful when log rotation is used. If there is an error while opening the log
file, this is logged to stderr.
dnl We do this in multiple stages, because unlike Linux all the other operating systems really suck and don't include their own dependencies.
AC_HEADER_STDC
dnl We do this in multiple stages, because unlike Linux all the other operating systems really suck and don't include their own dependencies.
AC_HEADER_STDC
-AC_CHECK_HEADERS([stdbool.h syslog.h sys/file.h sys/ioctl.h sys/mman.h sys/param.h sys/resource.h sys/socket.h sys/time.h sys/uio.h sys/wait.h netdb.h arpa/inet.h dirent.h])
+AC_CHECK_HEADERS([stdbool.h syslog.h sys/file.h sys/ioctl.h sys/mman.h sys/param.h sys/resource.h sys/socket.h sys/time.h time.h sys/uio.h sys/wait.h netdb.h arpa/inet.h dirent.h])
AC_CHECK_HEADERS([net/if.h net/if_types.h linux/if_tun.h net/if_tun.h net/tun/if_tun.h net/if_tap.h net/tap/if_tap.h net/ethernet.h net/if_arp.h netinet/in_systm.h netinet/in.h netinet/in6.h],
[], [], [#include "have.h"]
)
AC_CHECK_HEADERS([net/if.h net/if_types.h linux/if_tun.h net/if_tun.h net/tun/if_tun.h net/if_tap.h net/tap/if_tap.h net/ethernet.h net/if_arp.h netinet/in_systm.h netinet/in.h netinet/in6.h],
[], [], [#include "have.h"]
)
Partially rereads configuration files.
Connections to hosts whose host config file are removed are closed.
New outgoing connections specified in @file{tinc.conf} will be made.
Partially rereads configuration files.
Connections to hosts whose host config file are removed are closed.
New outgoing connections specified in @file{tinc.conf} will be made.
+If the --logfile option is used, this will also close and reopen the log file,
+useful when log rotation is used.
@item INT
Temporarily increases debug level to 5.
@item INT
Temporarily increases debug level to 5.
New outgoing connections specified in
.Pa tinc.conf
will be made.
New outgoing connections specified in
.Pa tinc.conf
will be made.
+If the
+.Fl -logfile
+option is used, this will also close and reopen the log file,
+useful when log rotation is used.
.It INT
Temporarily increases debug level to 5.
Send this signal again to revert to the original level.
.It INT
Temporarily increases debug level to 5.
Send this signal again to revert to the original level.
#include <sys/time.h>
#endif
#include <sys/time.h>
#endif
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
+
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
case LOGMODE_FILE:
logpid = getpid();
logfile = fopen(logfilename, "a");
case LOGMODE_FILE:
logpid = getpid();
logfile = fopen(logfilename, "a");
+ if(!logfile) {
+ fprintf(stderr, "Could not open log file %s: %s\n", logfilename, strerror(errno));
break;
case LOGMODE_SYSLOG:
#ifdef HAVE_MINGW
loghandle = RegisterEventSource(NULL, logident);
break;
case LOGMODE_SYSLOG:
#ifdef HAVE_MINGW
loghandle = RegisterEventSource(NULL, logident);
+ if(!loghandle) {
+ fprintf(stderr, "Could not open log handle!");
break;
#else
#ifdef HAVE_SYSLOG_H
break;
#else
#ifdef HAVE_SYSLOG_H
+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\n", 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;
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);
extern debug_t debug_level;
extern void openlogger(const char *, logmode_t);
extern debug_t debug_level;
extern void openlogger(const char *, logmode_t);
+extern void reopenlogger(void);
extern void logger(int, const char *, ...) __attribute__ ((__format__(printf, 2, 3)));
extern void closelogger(void);
extern void logger(int, const char *, ...) __attribute__ ((__format__(printf, 2, 3)));
extern void closelogger(void);
struct stat s;
sighup = false;
struct stat s;
sighup = false;
/* Reread our own configuration file */
/* Reread our own configuration file */