From 09c8a687d4109c7a048fe1b40bc227c68b71acf4 Mon Sep 17 00:00:00 2001 From: thebaptiste Date: Fri, 13 Mar 2020 19:05:43 +0100 Subject: [PATCH] feat: force rotation-size to 90% of rlimit-fsize (if set) --- src/options.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/options.h b/src/options.h index 648d1b2..8448583 100644 --- a/src/options.h +++ b/src/options.h @@ -4,6 +4,7 @@ #include #include #include +#include static gchar *log_file = NULL; static glong rotation_size = -1; @@ -18,7 +19,8 @@ static gboolean use_locks = FALSE; void set_default_values_from_env() { const gchar *env_val; - + struct rlimit rl; + getrlimit(RLIMIT_FSIZE, &rl); if ( rotation_size == -1 ) { env_val = g_getenv("LOGPROXY_ROTATION_SIZE"); if ( env_val != NULL ) { @@ -28,6 +30,12 @@ void set_default_values_from_env() rotation_size = 104857600; } } + if ( (long long int) rl.rlim_max != -1 ) { + long long int val_max = (long long int) rl.rlim_max * 90 / 100; + if ( rotation_size > (int) val_max ) { + rotation_size = (int) val_max; + } + } if ( rotation_time == -1 ) { env_val = g_getenv("LOGPROXY_ROTATION_TIME");