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"]
)
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.
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.
#include <sys/time.h>
#endif
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
+
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
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;
+ }
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;
+ }
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;
+ char timestr[32] = "";
+ time_t now;
va_start(ap, format);
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);
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);
struct stat s;
sighup = false;
+
+ reopenlogger();
/* Reread our own configuration file */