summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthe xhr <xhr@giessen.ccc.de>2021-08-26 10:23:59 +0200
committerthe xhr <xhr@giessen.ccc.de>2021-08-26 10:23:59 +0200
commit75e29febe513405dbcb534883dc76a7096a207ec (patch)
treeb1e54e9e04aaa14bcb7b3a6a3f97085300acacac
parent0321d839ea813adcaafa0dbe6463e5caa654bf1e (diff)
Re-open access and error log files on SIGHUP
-rw-r--r--twind.c12
-rw-r--r--twind.h4
2 files changed, 16 insertions, 0 deletions
diff --git a/twind.c b/twind.c
index bf3790c..bcd1393 100644
--- a/twind.c
+++ b/twind.c
@@ -92,6 +92,9 @@ static void
signal_handler(int signal)
{
switch (signal) {
+ case SIGHUP:
+ reload_log_files = 1;
+ break;
case SIGINT:
case SIGTERM:
organize_termination();
@@ -146,6 +149,8 @@ main(int argc, char *argv[])
fatalx("signal");
if (signal(SIGTERM, signal_handler) == SIG_ERR)
fatalx("signal");
+ if (signal(SIGHUP, signal_handler) == SIG_ERR)
+ fatalx("signal");
open_sockets(tcpsock, port);
@@ -252,6 +257,13 @@ handle_incoming_connections(int counter, int tcpsock, SSL_CTX *sslctx)
memset(str, 0, sizeof(str));
while (1) {
+ if (reload_log_files == 1) {
+ reload_log_files = 0;
+ log_debug("Re-open log files");
+ close_twind_logs();
+ open_twind_logs();
+ }
+
ret = accept(tcpsock, (struct sockaddr *)&addr, &len);
if (ret < 0)
fatalx("Error when accepting connection");
diff --git a/twind.h b/twind.h
index 9d9fce3..eb73199 100644
--- a/twind.h
+++ b/twind.h
@@ -21,6 +21,8 @@
#include <openssl/ssl.h>
+#include <signal.h>
+
#define VERSION "2021.a"
#define MAXREQLEN 1025
#define _PATH_TWIND_ACCESS_LOG "logs/access.log"
@@ -52,6 +54,8 @@ struct client_connection {
char client_addr[INET6_ADDRSTRLEN];
};
+static volatile sig_atomic_t reload_log_files = 0;
+
/* gemini.c */
int check_gemini_file(const char *);
int send_response(SSL*, int, const char *, const char *);
generated by cgit on OpenBSD