[LTP] [PATCH] logrotate: fix permission issue on Ubuntu

Po-Hsu Lin po-hsu.lin@canonical.com
Thu Jun 13 09:53:48 CEST 2024


When running this logrotate test on Ubuntu, the test will fail with:
  logrotate_tests 2 TINFO: sleep 1 min to wait for rotating logs
  logrotate_tests 2 TFAIL: [ -f /var/log/tst_largelogfile.1.gz ] failed unexpectedly
  logrotate_tests 2 TFAIL: Failed to create a compressed file

Look more closely to what this test is trying to do we will see there
are two issues here in the tst_largelog.conf:

1. "include /etc/logrotate.d"
This will rotate other log files defined here, since we are just testing
the log rotation capibility I think there is no need to rotate log files
other than the one for this test.

2. Permission issue on Ubuntu
Trying to rotate the target file on Ubuntu will cause the following error:
  error: skipping "/var/log/tst_largelogfile" because parent directory has
         insecure permissions (It's world writable or writable by group which
         is not "root") Set "su" directive in config file to tell logrotate
         which user/group should be used for rotation.

Solution is to add an extra line with the user and group information of
the /var/log directory. This change has been limited to Ubuntu to prevent
causing regression on other OS.

Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
---
 testcases/commands/logrotate/logrotate_tests.sh | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/testcases/commands/logrotate/logrotate_tests.sh b/testcases/commands/logrotate/logrotate_tests.sh
index 1f3e61294..4506ab5c6 100755
--- a/testcases/commands/logrotate/logrotate_tests.sh
+++ b/testcases/commands/logrotate/logrotate_tests.sh
@@ -90,14 +90,17 @@ test1()
 
 test2()
 {
+	permission=""
+	if `grep -q 'NAME="Ubuntu"' /etc/os-release 2>/dev/null`; then
+		permission="su `stat -c "%U %G" /var/log`"
+	fi
 	cat >tst_largelog.conf <<-EOF
         # create new (empty) log files after rotating old ones
         create
         # compress the log files
         compress
-        # RPM packages drop log rotation information into this directory
-        include /etc/logrotate.d
         /var/log/tst_largelogfile {
+            $permission
             rotate 5
             size=2k
         }
-- 
2.25.1



More information about the ltp mailing list