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

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