From 718f3a0385b600aee9a80a3c17d7d3c5387a9b7a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste VESLIN Date: Mon, 21 Feb 2022 15:19:59 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20add=20optional=20environment=20variable?= =?UTF-8?q?=20LOGPROXY=5FCHMOD=20to=20change=20logf=E2=80=A6=20(#32)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …iles mode --- README.md | 3 ++- src/options.h | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 61d9b32..71ec7aa 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,7 @@ Optional environment variables to override defaults : LOGPROXY_ROTATION_TIME LOGPROXY_ROTATION_SUFFIX LOGPROXY_ROTATED_FILES + LOGPROXY_CHMOD Example for rotation-size option : - If log_proxy is run with the option --rotation-size on command line, rotation-size will take the provided value @@ -155,7 +156,7 @@ Application Options: -S, --rotation-suffix strftime based suffix to append to rotated log files (default: content of environment variable LOGPROXY_ROTATION_SUFFIX or .%%Y%%m%%d%%H%%M%%S) -d, --log-directory directory to store log files (default: content of environment variable LOGPROXY_LOG_DIRECTORY or current directory), directory is created if missing -n, --rotated-files maximum number of rotated files to keep including main one (0 => no cleaning, default: content of environment variable LOGPROXY_ROTATED_FILES or 5) - -c, --chmod if set, chmod the logfile to this octal value (0700 for example) + -c, --chmod if set, chmod the logfile to this value, "0700" for example (default : content of environment variable LOGPROXY_CHMOD or NULL) -o, --chown if set, try (if you don't have sufficient privileges, it will fail silently) to change the owner of the logfile to the given user value -g, --chgrp if set, try (if you don't have sufficient privileges, it will fail silently) to change the group of the logfile to the given group value -m, --use-locks use locks to append to main log file (useful if several process writes to the same file) diff --git a/src/options.h b/src/options.h index a954b38..1977444 100644 --- a/src/options.h +++ b/src/options.h @@ -79,6 +79,13 @@ void set_default_values_from_env() log_directory = g_get_current_dir(); } } + + if ( chmod == NULL ) { + env_val = g_getenv("LOGPROXY_CHMOD"); + if ( env_val != NULL ) { + chmod = (gchar *)env_val; + } + } } static GOptionEntry entries[] = { @@ -87,7 +94,7 @@ static GOptionEntry entries[] = { { "rotation-suffix", 'S', 0, G_OPTION_ARG_STRING, &rotation_suffix, "strftime based suffix to append to rotated log files (default: content of environment variable LOGPROXY_ROTATION_SUFFIX or .%%Y%%m%%d%%H%%M%%S)", NULL }, { "log-directory", 'd', 0, G_OPTION_ARG_STRING, &log_directory, "directory to store log files (default: content of environment variable LOGPROXY_LOG_DIRECTORY or current directory), directory is created if missing", NULL }, { "rotated-files", 'n', 0, G_OPTION_ARG_INT, &rotated_files, "maximum number of rotated files to keep including main one (0 => no cleaning, default: content of environment variable LOGPROXY_ROTATED_FILES or 5)", NULL }, - { "chmod", 'c', 0, G_OPTION_ARG_STRING, &chmod_str, "if set, chmod the logfile to this octal value (0700 for example)", NULL }, + { "chmod", 'c', 0, G_OPTION_ARG_STRING, &chmod_str, "if set, chmod the logfile to this value, '0700' for example (default: content of environment variable LOGPROXY_CHMOD or NULL)", NULL }, { "chown", 'o', 0, G_OPTION_ARG_STRING, &chown_str, "if set, try (if you don't have sufficient privileges, it will fail silently) to change the owner of the logfile to the given user value", NULL }, { "chgrp", 'g', 0, G_OPTION_ARG_STRING, &chgrp_str, "if set, try (if you don't have sufficient privileges, it will fail silently) to change the group of the logfile to the given group value", NULL }, { "use-locks", 'm', 0, G_OPTION_ARG_NONE, &use_locks, "use locks to append to main log file (useful if several process writes to the same file)", NULL },