[LTP] [PATCHv2] logrotate: fix permission issue for test2

Po-Hsu Lin po-hsu.lin@canonical.com
Thu Jun 20 05:27:37 CEST 2024


When running this logrotate test on Ubuntu, this 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 capability I think there is no need to rotate log files
other than the testfile itself.

2. Permission issue
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.

Fix these by removing the extra include, reuse the existing user/group
setting for test1 with setup() as suggested by Petr Vorel.

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

diff --git a/testcases/commands/logrotate/logrotate_tests.sh b/testcases/commands/logrotate/logrotate_tests.sh
index 1f3e61294..c382fd1e4 100755
--- a/testcases/commands/logrotate/logrotate_tests.sh
+++ b/testcases/commands/logrotate/logrotate_tests.sh
@@ -25,7 +25,16 @@ TST_NEEDS_CMDS="crontab file grep logrotate"
 TST_TESTFUNC=test
 TST_NEEDS_TMPDIR=1
 TST_CNT=2
+TST_SETUP=setup
 TST_CLEANUP=cleanup
+PERMISSION=
+
+setup()
+{
+	local group="syslog"
+	grep -q $group /etc/group || group="root"
+	PERMISSION="su root $group"
+}
 
 cleanup()
 {
@@ -47,10 +56,6 @@ check_log()
 
 test1()
 {
-	local group="syslog"
-
-	grep -q $group /etc/group || group="root"
-
 	cat >tst_logrotate.conf <<-EOF
         #****** Begin Config file *******
         # create new (empty) log files after rotating old ones
@@ -60,7 +65,7 @@ test1()
         compress
 
         /var/log/tst_logfile {
-                su root $group
+                $PERMISSION
                 rotate 5
                 weekly
         }
@@ -95,9 +100,8 @@ test2()
         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