]> sourceware.org Git - lvm2.git/commitdiff
tests: add LVM_LOG_FILE_MAX_LINES
authorZdenek Kabelac <zkabelac@redhat.com>
Mon, 11 Jul 2016 10:43:28 +0000 (12:43 +0200)
committerZdenek Kabelac <zkabelac@redhat.com>
Mon, 11 Jul 2016 10:43:28 +0000 (12:43 +0200)
When logging to epoch files we would like to prevent creating too large
log files otherwise a spining command could fulfill available space
very easily and quickly.

Limit for to 100000 per command.

WHATS_NEW
lib/log/log.c
man/lvm.8.in
test/lib/inittest.sh

index 5be0449703ff2053caa0d429c2295656e44cc729..5653b139c97eaac12df44283aa350d44d5207185 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 Version 2.02.161 - 
 ================================
+  New LVM_LOG_FILE_MAX_LINES env var to limit max size of created logs.
 
 Version 2.02.160 - 6th July 2016
 ================================
index 30d71ef73dd1180918c0fefe2910f344be613c8d..434b8d05d2b13e9e54396b4856b745c20a711677 100644 (file)
@@ -31,6 +31,8 @@ static struct dm_str_list _log_dev_alias;
 
 static int _syslog = 0;
 static int _log_to_file = 0;
+static uint64_t _log_file_max_lines = 0;
+static uint64_t _log_file_lines = 0;
 static int _log_direct = 0;
 static int _log_while_suspended = 0;
 static int _indent = 1;
@@ -111,6 +113,14 @@ void init_log_file(const char *log_file, int append)
 
                if (st && fclose(st))
                        log_sys_debug("fclose", statfile);
+
+               if ((env = getenv("LVM_LOG_FILE_MAX_LINES"))) {
+                       if (sscanf(env, FMTu64, &_log_file_max_lines) != 1) {
+                               log_warn("WARNING: Ingnoring incorrect LVM_LOG_MAX_LINES envvar \"%s\".", env);
+                               _log_file_max_lines = 0;
+                       }
+                       _log_file_lines = 0;
+               }
        }
 
 no_epoch:
@@ -487,6 +497,9 @@ static void _vprint_log(int level, const char *file, int line, int dm_errno_or_c
 
                fputc('\n', _log_file);
                fflush(_log_file);
+
+               if (_log_file_max_lines && ++_log_file_lines >= _log_file_max_lines)
+                       fatal_internal_error = 1;
        }
 
        if (_syslog && (_log_while_suspended || !critical_section())) {
index 729518b43b67fbdda88de62bcb9501b942ad34fd..82d0558a16760e3a87ca463ceb956a9156ad95fc 100644 (file)
@@ -778,6 +778,11 @@ followed by the process ID and a startup timestamp using
 this format string "_%s_%d_%llu".  When set, each process logs to a
 separate file.
 .TP
+.B LVM_LOG_FILE_MAX_LINES
+A max number of lines to be printed to log file before
+the application aborts. Useful for testing to prevent creation
+of too big log files from spinning command.
+.TP
 .B LVM_EXPECTED_EXIT_STATUS
 The status anticipated when the process exits.  Use ">N" to match any
 status greater than N.  If the actual exit status matches and a log
index a453ee6245318f50f15a982e987786deed868348..dcc1304d058516bf6515f36a885ac0d827a9dd52 100644 (file)
@@ -58,6 +58,7 @@ RUNNING_DMEVENTD=$(pgrep dmeventd || true)
 
 export TESTOLDPWD TESTDIR COMMON_PREFIX PREFIX RUNNING_DMEVENTD
 export LVM_LOG_FILE_EPOCH=DEBUG
+export LVM_LOG_FILE_MAX_LINES=100000
 export LVM_EXPECTED_EXIT_STATUS=1
 
 test -n "$BASH" && trap 'set +vx; STACKTRACE; set -vx' ERR
This page took 0.052606 seconds and 5 git commands to generate.