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

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