public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] logrotate: fix permission issue on Ubuntu
@ 2024-06-13  7:53 Po-Hsu Lin
  2024-06-19 16:31 ` Petr Vorel
  0 siblings, 1 reply; 3+ messages in thread
From: Po-Hsu Lin @ 2024-06-13  7:53 UTC (permalink / raw)
  To: ltp; +Cc: po-hsu.lin

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


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-06-20  3:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-13  7:53 [LTP] [PATCH] logrotate: fix permission issue on Ubuntu Po-Hsu Lin
2024-06-19 16:31 ` Petr Vorel
2024-06-20  3:12   ` Po-Hsu Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox