Blame SOURCES/logrotate-3.8.6-copy-and-copytruncate.patch

900687
From ba18db9a3c47f3283bb3493a84946fe27d7b1bc4 Mon Sep 17 00:00:00 2001
900687
From: Kamil Dudka <kdudka@redhat.com>
900687
Date: Tue, 20 Jun 2017 13:35:37 +0200
900687
Subject: [PATCH] make 'copy' and 'copytruncate' work together
900687
900687
This commit fixes a regression introduced
900687
by 3b26f4d8bbb338981aa2796c4076792c63d850c0.
900687
900687
Upstream-commit: 65faf212e51115699f55f491d464f0ead9c2047e
900687
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
900687
---
900687
 logrotate.c            |  5 ++++-
900687
 test/test              | 13 +++++++++++++
900687
 test/test-config.73.in |  4 ++++
900687
 3 files changed, 21 insertions(+), 1 deletion(-)
900687
 create mode 100644 test/test-config.73.in
900687
900687
diff --git a/logrotate.c b/logrotate.c
900687
index 20f6ea5..d5da299 100644
900687
--- a/logrotate.c
900687
+++ b/logrotate.c
900687
@@ -760,7 +760,10 @@ static int copyTruncate(char *currLog, char *saveLog, struct stat *sb,
900687
     message(MESS_DEBUG, "copying %s to %s\n", currLog, saveLog);
900687
 
900687
     if (!debug) {
900687
-	if ((fdcurr = open(currLog, ((flags & LOG_FLAG_COPY) ? O_RDONLY : O_RDWR) | O_NOFOLLOW)) < 0) {
900687
+	/* read access is sufficient for 'copy' but not for 'copytruncate' */
900687
+	const int read_only = (flags & LOG_FLAG_COPY)
900687
+	    && !(flags & LOG_FLAG_COPYTRUNCATE);
900687
+	if ((fdcurr = open(currLog, ((read_only) ? O_RDONLY : O_RDWR) | O_NOFOLLOW)) < 0) {
900687
 	    message(MESS_ERROR, "error opening %s: %s\n", currLog,
900687
 		    strerror(errno));
900687
 	    return 1;
900687
diff --git a/test/test b/test/test
900687
index 54d57d2..bcdfe05 100755
900687
--- a/test/test
900687
+++ b/test/test
900687
@@ -1586,5 +1586,18 @@ EOF
900687
 rm -rf testdir adir
900687
 rm -rf testdir bdir
900687
 
900687
+cleanup 73
900687
+
900687
+# ------------------------------- Test 73 ------------------------------------
900687
+# make sure that 'copy' and 'copytruncate' work together
900687
+preptest test.log 73 2
900687
+
900687
+$RLR test-config.73 --force
900687
+
900687
+checkoutput <
900687
+test.log 0
900687
+test.log.1 0 zero
900687
+EOF
900687
+
900687
 cleanup
900687
 
900687
diff --git a/test/test-config.73.in b/test/test-config.73.in
900687
new file mode 100644
900687
index 0000000..f3b7c87
900687
--- /dev/null
900687
+++ b/test/test-config.73.in
900687
@@ -0,0 +1,4 @@
900687
+&DIR&/test*.log {
900687
+    copy
900687
+    copytruncate
900687
+}
900687
-- 
900687
2.13.5
900687