Skip to content

Commit

Permalink
Merge pull request #6 from metwork-framework/issue5
Browse files Browse the repository at this point in the history
feat: force rotation-size to 90% of rlimit-fsize (if set)
  • Loading branch information
thefab authored Mar 17, 2020
2 parents f100b9c + 09c8a68 commit 1f5ed94
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <glib.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/resource.h>

static gchar *log_file = NULL;
static glong rotation_size = -1;
Expand All @@ -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 ) {
Expand All @@ -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");
Expand Down

0 comments on commit 1f5ed94

Please sign in to comment.