log-handler: Set the end of the file as the file size
The file descriptor is lost after system AC cycle.
The log file will grow indefinitely if the log recorded does not exceed
the maximum log size after each AC cycle.
Change-Id: If23d68b08817d54731dd6eff8a42e9eb476b6437
Fixes: 46d9ef298f2e ("Do not truncate log files after reboot")
Signed-off-by: Marshall Zhan <marshall.zhan.wiwynn@gmail.com>
diff --git a/test/test-console-logs-to-file-no-sections b/test/test-console-logs-to-file-no-sections
index 8d4e052..1dbfb21 100755
--- a/test/test-console-logs-to-file-no-sections
+++ b/test/test-console-logs-to-file-no-sections
@@ -26,12 +26,17 @@
TEST_CONF="${TEST_NAME}.conf"
TEST_LOG="${TEST_NAME}.log"
+BLOCK_SIZE=1024
+LOG_MAX_SIZE=$((5 * $BLOCK_SIZE))
cat <<EOF > "$TEST_CONF"
logfile = $TEST_LOG
console-id = $TEST_NAME
+logsize = $LOG_MAX_SIZE
EOF
+dd if=/dev/zero bs=$BLOCK_SIZE count=$(($LOG_MAX_SIZE / $BLOCK_SIZE)) >> "$TEST_LOG"
+
"$SOCAT" -u PTY,raw,echo=0,link=remote PTY,raw,echo=0,wait-slave,link=local &
PTYS_PID="$!"
while ! [ -e remote ] || ! [ -e local ]; do sleep 1; done
@@ -43,3 +48,5 @@
echo console-should-log-to-file-legacy-syntax > remote
sleep 1
grep -LF console-should-log-to-file-legacy-syntax "$TEST_LOG"
+
+[ -e "$TEST_LOG" ] && [ $(stat -c%s "$TEST_LOG") -le $LOG_MAX_SIZE ]